QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
25#include "moc_qgsowssourcewidget.cpp"
26
27QgsOWSSourceWidget::QgsOWSSourceWidget( const QString &providerKey, QWidget *parent )
28 : QgsProviderSourceWidget( parent )
29 , mProviderKey( providerKey )
30{
31 setupUi( this );
32
33 QgsCoordinateReferenceSystem destinationCrs;
34 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
35 mSpatialExtentBox->setOutputCrs( crs );
36}
37
38
40{
42
43 QgsCoordinateReferenceSystem destinationCrs;
44 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
45
46 if ( mapCanvas() && mapCanvas()->mapSettings().destinationCrs().isValid() )
47 destinationCrs = mapCanvas()->mapSettings().destinationCrs();
48 else
49 destinationCrs = crs;
50
51 mSpatialExtentBox->setOutputCrs( destinationCrs );
52 mSpatialExtentBox->setMapCanvas( mapCanvas() );
53}
54
55
57{
58 QgsCoordinateReferenceSystem destinationCrs;
59 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
60 mSpatialExtentBox->setOutputCrs( crs );
61
62 if ( mapCanvas() && mapCanvas()->mapSettings().destinationCrs().isValid() )
63 destinationCrs = mapCanvas()->mapSettings().destinationCrs();
64 else
65 destinationCrs = crs;
66 mSpatialExtentBox->setCurrentExtent( extent, destinationCrs );
67 mSpatialExtentBox->setOutputExtentFromCurrent();
68 mSpatialExtentBox->setMapCanvas( mapCanvas() );
69}
70
72{
73 return mSpatialExtentBox->outputExtent();
74}
75
76void QgsOWSSourceWidget::setSourceUri( const QString &uri )
77{
78 mSourceParts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, uri );
79 bool inverted = mSourceParts.value( QStringLiteral( "InvertAxisOrientation" ) ).toBool();
80
81 QString bbox = mSourceParts.value( QStringLiteral( "bbox" ) ).toString();
83 if ( !bbox.isEmpty() )
84 {
85 QStringList coords = bbox.split( ',' );
86 extent = inverted ? QgsRectangle(
87 coords.at( 1 ).toDouble(),
88 coords.at( 0 ).toDouble(),
89 coords.at( 3 ).toDouble(),
90 coords.at( 2 ).toDouble()
91 )
93 coords.at( 0 ).toDouble(),
94 coords.at( 1 ).toDouble(),
95 coords.at( 2 ).toDouble(),
96 coords.at( 3 ).toDouble()
97 );
98 }
99 else
100 {
102 }
103
104 setExtent( extent );
105 mSpatialExtentBox->setChecked( !extent.isNull() );
106}
107
109{
110 QVariantMap parts = mSourceParts;
111
112 QgsRectangle spatialExtent = extent();
113
114 if ( mSpatialExtentBox->isChecked() && !spatialExtent.isNull() )
115 {
116 bool inverted = parts.value( QStringLiteral( "InvertAxisOrientation" ) ).toBool();
117
118 QString bbox = QString( inverted ? "%2,%1,%4,%3" : "%1,%2,%3,%4" )
119 .arg( qgsDoubleToString( spatialExtent.xMinimum() ), qgsDoubleToString( spatialExtent.yMinimum() ), qgsDoubleToString( spatialExtent.xMaximum() ), qgsDoubleToString( spatialExtent.yMaximum() ) );
120
121 parts.insert( QStringLiteral( "bbox" ), bbox );
122 }
123
124
125 return QgsProviderRegistry::instance()->encodeUri( mProviderKey, parts );
126}
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:6524