Skip to content

Commit e83ef2e

Browse files
committedJul 18, 2017
Store canvas into the base class and set extent/crs from the arcgis classes
This modification was necessary because the current implementation of the source select dialogs within the unified add layer dialog create the provider dialogs the first time and do not destroy them, this means that the canvas extent and CRS can change from a dialog invocation to the next and the extent and CRS need to be updated at layer creation time.
1 parent f459790 commit e83ef2e

File tree

6 files changed

+51
-72
lines changed

6 files changed

+51
-72
lines changed
 

‎python/gui/qgsabstractdatasourcewidget.sip

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212

13+
1314
class QgsAbstractDataSourceWidget : QDialog
1415
{
1516
%Docstring
@@ -30,37 +31,12 @@ class QgsAbstractDataSourceWidget : QDialog
3031
Destructor
3132
%End
3233

33-
QgsProviderRegistry::WidgetMode widgetMode( ) const;
34-
%Docstring
35-
Return the widget mode
36-
:rtype: QgsProviderRegistry.WidgetMode
37-
%End
38-
39-
void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
40-
%Docstring
41-
Set the current CRS
42-
The CRS is normally the CRS of the map canvas, and it can be used
43-
by the provider dialog to transform the extent and constraint the service
44-
%End
45-
46-
void setCurrentExtent( const QgsRectangle &extent );
47-
%Docstring
48-
Set the current extent
49-
The extent is normally the extent of the map canvas, and it can be used
50-
by the provider dialog to constraint the service
51-
%End
52-
53-
QgsRectangle currentExtent( ) const;
34+
void setMapCanvas( const QgsMapCanvas *mapCanvas );
5435
%Docstring
55-
Return the current extent
56-
:rtype: QgsRectangle
36+
Store a pointer to the map canvas to retrieve extent and CRS
37+
Used to select an appropriate CRS and possibly to retrieve data only in the current extent
5738
%End
5839

59-
QgsCoordinateReferenceSystem currentCrs( ) const;
60-
%Docstring
61-
Return the current CRS
62-
:rtype: QgsCoordinateReferenceSystem
63-
%End
6440

6541
public slots:
6642

@@ -100,6 +76,18 @@ Emitted when a vector layer has been selected for addition
10076
Constructor
10177
%End
10278

79+
QgsProviderRegistry::WidgetMode widgetMode( ) const;
80+
%Docstring
81+
Return the widget mode
82+
:rtype: QgsProviderRegistry.WidgetMode
83+
%End
84+
85+
const QgsMapCanvas *mapCanvas( ) const;
86+
%Docstring
87+
Return the map canvas (can be null)
88+
:rtype: QgsMapCanvas
89+
%End
90+
10391
};
10492

10593
/************************************************************************

‎src/gui/qgsabstractdatasourcewidget.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,13 @@ QgsProviderRegistry::WidgetMode QgsAbstractDataSourceWidget::widgetMode() const
3030
return mWidgetMode;
3131
}
3232

33-
void QgsAbstractDataSourceWidget::setCurrentCrs( const QgsCoordinateReferenceSystem &crs )
33+
const QgsMapCanvas *QgsAbstractDataSourceWidget::mapCanvas() const
3434
{
35-
mCurrentCrs = crs;
35+
return mMapCanvas;
3636
}
3737

38-
void QgsAbstractDataSourceWidget::setCurrentExtent( const QgsRectangle &extent )
39-
{
40-
mCurrentExtent = extent;
41-
}
42-
43-
QgsRectangle QgsAbstractDataSourceWidget::currentExtent() const
44-
{
45-
return mCurrentExtent;
46-
}
4738

48-
QgsCoordinateReferenceSystem QgsAbstractDataSourceWidget::currentCrs() const
39+
void QgsAbstractDataSourceWidget::setMapCanvas( const QgsMapCanvas *mapCanvas )
4940
{
50-
return mCurrentCrs;
41+
mMapCanvas = mapCanvas;
5142
}

‎src/gui/qgsabstractdatasourcewidget.h

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "qgscoordinatereferencesystem.h"
3030
#include <QDialog>
3131

32+
class QgsMapCanvas;
33+
3234
/** \ingroup gui
3335
* \brief Abstract base Data Source Widget to create connections and add layers
3436
* This class provides common functionality and the interface for all
@@ -45,26 +47,11 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
4547
//! Destructor
4648
~QgsAbstractDataSourceWidget( ) = default;
4749

48-
//! Return the widget mode
49-
QgsProviderRegistry::WidgetMode widgetMode( ) const;
50-
51-
/** Set the current CRS
52-
* The CRS is normally the CRS of the map canvas, and it can be used
53-
* by the provider dialog to transform the extent and constraint the service
54-
*/
55-
void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
56-
57-
/** Set the current extent
58-
* The extent is normally the extent of the map canvas, and it can be used
59-
* by the provider dialog to constraint the service
50+
/** Store a pointer to the map canvas to retrieve extent and CRS
51+
* Used to select an appropriate CRS and possibly to retrieve data only in the current extent
6052
*/
61-
void setCurrentExtent( const QgsRectangle &extent );
53+
void setMapCanvas( const QgsMapCanvas *mapCanvas );
6254

