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

‎src/providers/arcgisrest/qgsamsdataitems.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void QgsAmsRootItem::newConnection()
7575

7676
if ( nc.exec() )
7777
{
78-
refresh();
78+
refreshConnections();
7979
}
8080
}
8181
#endif
@@ -158,14 +158,14 @@ void QgsAmsConnectionItem::editConnection()
158158

159159
if ( nc.exec() )
160160
{
161-
mParent->refresh();
161+
mParent->refreshConnections();
162162
}
163163
}
164164

165165
void QgsAmsConnectionItem::deleteConnection()
166166
{
167167
QgsOwsConnection::deleteConnection( QStringLiteral( "arcgismapserver" ), mName );
168-
mParent->refresh();
168+
mParent->refreshConnections();
169169
}
170170
#endif
171171

‎src/providers/db2/qgsdb2dataitems.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void QgsDb2ConnectionItem::editConnection()
275275
if ( nc.exec() )
276276
{
277277
// the parent should be updated
278-
mParent->refresh();
278+
mParent->refreshConnections();
279279
}
280280
}
281281

@@ -292,7 +292,7 @@ void QgsDb2ConnectionItem::deleteConnection()
292292
settings.remove( key + "/password" );
293293
settings.remove( key + "/environment" );
294294
settings.remove( key );
295-
mParent->refresh();
295+
mParent->refreshConnections();
296296
}
297297

298298
void QgsDb2ConnectionItem::refreshConnection()
@@ -453,7 +453,7 @@ void QgsDb2RootItem::newConnection()
453453
QgsDb2NewConnection newConnection( NULL, mName );
454454
if ( newConnection.exec() )
455455
{
456-
refresh();
456+
refreshConnections();
457457
}
458458

459459
}

‎src/providers/db2/qgsdb2sourceselect.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,15 @@ void QgsDb2SourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemMod
117117
}
118118

119119
QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
120-
: QDialog( parent, fl )
121-
, mWidgetMode( widgetMode )
120+
: QgsSourceSelect( parent, fl, widgetMode )
122121
, mColumnTypeThread( NULL )
123122
, mUseEstimatedMetadata( false )
124123
{
125124
setupUi( this );
126125

127126
setWindowTitle( tr( "Add Db2 Table(s)" ) );
128127

129-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
128+
if ( QgsSourceSelect::widgetMode() != QgsProviderRegistry::WidgetMode::None )
130129
{
131130
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
132131
mHoldDialogOpen->hide();
@@ -139,7 +138,7 @@ QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
139138
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
140139
mBuildQueryButton->setDisabled( true );
141140

142-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::Manager )
141+
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::Manager )
143142
{
144143
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
145144
connect( mAddButton, &QAbstractButton::clicked, this, &QgsDb2SourceSelect::addTables );
@@ -305,6 +304,11 @@ void QgsDb2SourceSelect::buildQuery()
305304
setSql( mTablesTreeView->currentIndex() );
306305
}
307306

