Skip to content

Commit

Permalink
[bugfix] Sync the dialogs connections when changed from the browser
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elpaso committed Jul 18, 2017
1 parent 9ff73c0 commit e57399b
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 25 deletions.
4 changes: 4 additions & 0 deletions python/core/qgsbrowsermodel.sip
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ Refresh item children
void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
%Docstring
Emitted when item children fetch was finished
%End
void connectionsChanged( );
%Docstring
notify the provider dialogs of a changed connection
%End

public slots:
Expand Down
9 changes: 9 additions & 0 deletions python/core/qgsdataitem.sip
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ Remove children recursively and set as not populated. This is used when refreshi

virtual void refresh();

virtual void refreshConnections();
%Docstring
Refresh connections: update GUI and emit signal
%End

virtual void childrenCreated();

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

protected slots:

Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgsbrowserdockwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Toggle fast scan

void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
%Docstring
Selection hass changed
Selection has changed
%End
void splitterMoved();
%Docstring
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsbrowsermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ void QgsBrowserModel::addRootItems()
QgsDataItem *item = pr->createDataItem( QLatin1String( "" ), nullptr ); // empty path -> top level
if ( item )
{
// Forward the signal from the root items to the model (and then to the app)
connect( item, &QgsDataItem::connectionsChanged, this, &QgsBrowserModel::connectionsChanged );
QgsDebugMsgLevel( "Add new top level item : " + item->name(), 4 );
connectItem( item );
providerMap.insertMulti( capabilities, item );
Expand Down Expand Up @@ -411,6 +413,7 @@ void QgsBrowserModel::itemStateChanged( QgsDataItem *item, QgsDataItem::State ol
QgsDebugMsgLevel( QString( "item %1 state changed %2 -> %3" ).arg( item->path() ).arg( oldState ).arg( item->state() ), 4 );
emit stateChanged( idx, oldState );
}

void QgsBrowserModel::connectItem( QgsDataItem *item )
{
connect( item, &QgsDataItem::beginInsertItems,
Expand All @@ -425,6 +428,11 @@ void QgsBrowserModel::connectItem( QgsDataItem *item )
this, &QgsBrowserModel::itemDataChanged );
connect( item, &QgsDataItem::stateChanged,
this, &QgsBrowserModel::itemStateChanged );

// if it's a collection item, also forwards connectionsChanged
QgsDataCollectionItem *collectionItem = dynamic_cast<QgsDataCollectionItem *>( item );
if ( collectionItem )
connect( collectionItem, &QgsDataCollectionItem::connectionsChanged, this, &QgsBrowserModel::connectionsChanged );
}

QStringList QgsBrowserModel::mimeTypes() const
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsbrowsermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
signals:
//! Emitted when item children fetch was finished
void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
//! Connections changed in the browser, forwarded to the widget and used to
//! notify the provider dialogs of a changed connection
void connectionsChanged( );

public slots:
//! Reload the whole model
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ void QgsDataItem::refresh()
}
}

void QgsDataItem::refreshConnections()
{
refresh( );
emit connectionsChanged( );
}

void QgsDataItem::refresh( const QVector<QgsDataItem *> &children )
{
QgsDebugMsgLevel( "mPath = " + mPath, 2 );
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsdataitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ class CORE_EXPORT QgsDataItem : public QObject

virtual void refresh();

//! Refresh connections: update GUI and emit signal
virtual void refreshConnections();

virtual void childrenCreated();

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

protected slots:

Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ SET(QGIS_GUI_SRCS
qgsvertexmarker.cpp
qgsfiledownloader.cpp
qgsdatasourcemanagerdialog.cpp
qgssourceselect.cpp
)

SET(QGIS_GUI_MOC_HDRS
Expand Down Expand Up @@ -502,6 +503,7 @@ SET(QGIS_GUI_MOC_HDRS
ogr/qgsopenvectorlayerdialog.h
ogr/qgsnewogrconnection.h
ogr/qgsvectorlayersaveasdialog.h
qgssourceselect.h

raster/qgsmultibandcolorrendererwidget.h
raster/qgspalettedrendererwidget.h
Expand Down Expand Up @@ -710,6 +712,7 @@ SET(QGIS_GUI_HDRS
ogr/qgsnewogrconnection.h
ogr/qgsvectorlayersaveasdialog.h

qgssourceselect.h

attributetable/qgsfeaturemodel.h

Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsbrowserdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ void QgsBrowserDockWidget::showEvent( QShowEvent *e )
connect( mBrowserView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsBrowserDockWidget::selectionChanged );

// Forward the model changed signals to the widget
connect( mModel, &QgsBrowserModel::connectionsChanged,
this, &QgsBrowserDockWidget::connectionsChanged );


// objectName used by settingsSection() is not yet set in constructor
QgsSettings settings;
mPropertiesWidgetEnabled = settings.value( settingsSection() + "/propertiesWidgetEnabled", false ).toBool();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsbrowserdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
//! Toggle fast scan
void toggleFastScan();

//! Selection hass changed
//! Selection has changed
void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
//! Splitter has been moved
void splitterMoved();
Expand Down
6 changes: 3 additions & 3 deletions src/gui/qgsdatasourcemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void QgsDataSourceManagerDialog::setPreviousPage()
void QgsDataSourceManagerDialog::refresh()
{
mBrowserWidget->refresh( );
emit dlg_refresh();
emit providerDialogsRefreshRequested();
}

void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
Expand Down Expand Up @@ -221,7 +221,7 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
connect( dlg, SIGNAL( progressMessage( QString ) ),
this, SIGNAL( showStatusMessage( QString ) ) );
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
connect( this, SIGNAL( dlg_refresh( ) ), dlg, SLOT( refresh( ) ) );
connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) );
}
}

