[bugfix] Sync the bowser connections when changed from the select dialogs

For now, the sync works only in one direction: from the dialogs
to the browser instances
This commit is contained in:
Alessandro Pasotti 2017-06-15 12:52:50 +02:00
parent 7ec8c4ae3b
commit 9ff73c0b77
7 changed files with 40 additions and 2 deletions

View File

@ -120,6 +120,10 @@ Emitted when a file needs to be opened
void handleDropUriList( const QgsMimeDataUtils::UriList & ); void handleDropUriList( const QgsMimeDataUtils::UriList & );
%Docstring %Docstring
Emitted when drop uri list needs to be handled Emitted when drop uri list needs to be handled
%End
void connectionsChanged( );
%Docstring
Connections changed in the browser
%End %End
protected: protected:

View File

@ -888,6 +888,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget ); addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget );
mBrowserWidget->hide(); mBrowserWidget->hide();
connect( this, &QgisApp::newProject, mBrowserWidget, &QgsBrowserDockWidget::updateProjectHome ); connect( this, &QgisApp::newProject, mBrowserWidget, &QgsBrowserDockWidget::updateProjectHome );
connect( this, &QgisApp::connectionsChanged, mBrowserWidget, &QgsBrowserDockWidget::refresh );
connect( mBrowserWidget, &QgsBrowserDockWidget::connectionsChanged, this, &QgisApp::connectionsChanged );
connect( mBrowserWidget, &QgsBrowserDockWidget::openFile, this, &QgisApp::openFile ); connect( mBrowserWidget, &QgsBrowserDockWidget::openFile, this, &QgisApp::openFile );
connect( mBrowserWidget, &QgsBrowserDockWidget::handleDropUriList, this, &QgisApp::handleDropUriList ); connect( mBrowserWidget, &QgsBrowserDockWidget::handleDropUriList, this, &QgisApp::handleDropUriList );
@ -896,6 +898,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget2 ); addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget2 );
mBrowserWidget2->hide(); mBrowserWidget2->hide();
connect( this, &QgisApp::newProject, mBrowserWidget2, &QgsBrowserDockWidget::updateProjectHome ); connect( this, &QgisApp::newProject, mBrowserWidget2, &QgsBrowserDockWidget::updateProjectHome );
connect( mBrowserWidget2, &QgsBrowserDockWidget::connectionsChanged, this, &QgisApp::connectionsChanged );
connect( this, &QgisApp::connectionsChanged, mBrowserWidget2, &QgsBrowserDockWidget::refresh );
connect( mBrowserWidget2, &QgsBrowserDockWidget::openFile, this, &QgisApp::openFile ); connect( mBrowserWidget2, &QgsBrowserDockWidget::openFile, this, &QgisApp::openFile );
connect( mBrowserWidget2, &QgsBrowserDockWidget::handleDropUriList, this, &QgisApp::handleDropUriList ); connect( mBrowserWidget2, &QgsBrowserDockWidget::handleDropUriList, this, &QgisApp::handleDropUriList );
@ -1594,6 +1598,8 @@ void QgisApp::dataSourceManager( QString pageName )
{ {
mDataSourceManagerDialog = new QgsDataSourceManagerDialog( mapCanvas( ), this ); mDataSourceManagerDialog = new QgsDataSourceManagerDialog( mapCanvas( ), this );
// Forward signals to this // Forward signals to this
connect( this, &QgisApp::connectionsChanged, mDataSourceManagerDialog, &QgsDataSourceManagerDialog::refresh );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::connectionsChanged, this, &QgisApp::connectionsChanged );
connect( mDataSourceManagerDialog, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ), connect( mDataSourceManagerDialog, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) ); this, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
connect( mDataSourceManagerDialog, SIGNAL( addVectorLayer( QString const &, QString const &, QString const & ) ), connect( mDataSourceManagerDialog, SIGNAL( addVectorLayer( QString const &, QString const &, QString const & ) ),

View File

@ -1494,6 +1494,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
signals: signals:
/**
* Emitted when a connection has been added/removed or changed by the provider
* selection dialogs
*/
void connectionsChanged( );
/** Emitted when a key is pressed and we want non widget sublasses to be able /** Emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */ to pick up on this (e.g. maplayer) */
void keyPressed( QKeyEvent *e ); void keyPressed( QKeyEvent *e );

View File

@ -117,7 +117,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent *e )
mModel = new QgsBrowserModel( mBrowserView ); mModel = new QgsBrowserModel( mBrowserView );
mProxyModel = new QgsBrowserTreeFilterProxyModel( this ); mProxyModel = new QgsBrowserTreeFilterProxyModel( this );
mProxyModel->setBrowserModel( mModel ); mProxyModel->setBrowserModel( mModel );
mBrowserView->setSettingsSection( objectName().toLower() ); // to distinguish 2 instances ow browser mBrowserView->setSettingsSection( objectName().toLower() ); // to distinguish 2 or more instances of the browser
mBrowserView->setBrowserModel( mModel ); mBrowserView->setBrowserModel( mModel );
mBrowserView->setModel( mProxyModel ); mBrowserView->setModel( mProxyModel );
// provide a horizontal scroll bar instead of using ellipse (...) for longer items // provide a horizontal scroll bar instead of using ellipse (...) for longer items
@ -242,7 +242,8 @@ void QgsBrowserDockWidget::removeFavorite()
void QgsBrowserDockWidget::refresh() void QgsBrowserDockWidget::refresh()
{ {
refreshModel( QModelIndex() ); if ( mModel )
refreshModel( QModelIndex() );
} }
void QgsBrowserDockWidget::refreshModel( const QModelIndex &index ) void QgsBrowserDockWidget::refreshModel( const QModelIndex &index )

View File

@ -102,6 +102,8 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
void openFile( const QString & ); void openFile( const QString & );
//! Emitted when drop uri list needs to be handled //! Emitted when drop uri list needs to be handled
void handleDropUriList( const QgsMimeDataUtils::UriList & ); void handleDropUriList( const QgsMimeDataUtils::UriList & );
//! Connections changed in the browser
void connectionsChanged( );
protected: protected:
//! Show event override //! Show event override

View File

@ -51,6 +51,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
// Forward all browser signals // Forward all browser signals
connect( mBrowserWidget, &QgsBrowserDockWidget::handleDropUriList, this, &QgsDataSourceManagerDialog::handleDropUriList ); connect( mBrowserWidget, &QgsBrowserDockWidget::handleDropUriList, this, &QgsDataSourceManagerDialog::handleDropUriList );
connect( mBrowserWidget, &QgsBrowserDockWidget::openFile, this, &QgsDataSourceManagerDialog::openFile ); connect( mBrowserWidget, &QgsBrowserDockWidget::openFile, this, &QgsDataSourceManagerDialog::openFile );
connect( mBrowserWidget, &QgsBrowserDockWidget::connectionsChanged, this, &QgsDataSourceManagerDialog::connectionsChanged );
connect( this, &QgsDataSourceManagerDialog::updateProjectHome, mBrowserWidget, &QgsBrowserDockWidget::updateProjectHome ); connect( this, &QgsDataSourceManagerDialog::updateProjectHome, mBrowserWidget, &QgsBrowserDockWidget::updateProjectHome );
// VECTOR Layers (completely different interface: it's not a provider) // VECTOR Layers (completely different interface: it's not a provider)
@ -115,6 +116,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
{ {
this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) ); this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) );
} ); } );
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
} }
addRasterProviderDialog( QStringLiteral( "arcgismapserver" ), tr( "ArcGIS Map Server" ), QStringLiteral( "/mActionAddAmsLayer.svg" ) ); addRasterProviderDialog( QStringLiteral( "arcgismapserver" ), tr( "ArcGIS Map Server" ), QStringLiteral( "/mActionAddAmsLayer.svg" ) );
@ -166,6 +168,12 @@ void QgsDataSourceManagerDialog::setPreviousPage()
setCurrentPage( prevPage ); setCurrentPage( prevPage );
} }
void QgsDataSourceManagerDialog::refresh()
{
mBrowserWidget->refresh( );
emit dlg_refresh();
}
void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey ) void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
{ {
emit addRasterLayer( uri, baseName, providerKey ); emit addRasterLayer( uri, baseName, providerKey );
@ -212,6 +220,8 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
this, SIGNAL( showProgress( int, int ) ) ); this, SIGNAL( showProgress( int, int ) ) );
connect( dlg, SIGNAL( progressMessage( QString ) ), connect( dlg, SIGNAL( progressMessage( QString ) ),
this, SIGNAL( showStatusMessage( QString ) ) ); this, SIGNAL( showStatusMessage( QString ) ) );
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
connect( this, SIGNAL( dlg_refresh( ) ), dlg, SLOT( refresh( ) ) );
} }
} }
@ -223,5 +233,7 @@ void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString provider
// Forward // Forward
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ), connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ) ); this, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ) );
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
connect( this, SIGNAL( dlg_refresh( ) ), dlg, SLOT( refresh( ) ) );
} }
} }