307+
void QgsDb2SourceSelect::refresh()
308+
{
309+
populateConnectionList();
310+
}
311+
308312
void QgsDb2SourceSelect::on_mTablesTreeView_clicked( const QModelIndex &index )
309313
{
310314
mBuildQueryButton->setEnabled( index.parent().isValid() );

‎src/providers/db2/qgsdb2sourceselect.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgsdb2tablemodel.h"
2626
#include "qgshelp.h"
2727
#include "qgsproviderregistry.h"
28+
#include "qgssourceselect.h"
2829

2930
#include <QMap>
3031
#include <QPair>
@@ -87,7 +88,7 @@ class QgsDb2GeomColumnTypeThread : public QThread
8788
* for Db2 databases. The user can then connect and add
8889
* tables from the database to the map canvas.
8990
*/
90-
class QgsDb2SourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
91+
class QgsDb2SourceSelect : public QgsSourceSelect, private Ui::QgsDbSourceSelectBase
9192
{
9293
Q_OBJECT
9394

@@ -97,7 +98,7 @@ class QgsDb2SourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
9798
static void deleteConnection( const QString &key );
9899

99100
//! Constructor
100-
QgsDb2SourceSelect( QWidget *parent = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
101+
QgsDb2SourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
101102

102103
~QgsDb2SourceSelect();
103104
//! Populate the connection list combo box
@@ -109,7 +110,6 @@ class QgsDb2SourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
109110

110111
signals:
111112
void addDatabaseLayers( QStringList const &layerPathList, QString const &providerKey );
112-
void connectionsChanged();
113113
void addGeometryColumn( QgsDb2LayerProperty );
114114
void progress( int, int );
115115
void progressMessage( QString );
@@ -118,6 +118,8 @@ class QgsDb2SourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
118118
//! Determines the tables the user selected and closes the dialog
119119
void addTables();
120120
void buildQuery();
121+
//! Triggered when the provider's connections need to be refreshed
122+
void refresh( ) override;
121123

122124
/** Connects to the database using the stored connection parameters.
123125
* Once connected, available layers are displayed.
@@ -156,9 +158,6 @@ class QgsDb2SourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
156158
typedef QPair<QString, QString> geomPair;
157159
typedef QList<geomPair> geomCol;
158160

159-
//! Embedded mode, without 'Close'
160-
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
161-
162161
// queue another query for the thread
163162
void addSearchGeometryColumn( const QString &connectionName, const QgsDb2LayerProperty &layerProperty, bool estimateMetadata );
164163

‎src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,20 @@
3535
const int MAX_SAMPLE_LENGTH = 200;
3636

3737
QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
38-
: QDialog( parent, fl )
38+
: QgsSourceSelect( parent, fl, widgetMode )
3939
, mFile( new QgsDelimitedTextFile() )
4040
, mExampleRowCount( 20 )
4141
, mBadRowCount( 0 )
4242
, mPluginKey( QStringLiteral( "/Plugin-DelimitedText" ) )
4343
, mLastFileType( QLatin1String( "" ) )
44-
, mWidgetMode( widgetMode )
4544
{
4645

4746
setupUi( this );
4847

4948
QgsSettings settings;
5049
restoreGeometry( settings.value( mPluginKey + "/geometry" ).toByteArray() );
5150

52-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
51+
if ( QgsSourceSelect::widgetMode() != QgsProviderRegistry::WidgetMode::None )
5352
{
5453
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Cancel ) );
5554
buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Add" ) );
@@ -200,7 +199,7 @@ void QgsDelimitedTextSourceSelect::on_buttonBox_accepted()
200199

201200
// add the layer to the map
202201
emit addVectorLayer( QString::fromAscii( url.toEncoded() ), txtLayerName->text(), QStringLiteral( "delimitedtext" ) );
203-
if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
202+
if ( QgsSourceSelect::widgetMode() == QgsProviderRegistry::WidgetMode::None )
204203
{
205204
accept();
206205
}
@@ -743,6 +742,7 @@ bool QgsDelimitedTextSourceSelect::validate()
743742
return enabled;
744743
}
745744

745+
746746
void QgsDelimitedTextSourceSelect::enableAccept()
747747
{
748748
bool enabled = validate();

‎src/providers/delimitedtext/qgsdelimitedtextsourceselect.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgshelp.h"
2020
#include "qgsguiutils.h"
2121
#include "qgsproviderregistry.h"
22+
#include "qgssourceselect.h"
2223

2324
class QButtonGroup;
2425
class QgisInterface;
@@ -27,12 +28,12 @@ class QgsDelimitedTextFile;
2728
/**
2829
* \class QgsDelimitedTextSourceSelect
2930
*/
30-
class QgsDelimitedTextSourceSelect : public QDialog, private Ui::QgsDelimitedTextSourceSelectBase
31+
class QgsDelimitedTextSourceSelect : public QgsSourceSelect, private Ui::QgsDelimitedTextSourceSelectBase
3132
{
3233
Q_OBJECT
3334

3435
public:
35-
QgsDelimitedTextSourceSelect( QWidget *parent, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
36+
QgsDelimitedTextSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
3637
~QgsDelimitedTextSourceSelect();
3738

3839
QStringList splitLine( QString line );
@@ -57,7 +58,6 @@ class QgsDelimitedTextSourceSelect : public QDialog, private Ui::QgsDelimitedTex
5758
QString mLastFileType;
5859
QButtonGroup *bgFileFormat = nullptr;
5960
QButtonGroup *bgGeomType = nullptr;
60-
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
6161

6262
private slots:
6363
void on_buttonBox_accepted();

‎src/providers/mssql/qgsmssqldataitems.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,15 @@ void QgsMssqlConnectionItem::editConnection()
366366
if ( nc.exec() )
367367
{
368368
// the parent should be updated
369-
mParent->refresh();
369+
mParent->refreshConnections();
370370
}
371371
}
372372

373373
void QgsMssqlConnectionItem::deleteConnection()
374374
{
375375
QgsMssqlSourceSelect::deleteConnection( mName );
376376
// the parent should be updated
377-
mParent->refresh();
377+
mParent->refreshConnections();
378378
}
379379
#endif
380380

@@ -633,7 +633,7 @@ void QgsMssqlRootItem::newConnection()
633633
QgsMssqlNewConnection nc( nullptr );
634634
if ( nc.exec() )
635635
{
636-
refresh();
636+
refreshConnections();
637637
}
638638
}
639639
#endif

‎src/providers/mssql/qgsmssqlsourceselect.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,15 @@ void QgsMssqlSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemM
119119
}
120120

121121
QgsMssqlSourceSelect::QgsMssqlSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
122-
: QDialog( parent, fl )
123-
, mWidgetMode( widgetMode )
122+
: QgsSourceSelect( parent, fl, widgetMode )
124123
, mColumnTypeThread( nullptr )
125124
, mUseEstimatedMetadata( false )
126125
{
127126
setupUi( this );
128127

129128
setWindowTitle( tr( "Add MSSQL Table(s)" ) );
130129

131-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
130+
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::None )
132131
{
133132
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
134133
mHoldDialogOpen->hide();
@@ -141,7 +140,7 @@ QgsMssqlSourceSelect::QgsMssqlSourceSelect( QWidget *parent, Qt::WindowFlags fl,
141140
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
142141
mBuildQueryButton->setDisabled( true );
143142

144-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::Manager )
143+
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::Manager )
145144
{
146145
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
147146
connect( mAddButton, &QAbstractButton::clicked, this, &QgsMssqlSourceSelect::addTables );
@@ -657,6 +656,11 @@ QString QgsMssqlSourceSelect::connectionInfo()
657656
return mConnInfo;
658657
}
659658

659+
void QgsMssqlSourceSelect::refresh()
660+
{
661+
populateConnectionList();
662+
}
663+
660664
void QgsMssqlSourceSelect::setSql( const QModelIndex &index )
661665
{
662666
if ( !index.parent().isValid() )

‎src/providers/mssql/qgsmssqlsourceselect.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgsmssqltablemodel.h"
2424
#include "qgshelp.h"
2525
#include "qgsproviderregistry.h"
26+
#include "qgssourceselect.h"
2627

2728
#include <QMap>
2829
#include <QPair>
@@ -57,7 +58,7 @@ class QgsMssqlSourceSelectDelegate : public QItemDelegate
5758
* for MSSQL databases. The user can then connect and add
5859
* tables from the database to the map canvas.
5960
*/
60-
class QgsMssqlSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
61+
class QgsMssqlSourceSelect : public QgsSourceSelect, private Ui::QgsDbSourceSelectBase
6162
{
6263
Q_OBJECT
6364

@@ -79,12 +80,15 @@ class QgsMssqlSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
7980

8081
signals:
8182
void addDatabaseLayers( QStringList const &layerPathList, QString const &providerKey );
82-
void connectionsChanged();
8383
void addGeometryColumn( const QgsMssqlLayerProperty & );
8484
void progress( int, int );
8585
void progressMessage( QString );
8686

8787
public slots:
88+
89+
//! Triggered when the provider's connections need to be refreshed
90+
void refresh( ) override;
91+
8892
//! Determines the tables the user selected and closes the dialog
8993
void addTables();
9094
void buildQuery();
@@ -122,13 +126,11 @@ class QgsMssqlSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
122126

123127
void columnThreadFinished();
124128

129+
125130
private:
126131
typedef QPair<QString, QString> geomPair;
127132
typedef QList<geomPair> geomCol;
128133

129-
//! Embedded mode, without 'Close'
130-
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
131-
132134
// queue another query for the thread
133135
void addSearchGeometryColumn( const QString &connectionName, const QgsMssqlLayerProperty &layerProperty, bool estimateMetadata );
134136

‎src/providers/oracle/qgsoracledataitems.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void QgsOracleConnectionItem::editConnection()
199199
if ( nc.exec() )
200200
{
201201
// the parent should be updated
202-
mParent->refresh();
202+
mParent->refreshConnections();
203203
}
204204
}
205205

@@ -214,7 +214,7 @@ void QgsOracleConnectionItem::deleteConnection()
214214

215215
// the parent should be updated
216216
if ( mParent )
217-
mParent->refresh();
217+
mParent->refreshConnections();
218218
}
219219

220220
void QgsOracleConnectionItem::refreshConnection()
@@ -487,7 +487,7 @@ void QgsOracleRootItem::newConnection()
487487
QgsOracleNewConnection nc( NULL );
488488
if ( nc.exec() )
489489
{
490-
refresh();
490+
refreshConnections();
491491
}
492492
}
493493

‎src/providers/oracle/qgsoraclesourceselect.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,13 @@ void QgsOracleSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItem
167167
}
168168

