QGIS API Documentation 3.41.0-Master (3440c17df1d)
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#include "moc_qgsowssourcewidget.cpp"
20#include "qgsproviderregistry.h"
21#include "qgsmapcanvas.h"
22
23#include <QNetworkRequest>
24
25
26QgsOWSSourceWidget::QgsOWSSourceWidget( const QString &providerKey, QWidget *parent )
27 : QgsProviderSourceWidget( parent )
28 , mProviderKey( providerKey )
29{
30 setupUi( this );
31
32 QgsCoordinateReferenceSystem destinationCrs;
33 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
34 mSpatialExtentBox->setOutputCrs( crs );
35}
36
37
39{
41
42 QgsCoordinateReferenceSystem destinationCrs;
43 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
44
45 if ( mapCanvas() && mapCanvas()->mapSettings().destinationCrs().isValid() )
46 destinationCrs = mapCanvas()->mapSettings().destinationCrs();
47 else
48 destinationCrs = crs;
49
50 mSpatialExtentBox->setOutputCrs( destinationCrs );
51 mSpatialExtentBox->setMapCanvas( mapCanvas() );
52}
53
54
56{
57 QgsCoordinateReferenceSystem destinationCrs;
58 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
59 mSpatialExtentBox->setOutputCrs( crs );
60
61 if ( mapCanvas() && mapCanvas()->mapSettings().destinationCrs().isValid() )
62 destinationCrs = mapCanvas()->mapSettings().destinationCrs();
63 else
64 destinationCrs = crs;
65 mSpatialExtentBox->setCurrentExtent( extent, destinationCrs );
66 mSpatialExtentBox->setOutputExtentFromCurrent();
67 mSpatialExtentBox->setMapCanvas( mapCanvas() );
68}
69
71{
72 return mSpatialExtentBox->outputExtent();
73}
74
75void QgsOWSSourceWidget::setSourceUri( const QString &uri )
76{
77 mSourceParts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, uri );
78 bool inverted = mSourceParts.value( QStringLiteral( "InvertAxisOrientation" ) ).toBool();
79
80 QString bbox = mSourceParts.value( QStringLiteral( "bbox" ) ).toString();
82 if ( !bbox.isEmpty() )
83 {
84 QStringList coords = bbox.split( ',' );
85 extent = inverted ? QgsRectangle(
86 coords.takeAt( 1 ).toDouble(),
87 coords.takeAt( 0 ).toDouble(),
88 coords.takeAt( 2 ).toDouble(),
89 coords.takeAt( 3 ).toDouble() ) :
91 coords.takeAt( 0 ).toDouble(),
92 coords.takeAt( 1 ).toDouble(),
93 coords.takeAt( 2 ).toDouble(),
94 coords.takeAt( 3 ).toDouble() );
95 }
96 else
97 {
99 }
100
101 setExtent( extent );
102 mSpatialExtentBox->setChecked( !extent.isNull() );
103}
104
106{
107 QVariantMap parts = mSourceParts;
108
109 QgsRectangle spatialExtent = extent();
110
111 if ( mSpatialExtentBox->isChecked() && !spatialExtent.isNull() )
112 {
113 bool inverted = parts.value( QStringLiteral( "InvertAxisOrientation" ) ).toBool();
114
115 QString bbox = QString( inverted ? "%2,%1,%4,%3" : "%1,%2,%3,%4" )
116 .arg( qgsDoubleToString( spatialExtent.xMinimum() ),
117 qgsDoubleToString( spatialExtent.yMinimum() ),
118 qgsDoubleToString( spatialExtent.xMaximum() ),
119 qgsDoubleToString( spatialExtent.yMaximum() ) );
120
121 parts.insert( QStringLiteral( "bbox" ), bbox );
122 }
123
124
125 return QgsProviderRegistry::instance()->encodeUri( mProviderKey, parts );
126}
127
This class 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.
Base class for widgets which allow customization of a provider's source URI.
virtual QgsMapCanvas * mapCanvas()
Returns the map canvas associated with the 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:5875
const QgsCoordinateReferenceSystem & crs