View File

@ -74,6 +74,8 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
void vectorLayersAdded( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType ); void vectorLayersAdded( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
//! Reset current page to previously selected page //! Reset current page to previously selected page
void setPreviousPage(); void setPreviousPage();
//! Refresh the browser view
void refresh( );
signals: signals:
//! Emitted when a raster layer was selected for addition: for signal forwarding to QgisApp //! Emitted when a raster layer was selected for addition: for signal forwarding to QgisApp
@ -102,6 +104,10 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
void handleDropUriList( const QgsMimeDataUtils::UriList & ); void handleDropUriList( const QgsMimeDataUtils::UriList & );
//! Update project home directory //! Update project home directory
void updateProjectHome(); void updateProjectHome();
//! Connections changed
void connectionsChanged( );
// internal signal
void dlg_refresh( );
private: private:
//! Return the dialog from the provider //! Return the dialog from the provider
@ -114,6 +120,7 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
QgsMapCanvas *mMapCanvas = nullptr; QgsMapCanvas *mMapCanvas = nullptr;
int mPreviousRow; int mPreviousRow;
QStringList mPageNames; QStringList mPageNames;
}; };
#endif // QGSDATASOURCEMANAGERDIALOG_H #endif // QGSDATASOURCEMANAGERDIALOG_H