169169
QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
170-
: QDialog( parent, fl )
171-
, mWidgetMode( widgetMode )
170+
: QgsSourceSelect( parent, fl, widgetMode )
172171
, mColumnTypeThread( 0 )
173172
, mIsConnected( false )
174173
{
175174
setupUi( this );
176175

177-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
176+
if ( QgsSourceSelect::widgetMode( ) == QgsProviderRegistry::WidgetMode::Embedded )
178177
{
179178
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
180179
mHoldDialogOpen->hide();

‎src/providers/oracle/qgsoraclesourceselect.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgshelp.h"
2525
#include "qgsoracleconnpool.h"
2626
#include "qgsproviderregistry.h"
27+
#include "qgssourceselect.h"
2728

2829
#include <QMap>
2930
#include <QPair>
@@ -81,13 +82,13 @@ class QgsOracleSourceSelectDelegate : public QItemDelegate
8182
* for Oracle databases. The user can then connect and add
8283
* tables from the database to the map canvas.
8384
*/
84-
class QgsOracleSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
85+
class QgsOracleSourceSelect : public QgsSourceSelect, private Ui::QgsDbSourceSelectBase
8586
{
8687
Q_OBJECT
8788

8889
public:
8990
//! Constructor
90-
QgsOracleSourceSelect( QWidget *parent = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
91+
QgsOracleSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
9192
//! Destructor
9293
~QgsOracleSourceSelect();
9394
//! Populate the connection list combo box
@@ -97,7 +98,6 @@ class QgsOracleSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
9798

9899
signals:
99100
void addDatabaseLayers( QStringList const &layerPathList, QString const &providerKey );
100-
void connectionsChanged();
101101
void progress( int, int );
102102
void progressMessage( QString );
103103

@@ -143,9 +143,6 @@ class QgsOracleSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
143143
typedef QPair<QString, QString> geomPair;
144144
typedef QList<geomPair> geomCol;
145145

146-
//! Embedded mode, without 'Close'
147-
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
148-
149146
//! try to load list of tables from local cache
150147
void loadTableFromCache();
151148

‎src/providers/ows/qgsowsdataitems.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void QgsOWSConnectionItem::editConnection()
157157
if ( nc.exec() )
158158
{
159159
// the parent should be updated
160-
mParent->refresh();
160+
mParent->refreshConnections();
161161
}
162162
#endif
163163
}
@@ -167,7 +167,7 @@ void QgsOWSConnectionItem::deleteConnection()
167167
#if 0
168168
QgsOWSConnection::deleteConnection( "OWS", mName );
169169
// the parent should be updated
170-
mParent->refresh();
170+
mParent->refreshConnections();
171171
#endif
172172
}
173173
#endif
@@ -247,7 +247,7 @@ void QgsOWSRootItem::newConnection()
247247

248248
if ( nc.exec() )
249249
{
250-
refresh();
250+
refreshConnections();
251251
}
252252
#endif
253253
}

‎src/providers/postgres/qgspgsourceselect.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,13 @@ void QgsPgSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemMode
194194
}
195195