63-
//! Return the current extent
64-
QgsRectangle currentExtent( ) const;
65-
66-
//! Return the current CRS
67-
QgsCoordinateReferenceSystem currentCrs( ) const;
6855

6956
public slots:
7057

@@ -94,11 +81,19 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
9481
//! Constructor
9582
QgsAbstractDataSourceWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
9683

84+
//! Return the widget mode
85+
QgsProviderRegistry::WidgetMode widgetMode( ) const;
86+
87+
/** Return the map canvas (can be null)
88+
*/
89+
const QgsMapCanvas *mapCanvas( ) const;
90+
9791
private:
9892

9993
QgsProviderRegistry::WidgetMode mWidgetMode;
10094
QgsCoordinateReferenceSystem mCurrentCrs;
10195
QgsRectangle mCurrentExtent;
96+
QgsMapCanvas const *mMapCanvas = nullptr;
10297

10398
};
10499

‎src/gui/qgsdatasourcemanagerdialog.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::providerDialog( const Q
185185
// Set crs and extent from canvas
186186
if ( mMapCanvas )
187187
{
188-
dlg->setCurrentExtent( mMapCanvas->extent() );
189-
dlg->setCurrentCrs( mMapCanvas->mapSettings().destinationCrs( ) );
188+
dlg->setMapCanvas( mMapCanvas );
190189
}
191190
return dlg;
192191
}

‎src/providers/arcgisrest/qgsarcgisservicesourceselect.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,6 @@ QgsArcGisServiceSourceSelect::~QgsArcGisServiceSourceSelect()
123123
delete mModelProxy;
124124
}
125125

126-
void QgsArcGisServiceSourceSelect::setCurrentExtentAndCrs( const QgsRectangle &canvasExtent, const QgsCoordinateReferenceSystem &canvasCrs )
127-
{
128-
mCanvasExtent = canvasExtent;
129-
mCanvasCrs = canvasCrs;
130-
}
131126

132127
void QgsArcGisServiceSourceSelect::populateImageEncodings( const QStringList &availableEncodings )
133128
{
@@ -325,15 +320,21 @@ void QgsArcGisServiceSourceSelect::addButtonClicked()
325320
QString pCrsString( labelCoordRefSys->text() );
326321
QgsCoordinateReferenceSystem pCrs( pCrsString );
327322
//prepare canvas extent info for layers with "cache features" option not set
328-
QgsRectangle extent = mCanvasExtent;
323+
QgsRectangle extent;
324+
QgsCoordinateReferenceSystem canvasCrs;
325+
if ( mapCanvas() )
326+
{
327+
extent = mapCanvas()->extent();
328+
canvasCrs = mapCanvas()->mapSettings().destinationCrs();
329+
}
329330
//does canvas have "on the fly" reprojection set?
330-
if ( pCrs.isValid() && mCanvasCrs.isValid() )
331+
if ( pCrs.isValid() && canvasCrs.isValid() )
331332
{
332333
try
333334
{
334-
extent = QgsCoordinateTransform( mCanvasCrs, pCrs ).transform( extent );
335+
extent = QgsCoordinateTransform( canvasCrs, pCrs ).transform( extent );
335336
QgsDebugMsg( QString( "canvas transform: Canvas CRS=%1, Provider CRS=%2, BBOX=%3" )
336-
.arg( mCanvasCrs.authid(), pCrs.authid(), extent.asWktCoordinates() ) );
337+
.arg( canvasCrs.authid(), pCrs.authid(), extent.asWktCoordinates() ) );
337338
}
338339
catch ( const QgsCsException & )
339340
{

‎src/providers/arcgisrest/qgsarcgisservicesourceselect.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class QStandardItemModel;
2727
class QSortFilterProxyModel;
2828
class QgsProjectionSelectionDialog;
2929
class QgsOwsConnection;
30+
class QgsMapCanvas;
3031

3132
/**
3233
* Base class for listing ArcGis layers available from a remote service.
@@ -78,8 +79,6 @@ class QgsArcGisServiceSourceSelect : public QgsAbstractDataSourceWidget, protect
7879
void populateImageEncodings( const QStringList &availableEncodings );
7980
//! Returns the selected image encoding.
8081
QString getSelectedImageEncoding() const;
81-
//! Sets the current extent and CRS. Used to select an appropriate CRS and possibly to retrieve data only in the current extent
82-
void setCurrentExtentAndCrs( const QgsRectangle &canvasExtent, const QgsCoordinateReferenceSystem &canvasCrs );
8382

8483
private:
8584
void populateConnectionList();
@@ -91,6 +90,12 @@ class QgsArcGisServiceSourceSelect : public QgsAbstractDataSourceWidget, protect
9190
\returns the authority id of the crs or an empty string in case of error*/
9291
QString getPreferredCrs( const QSet<QString> &crsSet ) const;
9392

93+
/** Store a pointer to map canvas to retrieve extent and CRS
94+
* Used to select an appropriate CRS and possibly to retrieve data only in the current extent
95+
*/
96+
QgsMapCanvas *mMapCanvas = nullptr;
97+
98+
9499
public slots:
95100

96101
//! Triggered when the provider's connections need to be refreshed

0 commit comments

Comments
 (0)
Please sign in to comment.