Skip to content

Commit

Permalink
[bugfix] Sync the bowser connections when changed from the select dia…
Browse files Browse the repository at this point in the history
…logs

For now, the sync works only in one direction: from the dialogs
to the browser instances
  • Loading branch information
elpaso committed Jul 18, 2017
1 parent 7ec8c4a commit 9ff73c0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions python/gui/qgsbrowserdockwidget.sip
Expand Up @@ -120,6 +120,10 @@ Emitted when a file needs to be opened
void handleDropUriList( const QgsMimeDataUtils::UriList & );
%Docstring
Emitted when drop uri list needs to be handled
%End
void connectionsChanged( );
%Docstring
Connections changed in the browser
%End

protected:
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -888,6 +888,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget );
mBrowserWidget->hide();
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::handleDropUriList, this, &QgisApp::handleDropUriList );

Expand All @@ -896,6 +898,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget2 );
mBrowserWidget2->hide();
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::handleDropUriList, this, &QgisApp::handleDropUriList );

Expand Down Expand Up @@ -1594,6 +1598,8 @@ void QgisApp::dataSourceManager( QString pageName )
{
mDataSourceManagerDialog = new QgsDataSourceManagerDialog( mapCanvas( ), 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 & ) ),
this, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
connect( mDataSourceManagerDialog, SIGNAL( addVectorLayer( QString const &, QString const &, QString const & ) ),
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1494,6 +1494,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

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
to pick up on this (e.g. maplayer) */
void keyPressed( QKeyEvent *e );
Expand Down
5 changes: 3 additions & 2 deletions src/gui/qgsbrowserdockwidget.cpp
Expand Up @@ -117,7 +117,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent *e )
mModel = new QgsBrowserModel( mBrowserView );
mProxyModel = new QgsBrowserTreeFilterProxyModel( this );
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->setModel( mProxyModel );
// provide a horizontal scroll bar instead of using ellipse (...) for longer items
Expand Down Expand Up @@ -242,7 +242,8 @@ void QgsBrowserDockWidget::removeFavorite()

void QgsBrowserDockWidget::refresh()
{
refreshModel( QModelIndex() );
if ( mModel )
refreshModel( QModelIndex() );
}

void QgsBrowserDockWidget::refreshModel( const QModelIndex &index )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsbrowserdockwidget.h
Expand Up @@ -102,6 +102,8 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
void openFile( const QString & );
//! Emitted when drop uri list needs to be handled
void handleDropUriList( const QgsMimeDataUtils::UriList & );
//! Connections changed in the browser
void connectionsChanged( );

protected:
//! Show event override
Expand Down
12 changes: 12 additions & 0 deletions src/gui/qgsdatasourcemanagerdialog.cpp
Expand Up @@ -51,6 +51,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
// Forward all browser signals
connect( mBrowserWidget, &QgsBrowserDockWidget::handleDropUriList, this, &QgsDataSourceManagerDialog::handleDropUriList );
connect( mBrowserWidget, &QgsBrowserDockWidget::openFile, this, &QgsDataSourceManagerDialog::openFile );
connect( mBrowserWidget, &QgsBrowserDockWidget::connectionsChanged, this, &QgsDataSourceManagerDialog::connectionsChanged );
connect( this, &QgsDataSourceManagerDialog::updateProjectHome, mBrowserWidget, &QgsBrowserDockWidget::updateProjectHome );

// VECTOR Layers (completely different interface: it's not a provider)
Expand Down Expand Up @@ -115,6 +116,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
{
this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) );
} );
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
}

addRasterProviderDialog( QStringLiteral( "arcgismapserver" ), tr( "ArcGIS Map Server" ), QStringLiteral( "/mActionAddAmsLayer.svg" ) );
Expand Down Expand Up @@ -166,6 +168,12 @@ void QgsDataSourceManagerDialog::setPreviousPage()
setCurrentPage( prevPage );
}

void QgsDataSourceManagerDialog::refresh()
{
mBrowserWidget->refresh( );
emit dlg_refresh();
}

void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
{
emit addRasterLayer( uri, baseName, providerKey );
Expand Down Expand Up @@ -212,6 +220,8 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
this, SIGNAL( showProgress( int, int ) ) );
connect( dlg, SIGNAL( progressMessage( QString ) ),
this, SIGNAL( showStatusMessage( QString ) ) );
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
connect( this, SIGNAL( dlg_refresh( ) ), dlg, SLOT( refresh( ) ) );
}
}

Expand All @@ -223,5 +233,7 @@ void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString provider
// Forward
connect( dlg, 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( ) ) );
}
}
7 changes: 7 additions & 0 deletions src/gui/qgsdatasourcemanagerdialog.h
Expand Up @@ -74,6 +74,8 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
void vectorLayersAdded( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
//! Reset current page to previously selected page
void setPreviousPage();
//! Refresh the browser view
void refresh( );

signals:
//! Emitted when a raster layer was selected for addition: for signal forwarding to QgisApp
Expand Down Expand Up @@ -102,6 +104,10 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
void handleDropUriList( const QgsMimeDataUtils::UriList & );
//! Update project home directory
void updateProjectHome();
//! Connections changed
void connectionsChanged( );
// internal signal
void dlg_refresh( );

private:
//! Return the dialog from the provider
Expand All @@ -114,6 +120,7 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
QgsMapCanvas *mMapCanvas = nullptr;
int mPreviousRow;
QStringList mPageNames;

};

#endif // QGSDATASOURCEMANAGERDIALOG_H

0 comments on commit 9ff73c0

Please sign in to comment.