196196
QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
197-
: QDialog( parent, fl )
198-
, mWidgetMode( widgetMode )
197+
: QgsSourceSelect( parent, fl, widgetMode )
199198
, mColumnTypeThread( nullptr )
200199
, mUseEstimatedMetadata( false )
201200
{
202201
setupUi( this );
203202

204-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
203+
if ( QgsSourceSelect::widgetMode() != QgsProviderRegistry::WidgetMode::None )
205204
{
206205
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
207206
mHoldDialogOpen->hide();
@@ -218,7 +217,7 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsPr
218217
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
219218
mBuildQueryButton->setDisabled( true );
220219

221-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::Manager )
220+
if ( QgsSourceSelect::widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
222221
{
223222
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
224223
connect( mAddButton, &QAbstractButton::clicked, this, &QgsPgSourceSelect::addTables );
@@ -509,7 +508,7 @@ void QgsPgSourceSelect::addTables()
509508
else
510509
{
511510
emit addDatabaseLayers( mSelectedTables, QStringLiteral( "postgres" ) );
512-
if ( ! mHoldDialogOpen->isChecked() && mWidgetMode == QgsProviderRegistry::WidgetMode::None )
511+
if ( ! mHoldDialogOpen->isChecked() && QgsSourceSelect::widgetMode( ) == QgsProviderRegistry::WidgetMode::None )
513512
{
514513
accept();
515514
}
@@ -591,6 +590,11 @@ QgsDataSourceUri QgsPgSourceSelect::dataSourceUri()
591590
return mDataSrcUri;
592591
}
593592

593+
void QgsPgSourceSelect::refresh()
594+
{
595+
populateConnectionList();
596+
}
597+
594598
void QgsPgSourceSelect::setSql( const QModelIndex &index )
595599
{
596600
if ( !index.parent().isValid() )

‎src/providers/postgres/qgspgsourceselect.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgspgtablemodel.h"
2525
#include "qgshelp.h"
2626
#include "qgsproviderregistry.h"
27+
#include "qgssourceselect.h"
2728

2829
#include <QMap>
2930
#include <QPair>
@@ -58,7 +59,7 @@ class QgsPgSourceSelectDelegate : public QItemDelegate
5859
* for PostGIS enabled PostgreSQL databases. The user can then connect and add
5960
* tables from the database to the map canvas.
6061
*/
61-
class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
62+
class QgsPgSourceSelect : public QgsSourceSelect, private Ui::QgsDbSourceSelectBase
6263
{
6364
Q_OBJECT
6465

@@ -78,12 +79,13 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
7879

7980
signals:
8081
void addDatabaseLayers( QStringList const &layerPathList, QString const &providerKey );
81-
void connectionsChanged();
8282
void addGeometryColumn( const QgsPostgresLayerProperty & );
8383
void progress( int, int );
8484
void progressMessage( const QString & );
8585

8686
public slots:
87+
//! Triggered when the provider's connections need to be refreshed
88+
void refresh( ) override;
8789
//! Determines the tables the user selected and closes the dialog
8890
void addTables();
8991
void buildQuery();
@@ -125,9 +127,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
125127
typedef QPair<QString, QString> geomPair;
126128
typedef QList<geomPair> geomCol;
127129

128-
//! Embedded mode, without 'Close'
129-
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
130-
131130
// queue another query for the thread
132131
void addSearchGeometryColumn( const QgsPostgresLayerProperty &layerProperty );
133132

‎src/providers/postgres/qgspostgresdataitems.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void QgsPGConnectionItem::editConnection()
134134
{
135135
// the parent should be updated
136136
if ( mParent )
137-
mParent->refresh();
137+
mParent->refreshConnections();
138138
}
139139
}
140140

@@ -148,13 +148,15 @@ void QgsPGConnectionItem::deleteConnection()
148148
QgsPostgresConn::deleteConnection( mName );
149149
// the parent should be updated
150150
if ( mParent )
151-
mParent->refresh();
151+
mParent->refreshConnections();
152152
}
153153

154154
void QgsPGConnectionItem::refreshConnection()
155155
{
156-
// the parent should be updated
157156
refresh();
157+
// the parent should be updated
158+
if ( mParent )
159+
mParent->refreshConnections();
158160
}
159161

160162
void QgsPGConnectionItem::createSchema()
@@ -185,6 +187,9 @@ void QgsPGConnectionItem::createSchema()
185187

186188
conn->unref();
187189
refresh();
190+
// the parent should be updated
191+
if ( mParent )
192+
mParent->refreshConnections();
188193
}
189194
#endif
190195

‎src/providers/spatialite/qgsspatialitedataitems.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void QgsSLConnectionItem::deleteConnection()
193193

194194
QgsSpatiaLiteConnection::deleteConnection( mName );
195195
// the parent should be updated
196-
mParent->refresh();
196+
mParent->refreshConnections();
197197
}
198198
#endif
199199

@@ -326,7 +326,7 @@ void QgsSLRootItem::newConnection()
326326
{
327327
if ( QgsSpatiaLiteSourceSelect::newConnection( nullptr ) )
328328
{
329-
refresh();
329+
refreshConnections();
330330
}
331331
}
332332
#endif

‎src/providers/spatialite/qgsspatialitesourceselect.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ email : a.furieri@lqt.it
4141
#endif
4242

4343
QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
44-
QDialog( parent, fl ),
45-
mWidgetMode( widgetMode )
44+
QgsSourceSelect( parent, fl, widgetMode )
4645
{
4746
setupUi( this );
4847

@@ -67,7 +66,7 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QWidget *parent, Qt::Windo
6766
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsSpatiaLiteSourceSelect::buildQuery );
6867
mBuildQueryButton->setEnabled( false );
6968

70-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
69+
if ( QgsSourceSelect::widgetMode() != QgsProviderRegistry::WidgetMode::None )
7170
{
7271
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
7372
mHoldDialogOpen->hide();
@@ -418,7 +417,7 @@ void QgsSpatiaLiteSourceSelect::addTables()
418417
else
419418
{
420419
emit addDatabaseLayers( m_selectedTables, QStringLiteral( "spatialite" ) );
421-
if ( !mHoldDialogOpen->isChecked() && mWidgetMode == QgsProviderRegistry::WidgetMode::None )
420+
if ( QgsSourceSelect::widgetMode( ) == QgsProviderRegistry::WidgetMode::None && ! mHoldDialogOpen->isChecked() )
422421
{
423422
accept();
424423
}
@@ -555,6 +554,11 @@ void QgsSpatiaLiteSourceSelect::dbChanged()
555554
settings.setValue( QStringLiteral( "SpatiaLite/connections/selected" ), cmbConnections->currentText() );
556555
}
557556

557+
void QgsSpatiaLiteSourceSelect::refresh()
558+
{
559+
populateConnectionList();
560+
}
561+
558562
void QgsSpatiaLiteSourceSelect::setConnectionListPosition()
559563
{
560564
QgsSettings settings;

‎src/providers/spatialite/qgsspatialitesourceselect.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgsspatialitetablemodel.h"
2323
#include "qgshelp.h"
2424
#include "qgsproviderregistry.h"
25+
#include "qgssourceselect.h"
2526

2627
#include <QThread>
2728
#include <QMap>
@@ -41,7 +42,7 @@ class QPushButton;
4142
* for SpatiaLite/SQLite databases. The user can then connect and add
4243
* tables from the database to the map canvas.
4344
*/
44-
class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBase
45+
class QgsSpatiaLiteSourceSelect: public QgsSourceSelect, private Ui::QgsDbSourceSelectBase
4546
{
4647
Q_OBJECT
4748

@@ -51,7 +52,7 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBa
5152
static bool newConnection( QWidget *parent );
5253

5354
//! Constructor
54-
QgsSpatiaLiteSourceSelect( QWidget *parent, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
55+
QgsSpatiaLiteSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
5556

5657
~QgsSpatiaLiteSourceSelect();
5758
//! Populate the connection list combo box
@@ -67,6 +68,9 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBa
6768

6869
public slots:
6970

71+
//! Triggered when the provider's connections need to be refreshed
72+
void refresh( ) override;
73+
7074
/** Connects to the database using the stored connection parameters.
7175
* Once connected, available layers are displayed.
7276
*/
@@ -95,7 +99,6 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBa
9599
void on_buttonBox_helpRequested() { QgsHelp::openHelp( QStringLiteral( "working_with_vector/supported_data.html#spatialite-layers" ) ); }
96100

97101
signals:
98-
void connectionsChanged();
99102
void addDatabaseLayers( QStringList const &paths, QString const &providerKey );
100103
void progress( int, int );
101104
void progressMessage( QString );
@@ -132,7 +135,6 @@ class QgsSpatiaLiteSourceSelect: public QDialog, private Ui::QgsDbSourceSelectBa
132135
QPushButton *mBuildQueryButton = nullptr;
133136
QPushButton *mAddButton = nullptr;
134137
QPushButton *mStatsButton = nullptr;
135-
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
136138
};
137139

138140
#endif // QGSSPATIALITESOURCESELECT_H

‎src/providers/virtual/qgsvirtuallayersourceselect.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ email : hugo dot mercier at oslandia dot com
3838
#include <QTextStream>
3939

4040
QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
41-
: QDialog( parent, fl )
41+
: QgsSourceSelect( parent, fl, widgetMode )
4242
, mSrid( 0 )
43-
, mWidgetMode( widgetMode )
4443
, mTreeView( nullptr )
4544
{
4645
setupUi( this );
4746

48-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
47+
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::None )
4948
{
5049
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Cancel ) );
5150
buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Add" ) );
@@ -95,6 +94,12 @@ QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget *parent, Qt::W
9594
}
9695
}
9796

97+
void QgsVirtualLayerSourceSelect::refresh()
98+
{
99+
// TODO: check that this really works
100+
updateLayersList();
101+
}
102+
98103
void QgsVirtualLayerSourceSelect::onLayerComboChanged( int idx )
99104
{
100105
if ( idx == -1 )
@@ -375,7 +380,7 @@ void QgsVirtualLayerSourceSelect::on_buttonBox_accepted()
375380
{
376381
emit addVectorLayer( def.toString(), layerName, QStringLiteral( "virtual" ) );
377382
}
378-
if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
383+
if ( QgsSourceSelect::widgetMode( ) == QgsProviderRegistry::WidgetMode::None )
379384
{
380385
accept( );
381386
}

‎src/providers/virtual/qgsvirtuallayersourceselect.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,23 @@ email : hugo dot mercier at oslandia dot com
2424
#include "qgsguiutils.h"
2525
#include <qgsvirtuallayerdefinition.h>
2626
#include "qgsproviderregistry.h"
27+
#include "qgssourceselect.h"
2728

2829
class QgsVectorLayer;
2930
class QMainWindow;
3031
class QgsEmbeddedLayerSelectDialog;
3132
class QgsLayerTreeView;
3233

33-
class QgsVirtualLayerSourceSelect : public QDialog, private Ui::QgsVirtualLayerSourceSelectBase
34+
class QgsVirtualLayerSourceSelect : public QgsSourceSelect, private Ui::QgsVirtualLayerSourceSelectBase
3435
{
3536
Q_OBJECT
3637

3738
public:
38-
QgsVirtualLayerSourceSelect( QWidget *parent, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
39+
QgsVirtualLayerSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
40+
41+
public slots:
42+
//! Triggered when the provider's connections need to be refreshed
43+
void refresh( ) override;
3944

4045
private slots:
4146
void on_buttonBox_accepted();
@@ -59,7 +64,6 @@ class QgsVirtualLayerSourceSelect : public QDialog, private Ui::QgsVirtualLayerS
5964
long mSrid;
6065
QStringList mProviderList;
6166
QgsEmbeddedLayerSelectDialog *mEmbeddedSelectionDialog = nullptr;
62-
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
6367
void addEmbeddedLayer( const QString &name, const QString &provider, const QString &encoding, const QString &source );
6468
QgsLayerTreeView *mTreeView = nullptr;
6569
};

‎src/providers/wcs/qgswcsdataitems.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ void QgsWCSConnectionItem::editConnection()
108108
if ( nc.exec() )
109109
{
110110
// the parent should be updated
111-
mParent->refresh();
111+
mParent->refreshConnections();
112112
}
113113
}
114114

115115
void QgsWCSConnectionItem::deleteConnection()
116116
{
117117
QgsOwsConnection::deleteConnection( QStringLiteral( "WCS" ), mName );
118118
// the parent should be updated
119-
mParent->refresh();
119+
mParent->refreshConnections();
120120
}
121121
#endif
122122

@@ -276,7 +276,7 @@ void QgsWCSRootItem::newConnection()
276276

277277
if ( nc.exec() )
278278
{
279-
refresh();
279+
refreshConnections();
280280
}
281281
}
282282
#endif

‎src/providers/wfs/qgswfsdataitems.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ void QgsWfsConnectionItem::editConnection()
114114
if ( nc.exec() )
115115
{
116116
// the parent should be updated
117-
mParent->refresh();
117+
mParent->refreshConnections();
118118
}
119119
}
120120