Expand All @@ -234,6 +234,6 @@ void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString provider
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( ) ) );
connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) );
}
}
5 changes: 3 additions & 2 deletions src/gui/qgsdatasourcemanagerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
void updateProjectHome();
//! Connections changed
void connectionsChanged( );
// internal signal
void dlg_refresh( );
//! One or more provider connections have changed and the
//! dialogs should be refreshed
void providerDialogsRefreshRequested( );

private:
//! Return the dialog from the provider
Expand Down
30 changes: 30 additions & 0 deletions src/gui/qgssourceselect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/***************************************************************************
qgssourceselect.cpp - base class for source selector widgets
-------------------
begin : 10 July 2017
original : (C) 2017 by Alessandro Pasotti email : apasotti at boundlessgeo dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgssourceselect.h"

QgsSourceSelect::QgsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
QDialog( parent, fl ),
mWidgetMode( widgetMode )
{

}

QgsSourceSelect::~QgsSourceSelect()
{

}
65 changes: 65 additions & 0 deletions src/gui/qgssourceselect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/***************************************************************************
qgssourceselect.h - base class for source selector widgets
-------------------
begin : 10 July 2017
original : (C) 2017 by Alessandro Pasotti email : apasotti at boundlessgeo dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSSOURCESELECT_H
#define QGSSOURCESELECT_H
#include "qgis_sip.h"
#include "qgis.h"
#include "qgis_gui.h"

#include "qgsproviderregistry.h"
#include "qgsguiutils.h"

#include <QDialog>

/** \ingroup gui
* \brief Abstract base Dialog to create connections and add layers
* This class must provide common functionality and the interface for all
* source select dialogs used by data providers to configure data sources
* and add layers.
*/
class GUI_EXPORT QgsSourceSelect : public QDialog
{
Q_OBJECT

public:

//! Constructor
QgsSourceSelect( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );

//! Destructor
~QgsSourceSelect( );

//! Return the widget mode
QgsProviderRegistry::WidgetMode widgetMode( ) { return mWidgetMode; }

public slots:

//! Triggered when the provider's connections need to be refreshed
virtual void refresh( ) = 0;

signals:

//! Emitted when the provider's connections have changed
void connectionsChanged();

private:

QgsProviderRegistry::WidgetMode mWidgetMode;
};

#endif // QGSSOURCESELECT_H
12 changes: 3 additions & 9 deletions src/providers/wms/qgswmsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ void QgsWMSConnectionItem::editConnection()
if ( nc.exec() )
{
// the parent should be updated
mParent->refresh();
mParent->refreshConnections();
}
}

void QgsWMSConnectionItem::deleteConnection()
{
QgsWMSConnection::deleteConnection( mName );
// the parent should be updated
mParent->refresh();
mParent->refreshConnections();
}
#endif

Expand Down Expand Up @@ -418,22 +418,16 @@ QList<QAction *> QgsWMSRootItem::actions()
QWidget *QgsWMSRootItem::paramWidget()
{
QgsWMSSourceSelect *select = new QgsWMSSourceSelect( nullptr, 0, QgsProviderRegistry::WidgetMode::Manager );
connect( select, &QgsWMSSourceSelect::connectionsChanged, this, &QgsWMSRootItem::connectionsChanged );
return select;
}

void QgsWMSRootItem::connectionsChanged()
{
refresh();
}

void QgsWMSRootItem::newConnection()
{
QgsNewHttpConnection nc( nullptr );

if ( nc.exec() )
{
refresh();
refreshConnections( );
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmsdataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ class QgsWMSRootItem : public QgsDataCollectionItem

public slots:
#ifdef HAVE_GUI
void connectionsChanged();
void newConnection();
#endif

};


Expand Down
15 changes: 11 additions & 4 deletions src/providers/wms/qgswmssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@
#include <QNetworkReply>

QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QDialog( parent, fl )
, mWidgetMode( widgetMode )
: QgsSourceSelect( parent, fl, widgetMode )
, mDefaultCRS( GEO_EPSG_CRS_AUTHID )
, mCurrentTileset( nullptr )
{
setupUi( this );

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

mImageFormatGroup = new QButtonGroup;

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

void QgsWMSSourceSelect::refresh( )
{
// Reload WMS connections and update the GUI
QgsDebugMsg( "Refreshing WMS connections ..." );
populateConnectionList( );
}


void QgsWMSSourceSelect::populateConnectionList()
{
Expand All @@ -164,6 +170,7 @@ void QgsWMSSourceSelect::populateConnectionList()

setConnectionListPosition();
}

void QgsWMSSourceSelect::on_btnNew_clicked()
{
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this );
Expand Down
Loading

0 comments on commit e57399b

Please sign in to comment.