From a6875a7c781d5a623dd6e8eaaec4808bbea48b94 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Thu, 25 Jul 2019 11:13:16 +0200 Subject: [PATCH] Reset selection when data source select dialog is reopened When the data source select dialog is closed and reopened it's much more likely that the user wants to add a different layer than last time he was using the dialog. So instead of offering him to add the same layer again, the selection is cleared and he is requested to make a new selection. --- .../qgsabstractdatasourcewidget.sip.in | 11 +++++++++++ src/app/qgisapp.cpp | 4 ++++ src/gui/qgsabstractdatasourcewidget.cpp | 8 ++++++++ src/gui/qgsabstractdatasourcewidget.h | 13 ++++++++++++- src/gui/qgsdatasourcemanagerdialog.cpp | 13 +++++++++++++ src/gui/qgsdatasourcemanagerdialog.h | 2 ++ src/gui/qgsowssourceselect.cpp | 5 +++++ src/gui/qgsowssourceselect.h | 4 ++-- src/providers/geonode/qgsgeonodesourceselect.cpp | 5 +++++ src/providers/geonode/qgsgeonodesourceselect.h | 4 +++- src/providers/mssql/qgsmssqlsourceselect.cpp | 5 +++++ src/providers/mssql/qgsmssqlsourceselect.h | 2 ++ src/providers/postgres/qgspgsourceselect.cpp | 5 +++++ src/providers/postgres/qgspgsourceselect.h | 2 ++ src/providers/wfs/qgswfssourceselect.cpp | 5 +++++ src/providers/wfs/qgswfssourceselect.h | 2 ++ src/providers/wms/qgswmssourceselect.cpp | 5 +++++ src/providers/wms/qgswmssourceselect.h | 12 +++++++----- 18 files changed, 98 insertions(+), 9 deletions(-) diff --git a/python/gui/auto_generated/qgsabstractdatasourcewidget.sip.in b/python/gui/auto_generated/qgsabstractdatasourcewidget.sip.in index a433a897e4f..9f336f53743 100644 --- a/python/gui/auto_generated/qgsabstractdatasourcewidget.sip.in +++ b/python/gui/auto_generated/qgsabstractdatasourcewidget.sip.in @@ -48,6 +48,17 @@ The default implementation does nothing Triggered when the add button is clicked, the add layer signal is emitted Concrete classes should implement the right behavior depending on the layer being added. +%End + + virtual void reset(); +%Docstring +Called when this source select widget is being shown in a "new and clean" dialog. + +The data source manager recycles exisiting source select widgets but will call +this method on every reopening. +This should clear any selection that has previously been done. + +.. versionadded:: 3.10 %End signals: diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index a449d74f3c5..08ccc0955ed 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1892,6 +1892,10 @@ void QgisApp::dataSourceManager( const QString &pageName ) connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::openFile, this, &QgisApp::openFile ); } + else + { + mDataSourceManagerDialog->reset(); + } // Try to open the dialog on a particular page if ( ! pageName.isEmpty() ) { diff --git a/src/gui/qgsabstractdatasourcewidget.cpp b/src/gui/qgsabstractdatasourcewidget.cpp index e2ea6ac5dc1..10c17453f86 100644 --- a/src/gui/qgsabstractdatasourcewidget.cpp +++ b/src/gui/qgsabstractdatasourcewidget.cpp @@ -61,3 +61,11 @@ void QgsAbstractDataSourceWidget::setMapCanvas( const QgsMapCanvas *mapCanvas ) mMapCanvas = mapCanvas; } +void QgsAbstractDataSourceWidget::addButtonClicked() +{ +} + +void QgsAbstractDataSourceWidget::reset() +{ +} + diff --git a/src/gui/qgsabstractdatasourcewidget.h b/src/gui/qgsabstractdatasourcewidget.h index 566f497701f..5b0c9a98eef 100644 --- a/src/gui/qgsabstractdatasourcewidget.h +++ b/src/gui/qgsabstractdatasourcewidget.h @@ -65,7 +65,18 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog * Concrete classes should implement the right behavior depending on the layer * being added. */ - virtual void addButtonClicked() { } + virtual void addButtonClicked(); + + /** + * Called when this source select widget is being shown in a "new and clean" dialog. + * + * The data source manager recycles exisiting source select widgets but will call + * this method on every reopening. + * This should clear any selection that has previously been done. + * + * \since QGIS 3.10 + */ + virtual void reset(); signals: diff --git a/src/gui/qgsdatasourcemanagerdialog.cpp b/src/gui/qgsdatasourcemanagerdialog.cpp index 63ae9e2eb45..371bed3bddb 100644 --- a/src/gui/qgsdatasourcemanagerdialog.cpp +++ b/src/gui/qgsdatasourcemanagerdialog.cpp @@ -118,6 +118,19 @@ void QgsDataSourceManagerDialog::refresh() emit providerDialogsRefreshRequested(); } +void QgsDataSourceManagerDialog::reset() +{ + int pageCount = ui->mOptionsStackedWidget->count(); + for ( int i = 0; i < pageCount; ++i ) + { + QWidget *widget = ui->mOptionsStackedWidget->widget( i ); + QgsAbstractDataSourceWidget *dataSourceWidget = qobject_cast( widget ); + if ( dataSourceWidget ) + dataSourceWidget->reset(); + } + +} + void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey ) { emit addRasterLayer( uri, baseName, providerKey ); diff --git a/src/gui/qgsdatasourcemanagerdialog.h b/src/gui/qgsdatasourcemanagerdialog.h index 5eeb491452e..8df7d823578 100644 --- a/src/gui/qgsdatasourcemanagerdialog.h +++ b/src/gui/qgsdatasourcemanagerdialog.h @@ -89,6 +89,8 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva //! Refresh the browser view void refresh(); + void reset(); + protected: void showEvent( QShowEvent *event ) override; diff --git a/src/gui/qgsowssourceselect.cpp b/src/gui/qgsowssourceselect.cpp index cfaa7a0276d..79d74ac0e66 100644 --- a/src/gui/qgsowssourceselect.cpp +++ b/src/gui/qgsowssourceselect.cpp @@ -124,6 +124,11 @@ void QgsOWSSourceSelect::refresh() populateConnectionList(); } +void QgsOWSSourceSelect::reset() +{ + mLayersTreeWidget->clearSelection(); +} + void QgsOWSSourceSelect::clearFormats() { mFormatComboBox->clear(); diff --git a/src/gui/qgsowssourceselect.h b/src/gui/qgsowssourceselect.h index 4ce62d5c97b..0efd8b03aa4 100644 --- a/src/gui/qgsowssourceselect.h +++ b/src/gui/qgsowssourceselect.h @@ -63,11 +63,11 @@ class GUI_EXPORT QgsOWSSourceSelect : public QgsAbstractDataSourceWidget, protec //! Constructor QgsOWSSourceSelect( const QString &service, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); - public slots: - //! Triggered when the provider's connections need to be refreshed void refresh() override; + void reset() override; + protected slots: //! show whatever error is exposed. void showError( const QString &title, const QString &format, const QString &error ); diff --git a/src/providers/geonode/qgsgeonodesourceselect.cpp b/src/providers/geonode/qgsgeonodesourceselect.cpp index d734f0425de..30b803a9b93 100644 --- a/src/providers/geonode/qgsgeonodesourceselect.cpp +++ b/src/providers/geonode/qgsgeonodesourceselect.cpp @@ -77,6 +77,11 @@ QgsGeoNodeSourceSelect::~QgsGeoNodeSourceSelect() emit abortRequests(); } +void QgsGeoNodeSourceSelect::reset() +{ + treeView->clearSelection(); +} + void QgsGeoNodeSourceSelect::addConnectionsEntryList() { QgsGeoNodeNewConnection nc( this ); diff --git a/src/providers/geonode/qgsgeonodesourceselect.h b/src/providers/geonode/qgsgeonodesourceselect.h index b1facd85f91..f518ee2d321 100644 --- a/src/providers/geonode/qgsgeonodesourceselect.h +++ b/src/providers/geonode/qgsgeonodesourceselect.h @@ -45,7 +45,9 @@ class QgsGeoNodeSourceSelect: public QgsAbstractDataSourceWidget, private Ui::Qg QgsGeoNodeSourceSelect( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); ~QgsGeoNodeSourceSelect() override; - public slots: + void reset() override; + + private: void addButtonClicked() override; diff --git a/src/providers/mssql/qgsmssqlsourceselect.cpp b/src/providers/mssql/qgsmssqlsourceselect.cpp index 3347e7a3ad2..7ed6261f7b2 100644 --- a/src/providers/mssql/qgsmssqlsourceselect.cpp +++ b/src/providers/mssql/qgsmssqlsourceselect.cpp @@ -662,6 +662,11 @@ QString QgsMssqlSourceSelect::connectionInfo() return mConnInfo; } +void QgsMssqlSourceSelect::reset() +{ + mTablesTreeView->clearSelection(); +} + void QgsMssqlSourceSelect::refresh() { populateConnectionList(); diff --git a/src/providers/mssql/qgsmssqlsourceselect.h b/src/providers/mssql/qgsmssqlsourceselect.h index d7e475deaec..c17a968d455 100644 --- a/src/providers/mssql/qgsmssqlsourceselect.h +++ b/src/providers/mssql/qgsmssqlsourceselect.h @@ -79,6 +79,8 @@ class QgsMssqlSourceSelect : public QgsAbstractDataSourceWidget, private Ui::Qgs //! Connection info (database, host, user, password) QString connectionInfo(); + void reset() override; + signals: void addGeometryColumn( const QgsMssqlLayerProperty & ); diff --git a/src/providers/postgres/qgspgsourceselect.cpp b/src/providers/postgres/qgspgsourceselect.cpp index 48f67eecdc9..a27a6f9a44c 100644 --- a/src/providers/postgres/qgspgsourceselect.cpp +++ b/src/providers/postgres/qgspgsourceselect.cpp @@ -595,6 +595,11 @@ void QgsPgSourceSelect::columnThreadFinished() finishList(); } +void QgsPgSourceSelect::reset() +{ + mTablesTreeView->clearSelection(); +} + QStringList QgsPgSourceSelect::selectedTables() { return mSelectedTables; diff --git a/src/providers/postgres/qgspgsourceselect.h b/src/providers/postgres/qgspgsourceselect.h index 5b00f9e0703..43f633117ef 100644 --- a/src/providers/postgres/qgspgsourceselect.h +++ b/src/providers/postgres/qgspgsourceselect.h @@ -122,6 +122,8 @@ class QgsPgSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDbS void columnThreadFinished(); + void reset() override; + private: typedef QPair geomPair; typedef QList geomCol; diff --git a/src/providers/wfs/qgswfssourceselect.cpp b/src/providers/wfs/qgswfssourceselect.cpp index 8c2bd927085..b1ee84c521e 100644 --- a/src/providers/wfs/qgswfssourceselect.cpp +++ b/src/providers/wfs/qgswfssourceselect.cpp @@ -126,6 +126,11 @@ QgsWFSSourceSelect::~QgsWFSSourceSelect() delete mBuildQueryButton; } +void QgsWFSSourceSelect::reset() +{ + treeView->clearSelection(); +} + void QgsWFSSourceSelect::populateConnectionList() { QStringList keys = QgsWfsConnection::connectionList(); diff --git a/src/providers/wfs/qgswfssourceselect.h b/src/providers/wfs/qgswfssourceselect.h index 4e7f3c0d758..4ad36da5199 100644 --- a/src/providers/wfs/qgswfssourceselect.h +++ b/src/providers/wfs/qgswfssourceselect.h @@ -67,6 +67,8 @@ class QgsWFSSourceSelect: public QgsAbstractDataSourceWidget, private Ui::QgsWFS QgsWFSSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); ~QgsWFSSourceSelect() override; + void reset() override; + private: QgsWFSSourceSelect(); //default constructor is forbidden QgsProjectionSelectionDialog *mProjectionSelector = nullptr; diff --git a/src/providers/wms/qgswmssourceselect.cpp b/src/providers/wms/qgswmssourceselect.cpp index 126282c91f3..476b6c09dba 100644 --- a/src/providers/wms/qgswmssourceselect.cpp +++ b/src/providers/wms/qgswmssourceselect.cpp @@ -592,6 +592,11 @@ void QgsWMSSourceSelect::addButtonClicked() QStringLiteral( "wms" ) ); } +void QgsWMSSourceSelect::reset() +{ + lstLayers->clearSelection(); +} + void QgsWMSSourceSelect::enableLayersForCrs( QTreeWidgetItem *item ) { QString layerName = item->data( 0, Qt::UserRole + 0 ).toString(); diff --git a/src/providers/wms/qgswmssourceselect.h b/src/providers/wms/qgswmssourceselect.h index bf4168d72f7..207c13f7763 100644 --- a/src/providers/wms/qgswmssourceselect.h +++ b/src/providers/wms/qgswmssourceselect.h @@ -51,11 +51,16 @@ class QgsWMSSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsWM //! Constructor QgsWMSSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); - public slots: - //! Triggered when the provider's connections need to be refreshed void refresh() override; + //! Determines the layers the user selected + void addButtonClicked() override; + + void reset() override; + + private slots: + //! Opens the create connection dialog to build a new connection void btnNew_clicked(); //! Opens a dialog to edit an existing connection @@ -73,9 +78,6 @@ class QgsWMSSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsWM */ void btnConnect_clicked(); - //! Determines the layers the user selected - void addButtonClicked() override; - void searchFinished(); //! Opens the Spatial Reference System dialog.