QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsowssourcewidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsowssourcewidget.cpp
3 --------------------------------------
4 Date : November 2021
5 Copyright : (C) 2021 by Samweli Mwakisambwe
6 Email : samweli at kartoza dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsowssourcewidget.h"
19
20#include "qgsmapcanvas.h"
21#include "qgsproviderregistry.h"
22
23#include <QNetworkRequest>
24#include <QString>
25
26#include "moc_qgsowssourcewidget.cpp"
27
28using namespace Qt::StringLiterals;
29
30QgsOWSSourceWidget::QgsOWSSourceWidget( const QString &providerKey, QWidget *parent )
31 : QgsProviderSourceWidget( parent )
32 , mProviderKey( providerKey )
33{
34 setupUi( this );
35
36 QgsCoordinateReferenceSystem destinationCrs;
38 mSpatialExtentBox->setOutputCrs( crs );
39}
40
41
43{
45
46 QgsCoordinateReferenceSystem destinationCrs;
48
49 if ( mapCanvas() && mapCanvas()->mapSettings().destinationCrs().isValid() )
50 destinationCrs = mapCanvas()->mapSettings().destinationCrs();
51 else
52 destinationCrs = crs;
53
54 mSpatialExtentBox->setOutputCrs( destinationCrs );
55 mSpatialExtentBox->setMapCanvas( mapCanvas() );
56}
57
58
60{
61 QgsCoordinateReferenceSystem destinationCrs;
63 mSpatialExtentBox->setOutputCrs( crs );
64
65 if ( mapCanvas() && mapCanvas()->mapSettings().destinationCrs().isValid() )
66 destinationCrs = mapCanvas()->mapSettings().destinationCrs();
67 else
68 destinationCrs = crs;
69 mSpatialExtentBox->setCurrentExtent( extent, destinationCrs );
70 mSpatialExtentBox->setOutputExtentFromCurrent();
71 mSpatialExtentBox->setMapCanvas( mapCanvas() );
72}
73
75{
76 return mSpatialExtentBox->outputExtent();
77}
78
79void QgsOWSSourceWidget::setSourceUri( const QString &uri )
80{
81 mSourceParts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, uri );
82 bool inverted = mSourceParts.value( u"InvertAxisOrientation"_s ).toBool();
83
84 QString bbox = mSourceParts.value( u"bbox"_s ).toString();
86 if ( !bbox.isEmpty() )
87 {
88 QStringList coords = bbox.split( ',' );
89 extent = inverted ? QgsRectangle(
90 coords.at( 1 ).toDouble(),
91 coords.at( 0 ).toDouble(),
92 coords.at( 3 ).toDouble(),
93 coords.at( 2 ).toDouble()
94 )
96 coords.at( 0 ).toDouble(),
97 coords.at( 1 ).toDouble(),
98 coords.at( 2 ).toDouble(),
99 coords.at( 3 ).toDouble()
100 );
101 }
102 else
103 {
105 }
106
107 setExtent( extent );
108 mSpatialExtentBox->setChecked( !extent.isNull() );
109}
110
112{
113 QVariantMap parts = mSourceParts;
114
115 QgsRectangle spatialExtent = extent();
116
117 if ( mSpatialExtentBox->isChecked() && !spatialExtent.isNull() )
118 {
119 bool inverted = parts.value( u"InvertAxisOrientation"_s ).toBool();
120
121 QString bbox = QString( inverted ? "%2,%1,%4,%3" : "%1,%2,%3,%4" )
122 .arg( qgsDoubleToString( spatialExtent.xMinimum() ), qgsDoubleToString( spatialExtent.yMinimum() ), qgsDoubleToString( spatialExtent.xMaximum() ), qgsDoubleToString( spatialExtent.yMaximum() ) );
123
124 parts.insert( u"bbox"_s, bbox );
125 }
126
127
128 return QgsProviderRegistry::instance()->encodeUri( mProviderKey, parts );
129}
Represents a coordinate reference system (CRS).
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsRectangle extent() const
Returns the spatial extent from the widget extent box.
QgsOWSSourceWidget(const QString &providerKey, QWidget *parent=nullptr)
Constructor for QgsOWSSourceWidget with the specified provider key and parent widget.
void setExtent(const QgsRectangle &extent)
Sets the spatial extent in the widget extent box.
void setMapCanvas(QgsMapCanvas *canvas) override
Sets a map canvas associated with the widget.
void setSourceUri(const QString &uri) override
Sets the source uri to show in the widget.
QString sourceUri() const override
Returns the source URI as currently defined by the widget.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString encodeUri(const QString &providerKey, const QVariantMap &parts)
Reassembles a provider data source URI from its component paths (e.g.
virtual QgsMapCanvas * mapCanvas()
Returns the map canvas associated with the widget.
QgsProviderSourceWidget(QWidget *parent=nullptr)
Constructor for QgsProviderSourceWidget with the specified parent widget.
virtual void setMapCanvas(QgsMapCanvas *mapCanvas)
Sets a map canvas associated with the widget.
A rectangle specified with double values.
double xMinimum
double yMinimum
double xMaximum
double yMaximum
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6817