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.
This commit is contained in:
Matthias Kuhn 2019-07-25 11:13:16 +02:00
parent a681e1ed45
commit a6875a7c78
18 changed files with 98 additions and 9 deletions

View File

@ -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:

View File

@ -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() )
{

View File

@ -61,3 +61,11 @@ void QgsAbstractDataSourceWidget::setMapCanvas( const QgsMapCanvas *mapCanvas )
mMapCanvas = mapCanvas;
}
void QgsAbstractDataSourceWidget::addButtonClicked()
{
}
void QgsAbstractDataSourceWidget::reset()
{
}

View File

@ -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:

View File

@ -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<QgsAbstractDataSourceWidget *>( widget );
if ( dataSourceWidget )
dataSourceWidget->reset();
}
}
void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
{
emit addRasterLayer( uri, baseName, providerKey );

View File

@ -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;

View File

@ -124,6 +124,11 @@ void QgsOWSSourceSelect::refresh()
populateConnectionList();
}
void QgsOWSSourceSelect::reset()
{
mLayersTreeWidget->clearSelection();
}
void QgsOWSSourceSelect::clearFormats()
{
mFormatComboBox->clear();

View File

@ -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 );

View File

@ -77,6 +77,11 @@ QgsGeoNodeSourceSelect::~QgsGeoNodeSourceSelect()
emit abortRequests();
}
void QgsGeoNodeSourceSelect::reset()
{
treeView->clearSelection();
}
void QgsGeoNodeSourceSelect::addConnectionsEntryList()
{
QgsGeoNodeNewConnection nc( this );

View File

@ -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;

View File

@ -662,6 +662,11 @@ QString QgsMssqlSourceSelect::connectionInfo()
return mConnInfo;
}
void QgsMssqlSourceSelect::reset()
{
mTablesTreeView->clearSelection();
}
void QgsMssqlSourceSelect::refresh()
{
populateConnectionList();

View File

@ -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 & );

View File

@ -595,6 +595,11 @@ void QgsPgSourceSelect::columnThreadFinished()
finishList();
}
void QgsPgSourceSelect::reset()
{
mTablesTreeView->clearSelection();
}
QStringList QgsPgSourceSelect::selectedTables()
{
return mSelectedTables;

View File

@ -122,6 +122,8 @@ class QgsPgSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDbS
void columnThreadFinished();
void reset() override;
private:
typedef QPair<QString, QString> geomPair;
typedef QList<geomPair> geomCol;

View File

@ -126,6 +126,11 @@ QgsWFSSourceSelect::~QgsWFSSourceSelect()
delete mBuildQueryButton;
}
void QgsWFSSourceSelect::reset()
{
treeView->clearSelection();
}
void QgsWFSSourceSelect::populateConnectionList()
{
QStringList keys = QgsWfsConnection::connectionList();

View File

@ -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;

View File

@ -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();

View File

@ -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.