Skip to content

Commit e57399b

Browse files
committed
[bugfix] Sync the dialogs connections when changed from the browser
For now it's only for WMS but you get the idea. There is a new abstract base class for the source select dialogs, that will grow with common behavior for all the select dialogs. Signals are forwarded from the (root) data items to the app and then delivered to the various browser instances and to the unified layer dialog. A change in one of the browser items should trigger a refresh in all the other browsers and dialogs.
1 parent 9ff73c0 commit e57399b

18 files changed

+166
-25
lines changed

python/core/qgsbrowsermodel.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ Refresh item children
138138
void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
139139
%Docstring
140140
Emitted when item children fetch was finished
141+
%End
142+
void connectionsChanged( );
143+
%Docstring
144+
notify the provider dialogs of a changed connection
141145
%End
142146

143147
public slots:

python/core/qgsdataitem.sip

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ Remove children recursively and set as not populated. This is used when refreshi
304304

305305
virtual void refresh();
306306

307+
virtual void refreshConnections();
308+
%Docstring
309+
Refresh connections: update GUI and emit signal
310+
%End
311+
307312
virtual void childrenCreated();
308313

309314
signals:
@@ -313,6 +318,10 @@ Remove children recursively and set as not populated. This is used when refreshi
313318
void endRemoveItems();
314319
void dataChanged( QgsDataItem *item );
315320
void stateChanged( QgsDataItem *item, QgsDataItem::State oldState );
321+
void connectionsChanged( );
322+
%Docstring
323+
Emitted when the provider's connections of the child items have changed
324+
%End
316325

317326
protected slots:
318327

python/gui/qgsbrowserdockwidget.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Toggle fast scan
105105

106106
void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
107107
%Docstring
108-
Selection hass changed
108+
Selection has changed
109109
%End
110110
void splitterMoved();
111111
%Docstring

src/core/qgsbrowsermodel.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ void QgsBrowserModel::addRootItems()
139139
QgsDataItem *item = pr->createDataItem( QLatin1String( "" ), nullptr ); // empty path -> top level
140140
if ( item )
141141
{
142+
// Forward the signal from the root items to the model (and then to the app)
143+
connect( item, &QgsDataItem::connectionsChanged, this, &QgsBrowserModel::connectionsChanged );
142144
QgsDebugMsgLevel( "Add new top level item : " + item->name(), 4 );
143145
connectItem( item );
144146
providerMap.insertMulti( capabilities, item );
@@ -411,6 +413,7 @@ void QgsBrowserModel::itemStateChanged( QgsDataItem *item, QgsDataItem::State ol
411413
QgsDebugMsgLevel( QString( "item %1 state changed %2 -> %3" ).arg( item->path() ).arg( oldState ).arg( item->state() ), 4 );
412414
emit stateChanged( idx, oldState );
413415
}
416+
414417
void QgsBrowserModel::connectItem( QgsDataItem *item )
415418
{
416419
connect( item, &QgsDataItem::beginInsertItems,
@@ -425,6 +428,11 @@ void QgsBrowserModel::connectItem( QgsDataItem *item )
425428
this, &QgsBrowserModel::itemDataChanged );
426429
connect( item, &QgsDataItem::stateChanged,
427430
this, &QgsBrowserModel::itemStateChanged );
431+
432+
// if it's a collection item, also forwards connectionsChanged
433+
QgsDataCollectionItem *collectionItem = dynamic_cast<QgsDataCollectionItem *>( item );
434+
if ( collectionItem )
435+
connect( collectionItem, &QgsDataCollectionItem::connectionsChanged, this, &QgsBrowserModel::connectionsChanged );
428436
}
429437

430438
QStringList QgsBrowserModel::mimeTypes() const

src/core/qgsbrowsermodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
134134
signals:
135135
//! Emitted when item children fetch was finished
136136
void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
137+
//! Connections changed in the browser, forwarded to the widget and used to
138+
//! notify the provider dialogs of a changed connection
139+
void connectionsChanged( );
137140

138141
public slots:
139142
//! Reload the whole model

src/core/qgsdataitem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ void QgsDataItem::refresh()
342342
}
343343
}
344344