121121
void QgsWfsConnectionItem::deleteConnection()
122122
{
123123
QgsWfsConnection::deleteConnection( mName );
124124
// the parent should be updated
125-
mParent->refresh();
125+
mParent->refreshConnections();
126126
}
127127
#endif
128128

@@ -187,7 +187,7 @@ void QgsWfsRootItem::newConnection()
187187

188188
if ( nc.exec() )
189189
{
190-
refresh();
190+
refreshConnections();
191191
}
192192
}
193193
#endif

‎src/providers/wfs/qgswfssourceselect.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@ enum
4949
};
5050

5151
QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
52-
: QDialog( parent, fl )
52+
: QgsSourceSelect( parent, fl, widgetMode )
5353
, mCapabilities( nullptr )
5454
, mSQLComposerDialog( nullptr )
55-
, mWidgetMode( widgetMode )
5655
{
5756
setupUi( this );
5857

59-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
58+
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::None )
6059
{
6160
// For some obscure reason hiding does not work!
6261
// buttonBox->button( QDialogButtonBox::Close )->hide();
@@ -206,6 +205,11 @@ QString QgsWFSSourceSelect::getPreferredCrs( const QSet<QString> &crsSet ) const
206205
return *( crsSet.constBegin() );
207206
}
208207

208+
void QgsWFSSourceSelect::refresh()
209+
{
210+
populateConnectionList();
211+
}
212+
209213
void QgsWFSSourceSelect::capabilitiesReplyFinished()
210214
{
211215
btnConnect->setEnabled( true );
@@ -404,7 +408,7 @@ void QgsWFSSourceSelect::addLayer()
404408
emit addWfsLayer( mUri, layerName );
405409
}
406410

