Skip to content
Permalink
Browse files

[bugfix] Sync the dialogs connections when changed from the browser

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 11, 2017
1 parent 9ff73c0 commit e57399bae044c4100d9f75e4cb0517ca5b63a6b1
@@ -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:
@@ -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:
@@ -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:

@@ -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
@@ -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 );
@@ -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,
@@ -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
@@ -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
@@ -342,6 +342,12 @@ void QgsDataItem::refresh()
}
}

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

void QgsDataItem::refresh( const QVector<QgsDataItem *> &children )
{
QgsDebugMsgLevel( "mPath = " + mPath, 2 );
@@ -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:
@@ -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:

@@ -346,6 +346,7 @@ SET(QGIS_GUI_SRCS
qgsvertexmarker.cpp
qgsfiledownloader.cpp
qgsdatasourcemanagerdialog.cpp
qgssourceselect.cpp
)

SET(QGIS_GUI_MOC_HDRS
@@ -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
@@ -710,6 +712,7 @@ SET(QGIS_GUI_HDRS
ogr/qgsnewogrconnection.h
ogr/qgsvectorlayersaveasdialog.h

qgssourceselect.h

attributetable/qgsfeaturemodel.h

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

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

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

@@ -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
@@ -107,9 +107,9 @@ class QgsWMSRootItem : public QgsDataCollectionItem

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

};


@@ -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();
@@ -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 );
@@ -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()
{
@@ -164,6 +170,7 @@ void QgsWMSSourceSelect::populateConnectionList()

setConnectionListPosition();
}

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

0 comments on commit e57399b

Please sign in to comment.
You can’t perform that action at this time.