Skip to content

Commit aba9da5

Browse files
committedJul 18, 2017
Refactored all providers to use the new base class
Also use refreshConnections from the data items when a refresh is required, this function also emits the signal to update the other GUI elements.
1 parent 1e6a4ab commit aba9da5

35 files changed

+213
-148
lines changed
 

‎python/gui/qgsarcgisservicesourceselect.sip

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111

1212

13-
class QgsArcGisServiceSourceSelect : QDialog, protected Ui::QgsArcGisServiceSourceSelectBase
13+
14+
class QgsArcGisServiceSourceSelect : QgsSourceSelect, protected Ui::QgsArcGisServiceSourceSelectBase
1415
{
1516
%Docstring
16-
Generic class listing layers available from a remote service.
17-
.. versionadded:: 3.0
17+
Base class for listing ArcGis layers available from a remote service.
1818
%End
1919

2020
%TypeHeaderCode
@@ -23,7 +23,7 @@ class QgsArcGisServiceSourceSelect : QDialog, protected Ui::QgsArcGisServiceSour
2323
public:
2424
enum ServiceType { MapService, FeatureService };
2525

26-
QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl );
26+
QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
2727
%Docstring
2828
Constructor
2929
%End
@@ -38,10 +38,6 @@ Sets the current extent and CRS. Used to select an appropriate CRS and possibly
3838
void addLayer( QString uri, QString typeName );
3939
%Docstring
4040
Emitted when a layer is added from the dialog
41-
%End
42-
void connectionsChanged();
43-
%Docstring
44-
Emitted when the connections for the service were changed
4541
%End
4642

4743
protected:
@@ -75,6 +71,14 @@ Returns the selected image encoding.
7571
:rtype: str
7672
%End
7773

74+
public slots:
75+
76+
virtual void refresh( );
77+
78+
%Docstring
79+
Triggered when the provider's connections need to be refreshed
80+
%End
81+
7882
};
7983

8084

‎python/gui/qgsowssourceselect.sip

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212

1313