345+
void QgsDataItem::refreshConnections()
346+
{
347+
refresh( );
348+
emit connectionsChanged( );
349+
}
350+
345351
void QgsDataItem::refresh( const QVector<QgsDataItem *> &children )
346352
{
347353
QgsDebugMsgLevel( "mPath = " + mPath, 2 );

src/core/qgsdataitem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ class CORE_EXPORT QgsDataItem : public QObject
283283

284284
virtual void refresh();
285285

286+
//! Refresh connections: update GUI and emit signal
287+
virtual void refreshConnections();
288+
286289
virtual void childrenCreated();
287290

288291
signals:
@@ -292,6 +295,8 @@ class CORE_EXPORT QgsDataItem : public QObject
292295
void endRemoveItems();
293296
void dataChanged( QgsDataItem *item );
294297
void stateChanged( QgsDataItem *item, QgsDataItem::State oldState );
298+
//! Emitted when the provider's connections of the child items have changed
299+
void connectionsChanged( );
295300

296301
protected slots:
297302

src/gui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ SET(QGIS_GUI_SRCS
346346
qgsvertexmarker.cpp
347347
qgsfiledownloader.cpp
348348
qgsdatasourcemanagerdialog.cpp
349+
qgssourceselect.cpp
349350
)
350351

351352
SET(QGIS_GUI_MOC_HDRS
@@ -502,6 +503,7 @@ SET(QGIS_GUI_MOC_HDRS
502503
ogr/qgsopenvectorlayerdialog.h
503504
ogr/qgsnewogrconnection.h
504505
ogr/qgsvectorlayersaveasdialog.h
506+
qgssourceselect.h
505507

506508
raster/qgsmultibandcolorrendererwidget.h
507509
raster/qgspalettedrendererwidget.h
@@ -710,6 +712,7 @@ SET(QGIS_GUI_HDRS
710712
ogr/qgsnewogrconnection.h
711713
ogr/qgsvectorlayersaveasdialog.h
712714

715+
qgssourceselect.h
713716

714717
attributetable/qgsfeaturemodel.h
715718

src/gui/qgsbrowserdockwidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ void QgsBrowserDockWidget::showEvent( QShowEvent *e )
129129
connect( mBrowserView->selectionModel(), &QItemSelectionModel::selectionChanged,
130130
this, &QgsBrowserDockWidget::selectionChanged );
131131

132+
// Forward the model changed signals to the widget
133+
connect( mModel, &QgsBrowserModel::connectionsChanged,
134+
this, &QgsBrowserDockWidget::connectionsChanged );
135+
136+
132137
// objectName used by settingsSection() is not yet set in constructor
133138
QgsSettings settings;
134139
mPropertiesWidgetEnabled = settings.value( settingsSection() + "/propertiesWidgetEnabled", false ).toBool();

src/gui/qgsbrowserdockwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
9292
//! Toggle fast scan
9393
void toggleFastScan();
9494

95-
//! Selection hass changed
95+
//! Selection has changed
9696
void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
9797
//! Splitter has been moved
9898
void splitterMoved();

src/gui/qgsdatasourcemanagerdialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void QgsDataSourceManagerDialog::setPreviousPage()
171171
void QgsDataSourceManagerDialog::refresh()
172172
{
173173
mBrowserWidget->refresh( );
174-
emit dlg_refresh();
174+
emit providerDialogsRefreshRequested();
175175
}
176176

177177
void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
@@ -221,7 +221,7 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
221221
connect( dlg, SIGNAL( progressMessage( QString ) ),
222222
this, SIGNAL( showStatusMessage( QString ) ) );
223223
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
224-
connect( this, SIGNAL( dlg_refresh( ) ), dlg, SLOT( refresh( ) ) );
224+
connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) );
225225
}
226226
}
227227

@@ -234,6 +234,6 @@ void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString provider
234234
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
235235
this, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ) );
236236
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
237-
connect( this, SIGNAL( dlg_refresh( ) ), dlg, SLOT( refresh( ) ) );
237+
connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) );
238238
}
239239
}

src/gui/qgsdatasourcemanagerdialog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
106106
void updateProjectHome();
107107
//! Connections changed
108108
void connectionsChanged( );
109-
// internal signal
110-
void dlg_refresh( );
109+
//! One or more provider connections have changed and the
110+
//! dialogs should be refreshed
111+
void providerDialogsRefreshRequested( );
111112

112113
private:
113114
//! Return the dialog from the provider