407-
if ( !mHoldDialogOpen->isChecked() && mWidgetMode == QgsProviderRegistry::WidgetMode::None )
411+
if ( ! mHoldDialogOpen->isChecked() && QgsSourceSelect::widgetMode( ) == QgsProviderRegistry::WidgetMode::None )
408412
{
409413
accept();
410414
}

‎src/providers/wfs/qgswfssourceselect.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgscontexthelp.h"
2323
#include "qgswfscapabilities.h"
2424
#include "qgsproviderregistry.h"
25+
#include "qgssourceselect.h"
2526

2627
#include <QItemDelegate>
2728
#include <QStandardItemModel>
@@ -42,18 +43,17 @@ class QgsWFSItemDelegate : public QItemDelegate
4243

4344
};
4445

45-
class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
46+
class QgsWFSSourceSelect: public QgsSourceSelect, private Ui::QgsWFSSourceSelectBase
4647
{
4748
Q_OBJECT
4849

4950
public:
5051

51-
QgsWFSSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode );
52+
QgsWFSSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
5253
~QgsWFSSourceSelect();
5354

5455
signals:
5556
void addWfsLayer( const QString &uri, const QString &layerName );
56-
void connectionsChanged();
5757

5858
private:
5959
QgsWFSSourceSelect(); //default constructor is forbidden
@@ -73,8 +73,6 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
7373
QgsWfsCapabilities::Capabilities mCaps;
7474
QModelIndex mSQLIndex;
7575
QgsSQLComposerDialog *mSQLComposerDialog = nullptr;
76-
//! Embedded mode, without 'Close'
77-
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
7876

7977
/** Returns the best suited CRS from a set of authority ids
8078
1. project CRS if contained in the set
@@ -83,6 +81,11 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
8381
\returns the authority id of the crs or an empty string in case of error*/
8482
QString getPreferredCrs( const QSet<QString> &crsSet ) const;
8583

84+
public slots:
85+
86+
//! Triggered when the provider's connections need to be refreshed
87+
void refresh( ) override;
88+
8689
private slots:
8790
void addEntryToServerList();
8891
void modifyEntryOfServerList();

0 commit comments

Comments
 (0)
Please sign in to comment.