14-
class QgsOWSSourceSelect : QDialog, protected Ui::QgsOWSSourceSelectBase
14+
class QgsOWSSourceSelect : QgsSourceSelect, protected Ui::QgsOWSSourceSelectBase
1515
{
1616
%Docstring
17-
Dialog to create connections and add layers from WMS, WFS, WCS etc.
17+
Dialog to create connections and add layers WCS etc.
1818

1919
This dialog allows the user to define and save connection information
2020
for WMS servers, etc.
2121

2222
The user can then connect and add
23-
layers from the WMS server to the map canvas.
23+
layers from the WCS server to the map canvas.
2424
%End
2525

2626
%TypeHeaderCode
@@ -42,6 +42,12 @@ Constructor
4242

4343
public slots:
4444

45+
virtual void refresh( );
46+
47+
%Docstring
48+
Triggered when the provider's connections need to be refreshed
49+
%End
50+
4551
void on_mNewButton_clicked();
4652
%Docstring
4753
Opens the create connection dialog to build a new connection
@@ -110,7 +116,6 @@ Add some default wms servers to the list
110116
void addRasterLayer( const QString &rasterLayerPath,
111117
const QString &baseName,
112118
const QString &providerKey );
113-
void connectionsChanged();
114119

115120
protected:
116121

@@ -198,8 +203,6 @@ Add a few example servers to the list.
198203
%End
199204

200205

201-
202-
203206
virtual void populateLayerList();
204207
%Docstring
205208
Populate the layer list.

‎python/gui/qgssourceselect.sip

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class QgsSourceSelect : QDialog
1414
{
1515
%Docstring
16-
Abstract base Dialog to create connections and add layers
16+
Abstract base Data Source Widget to create connections and add layers
1717
This class must provide common functionality and the interface for all
1818
source select dialogs used by data providers to configure data sources
1919
and add layers.
@@ -30,9 +30,9 @@ class QgsSourceSelect : QDialog
3030
Constructor
3131
%End
3232

33-
~QgsSourceSelect( );
33+
virtual ~QgsSourceSelect( ) = 0;
3434
%Docstring
35-
Destructor
35+
Pure Virtual Destructor
3636
%End
3737

3838
QgsProviderRegistry::WidgetMode widgetMode( );
@@ -43,9 +43,9 @@ Return the widget mode
4343

4444
public slots:
4545

46-
virtual void refresh( ) = 0;
46+
virtual void refresh( );
4747
%Docstring
48-
Triggered when the provider's connections need to be refreshed
48+
The default implementation does nothing
4949
%End
5050

5151
signals:

‎src/gui/qgsarcgisservicesourceselect.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
#include <QRadioButton>
3838
#include <QImageReader>
3939

40-
/** \ingroup gui
40+
/**
4141
* Item delegate with tweaked sizeHint.
42-
* @note not available in Python bindings */
42+
*/
4343
class QgsSourceSelectItemDelegate : public QItemDelegate
4444
{
4545
public:
@@ -49,12 +49,12 @@ class QgsSourceSelectItemDelegate : public QItemDelegate
4949
};
5050

5151

52-
QgsArcGisServiceSourceSelect::QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl )
53-
: QDialog( parent, fl ),
54-
mServiceName( serviceName ),
55-
mServiceType( serviceType ),
56-
mBuildQueryButton( 0 ),
57-
mImageEncodingGroup( 0 )
52+
QgsArcGisServiceSourceSelect::QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
53+
QgsSourceSelect( parent, fl, widgetMode ),
54+
mServiceName( serviceName ),
55+
mServiceType( serviceType ),
56+
mBuildQueryButton( 0 ),
57+
mImageEncodingGroup( 0 )
5858
{
5959
setupUi( this );
6060
setWindowTitle( QStringLiteral( "Add %1 Layer from a Server" ).arg( mServiceName ) );
@@ -221,6 +221,11 @@ QString QgsArcGisServiceSourceSelect::getPreferredCrs( const QSet<QString> &crsS
221221
return *( crsSet.constBegin() );
222222
}
223223

224+
void QgsArcGisServiceSourceSelect::refresh()
225+
{
226+
populateConnectionList();
227+
}
228+
224229
void QgsArcGisServiceSourceSelect::addEntryToServerList()
225230
{
226231

‎src/gui/qgsarcgisservicesourceselect.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,32 @@
1616
#ifndef QGSARCGISSERVICESOURCESELECTDIALOG_H
1717
#define QGSARCGISSERVICESOURCESELECTDIALOG_H
1818

19+
/// @cond PRIVATE
20+
21+
//
22+
// W A R N I N G
23+
// -------------
24+
//
25+
// This file is not part of the QGIS API. It exists purely as an
26+
// implementation detail. This header file may change from version to
27+
// version without notice, or even be removed.
28+
//
29+
1930
#include "ui_qgsarcgisservicesourceselectbase.h"
2031
#include "qgsrectangle.h"
2132
#include "qgscoordinatereferencesystem.h"
22-
33+
#include "qgssourceselect.h"
2334
#include "qgis_gui.h"
2435

2536
class QStandardItemModel;
2637
class QSortFilterProxyModel;
2738
class QgsProjectionSelectionDialog;
2839
class QgsOwsConnection;
2940

30-
/** \ingroup gui
31-
* Generic class listing layers available from a remote service.
32-
* \since QGIS 3.0
41+
/**
42+
* Base class for listing ArcGis layers available from a remote service.
3343
*/
34-
class GUI_EXPORT QgsArcGisServiceSourceSelect : public QDialog, protected Ui::QgsArcGisServiceSourceSelectBase
44+
class GUI_EXPORT QgsArcGisServiceSourceSelect : public QgsSourceSelect, protected Ui::QgsArcGisServiceSourceSelectBase
3545
{
3646
Q_OBJECT
3747

@@ -40,7 +50,7 @@ class GUI_EXPORT QgsArcGisServiceSourceSelect : public QDialog, protected Ui::Qg
4050
enum ServiceType { MapService, FeatureService };
4151

4252
//! Constructor
43-
QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl );
53+
QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
4454

4555
~QgsArcGisServiceSourceSelect();
4656
//! Sets the current extent and CRS. Used to select an appropriate CRS and possibly to retrieve data only in the current extent
@@ -49,8 +59,6 @@ class GUI_EXPORT QgsArcGisServiceSourceSelect : public QDialog, protected Ui::Qg
4959
signals:
5060
//! Emitted when a layer is added from the dialog
5161
void addLayer( QString uri, QString typeName );
52-
//! Emitted when the connections for the service were changed
53-
void connectionsChanged();
5462

5563
protected:
5664
QString mServiceName;
@@ -92,6 +100,11 @@ class GUI_EXPORT QgsArcGisServiceSourceSelect : public QDialog, protected Ui::Qg
92100
\returns the authority id of the crs or an empty string in case of error*/
93101
QString getPreferredCrs( const QSet<QString> &crsSet ) const;
94102

103+
public slots:
104+
105+
//! Triggered when the provider's connections need to be refreshed
106+
void refresh( ) override;
107+
95108
private slots:
96109
void addEntryToServerList();
97110
void deleteEntryOfServerList();

‎src/gui/qgsbrowserdockwidget_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class QgsLayerItem;
5050
class QgsDataItem;
5151
class QgsBrowserTreeFilterProxyModel;
5252

53-
SIP_NO_FILE
53+
#define SIP_NO_FILE
5454

5555
/**
5656
* Hack to show wrapped text without spaces

‎src/gui/qgsdatasourcemanagerdialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
117117
this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) );
118118
} );
119119
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
120+
connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) );
120121
}
121122

122123
addRasterProviderDialog( QStringLiteral( "arcgismapserver" ), tr( "ArcGIS Map Server" ), QStringLiteral( "/mActionAddAmsLayer.svg" ) );
@@ -129,6 +130,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
129130
afss->setCurrentExtentAndCrs( mMapCanvas->extent(), mMapCanvas->mapSettings().destinationCrs() );
130131
// Forward (if only a common interface for the signals had been used in the providers ...)
131132
connect( afss, SIGNAL( addLayer( QString, QString ) ), this, SIGNAL( addAfsLayer( QString, QString ) ) );
133+
connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), afss, SLOT( refresh( ) ) );
132134
connect( this, &QgsDataSourceManagerDialog::addAfsLayer,
133135
this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
134136
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "arcgisfeatureserver" ) ); } );
@@ -234,6 +236,5 @@ void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString provider
234236
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
235237
this, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ) );
236238
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
237-
connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) );
238239
}
239240
}

‎src/gui/qgsowssourceselect.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,13 @@
5555
#include <QNetworkReply>
5656

5757
QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
58-
: QDialog( parent, fl )
58+
: QgsSourceSelect( parent, fl, widgetMode )
5959
, mService( service )
60-
, mWidgetMode( widgetMode )
6160
, mCurrentTileset( nullptr )
6261
{
6362
setupUi( this );
6463

65-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
64+
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::None )
6665
{
6766
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
6867
}
@@ -89,7 +88,7 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
8988
// 'Prefer network' is the default noted in the combobox's tool tip
9089
mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );
9190

92-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::Manager )
91+
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::Manager )
9392
{
9493
connect( mAddButton, &QAbstractButton::clicked, this, &QgsOWSSourceSelect::addClicked );
9594
//set the current project CRS if available
@@ -126,6 +125,11 @@ QgsOWSSourceSelect::~QgsOWSSourceSelect()
126125
settings.setValue( QStringLiteral( "Windows/WMSSourceSelect/geometry" ), saveGeometry() );
127126
}
128127

128+
void QgsOWSSourceSelect::refresh()
129+
{
130+
populateConnectionList();
131+
}
132+
129133
void QgsOWSSourceSelect::clearFormats()
130134
{
131135
mFormatComboBox->clear();

‎src/gui/qgsowssourceselect.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsguiutils.h"
2727
#include "qgscontexthelp.h"
2828
#include "qgsproviderregistry.h"
29+
#include "qgssourceselect.h"
2930

3031
#include <QStringList>
3132
#include <QPushButton>
@@ -40,15 +41,15 @@ class QDomElement;
4041

4142

4243
/** \ingroup gui
43-
* \brief Dialog to create connections and add layers from WMS, WFS, WCS etc.
44+
* \brief Dialog to create connections and add layers WCS etc.
4445
*
4546
* This dialog allows the user to define and save connection information
4647
* for WMS servers, etc.
4748
*
4849
* The user can then connect and add
49-
* layers from the WMS server to the map canvas.
50+
* layers from the WCS server to the map canvas.
5051
*/
51-
class GUI_EXPORT QgsOWSSourceSelect : public QDialog, protected Ui::QgsOWSSourceSelectBase
52+
class GUI_EXPORT QgsOWSSourceSelect : public QgsSourceSelect, protected Ui::QgsOWSSourceSelectBase
5253
{
5354
Q_OBJECT
5455

@@ -67,6 +68,9 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, protected Ui::QgsOWSSource
6768

6869
public slots:
6970

71+
//! Triggered when the provider's connections need to be refreshed
72+
void refresh( ) override;
73+
7074
//! Opens the create connection dialog to build a new connection
7175
void on_mNewButton_clicked();
7276
//! Opens a dialog to edit an existing connection
@@ -110,7 +114,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, protected Ui::QgsOWSSource
110114
void addRasterLayer( const QString &rasterLayerPath,
111115
const QString &baseName,
112116
const QString &providerKey );
113-
void connectionsChanged();
114117

115118
protected:
116119

@@ -167,10 +170,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, protected Ui::QgsOWSSource
167170
//! Service name
168171
QString mService;
169172

170-
//! Embedded mode, without 'Close'
171-
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
172-
173-
174173
/**
175174
* \brief Populate the layer list.
176175
*

‎src/gui/qgssourceselect.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <QDialog>
2828

2929
/** \ingroup gui
30-
* \brief Abstract base Dialog to create connections and add layers
30+
* \brief Abstract base Data Source Widget to create connections and add layers
3131
* This class must provide common functionality and the interface for all
3232
* source select dialogs used by data providers to configure data sources
3333
* and add layers.
@@ -42,16 +42,17 @@ class GUI_EXPORT QgsSourceSelect : public QDialog
4242
//! Constructor
4343
QgsSourceSelect( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
4444

45-
//! Destructor
46-
~QgsSourceSelect( );
45+
//! Pure Virtual Destructor
46+
virtual ~QgsSourceSelect( ) = 0;
4747

4848
//! Return the widget mode
4949
QgsProviderRegistry::WidgetMode widgetMode( ) { return mWidgetMode; }
5050

5151
public slots:
5252

5353
//! Triggered when the provider's connections need to be refreshed
54-
virtual void refresh( ) = 0;
54+
//! The default implementation does nothing
55+
virtual void refresh( ) {}
5556

5657
signals:
5758

0 commit comments

Comments
 (0)
Please sign in to comment.