src/gui/qgssourceselect.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/***************************************************************************
2+
qgssourceselect.cpp - base class for source selector widgets
3+
-------------------
4+
begin : 10 July 2017
5+
original : (C) 2017 by Alessandro Pasotti email : apasotti at boundlessgeo dot com
6+
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 "qgssourceselect.h"
19+
20+
QgsSourceSelect::QgsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
21+
QDialog( parent, fl ),
22+
mWidgetMode( widgetMode )
23+
{
24+
25+
}
26+
27+
QgsSourceSelect::~QgsSourceSelect()
28+
{
29+
30+
}

src/gui/qgssourceselect.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/***************************************************************************
2+
qgssourceselect.h - base class for source selector widgets
3+
-------------------
4+
begin : 10 July 2017
5+
original : (C) 2017 by Alessandro Pasotti email : apasotti at boundlessgeo dot com
6+
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+
#ifndef QGSSOURCESELECT_H
19+
#define QGSSOURCESELECT_H
20+
#include "qgis_sip.h"
21+
#include "qgis.h"
22+
#include "qgis_gui.h"
23+
24+
#include "qgsproviderregistry.h"
25+
#include "qgsguiutils.h"
26+
27+
#include <QDialog>
28+
29+
/** \ingroup gui
30+
* \brief Abstract base Dialog to create connections and add layers
31+
* This class must provide common functionality and the interface for all
32+
* source select dialogs used by data providers to configure data sources
33+
* and add layers.
34+
*/
35+
class GUI_EXPORT QgsSourceSelect : public QDialog
36+
{
37+
Q_OBJECT
38+
39+
public:
40+
41+
//! Constructor
42+
QgsSourceSelect( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
43+
44+
//! Destructor
45+
~QgsSourceSelect( );
46+
47+
//! Return the widget mode
48+
QgsProviderRegistry::WidgetMode widgetMode( ) { return mWidgetMode; }
49+
50+
public slots:
51+
52+
//! Triggered when the provider's connections need to be refreshed
53+
virtual void refresh( ) = 0;
54+
55+
signals:
56+
57+
//! Emitted when the provider's connections have changed
58+
void connectionsChanged();
59+
60+
private:
61+
62+
QgsProviderRegistry::WidgetMode mWidgetMode;
63+
};
64+
65+
#endif // QGSSOURCESELECT_H

src/providers/wms/qgswmsdataitems.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,15 @@ void QgsWMSConnectionItem::editConnection()
241241
if ( nc.exec() )
242242
{
243243
// the parent should be updated
244-
mParent->refresh();
244+
mParent->refreshConnections();
245245
}
246246
}
247247

248248
void QgsWMSConnectionItem::deleteConnection()
249249
{
250250
QgsWMSConnection::deleteConnection( mName );
251251
// the parent should be updated
252-
mParent->refresh();
252+
mParent->refreshConnections();
253253
}
254254
#endif
255255

@@ -418,22 +418,16 @@ QList<QAction *> QgsWMSRootItem::actions()
418418
QWidget *QgsWMSRootItem::paramWidget()
419419
{
420420
QgsWMSSourceSelect *select = new QgsWMSSourceSelect( nullptr, 0, QgsProviderRegistry::WidgetMode::Manager );
421-
connect( select, &QgsWMSSourceSelect::connectionsChanged, this, &QgsWMSRootItem::connectionsChanged );
422421
return select;
423422
}
424423

425-
void QgsWMSRootItem::connectionsChanged()
426-
{
427-
refresh();
428-
}
429-
430424
void QgsWMSRootItem::newConnection()
431425
{
432426
QgsNewHttpConnection nc( nullptr );
433427

434428
if ( nc.exec() )
435429
{
436-
refresh();
430+
refreshConnections( );
437431
}
438432
}
439433
#endif

src/providers/wms/qgswmsdataitems.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ class QgsWMSRootItem : public QgsDataCollectionItem
107107

108108
public slots:
109109
#ifdef HAVE_GUI
110-
void connectionsChanged();
111110
void newConnection();
112111
#endif
112+
113113
};
114114

115115

src/providers/wms/qgswmssourceselect.cpp

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

5757
QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
58-
: QDialog( parent, fl )
59-
, mWidgetMode( widgetMode )
58+
: QgsSourceSelect( parent, fl, widgetMode )
6059
, mDefaultCRS( GEO_EPSG_CRS_AUTHID )
6160
, mCurrentTileset( nullptr )
6261
{
6362
setupUi( this );
6463

65-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
64+
if ( QgsSourceSelect::widgetMode() != QgsProviderRegistry::WidgetMode::None )
6665
{
6766
// For some obscure reason hiding does not work!
6867
// buttonBox->button( QDialogButtonBox::Close )->hide();
@@ -81,7 +80,7 @@ QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
8180

8281
mImageFormatGroup = new QButtonGroup;
8382

84-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::Manager )
83+
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::Manager )
8584
{
8685
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
8786
connect( mAddButton, &QAbstractButton::clicked, this, &QgsWMSSourceSelect::addClicked );
@@ -156,6 +155,13 @@ QgsWMSSourceSelect::~QgsWMSSourceSelect()
156155
settings.setValue( QStringLiteral( "Windows/WMSSourceSelect/geometry" ), saveGeometry() );
157156
}
158157

158+
void QgsWMSSourceSelect::refresh( )
159+
{
160+
// Reload WMS connections and update the GUI
161+
QgsDebugMsg( "Refreshing WMS connections ..." );
162+
populateConnectionList( );
163+
}
164+
159165

160166
void QgsWMSSourceSelect::populateConnectionList()
161167
{
@@ -164,6 +170,7 @@ void QgsWMSSourceSelect::populateConnectionList()
164170

165171
setConnectionListPosition();
166172
}
173+
167174
void QgsWMSSourceSelect::on_btnNew_clicked()
168175
{
169176
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this );

0 commit comments

Comments
 (0)