Skip to content

Commit

Permalink
Refactored all providers to use the new base class
Browse files Browse the repository at this point in the history
Also use refreshConnections from the data items when
a refresh is required, this function also emits
the signal to update the other GUI elements.
  • Loading branch information
elpaso committed Jul 18, 2017
1 parent 1e6a4ab commit aba9da5
Show file tree
Hide file tree
Showing 35 changed files with 213 additions and 148 deletions.
20 changes: 12 additions & 8 deletions python/gui/qgsarcgisservicesourceselect.sip
Expand Up @@ -10,11 +10,11 @@



class QgsArcGisServiceSourceSelect : QDialog, protected Ui::QgsArcGisServiceSourceSelectBase

class QgsArcGisServiceSourceSelect : QgsSourceSelect, protected Ui::QgsArcGisServiceSourceSelectBase
{
%Docstring
Generic class listing layers available from a remote service.
.. versionadded:: 3.0
Base class for listing ArcGis layers available from a remote service.
%End

%TypeHeaderCode
Expand All @@ -23,7 +23,7 @@ class QgsArcGisServiceSourceSelect : QDialog, protected Ui::QgsArcGisServiceSour
public:
enum ServiceType { MapService, FeatureService };

QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl );
QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
%Docstring
Constructor
%End
Expand All @@ -38,10 +38,6 @@ Sets the current extent and CRS. Used to select an appropriate CRS and possibly
void addLayer( QString uri, QString typeName );
%Docstring
Emitted when a layer is added from the dialog
%End
void connectionsChanged();
%Docstring
Emitted when the connections for the service were changed
%End

protected:
Expand Down Expand Up @@ -75,6 +71,14 @@ Returns the selected image encoding.
:rtype: str
%End

public slots:

virtual void refresh( );

%Docstring
Triggered when the provider's connections need to be refreshed
%End

};


Expand Down
15 changes: 9 additions & 6 deletions python/gui/qgsowssourceselect.sip
Expand Up @@ -11,16 +11,16 @@



class QgsOWSSourceSelect : QDialog, protected Ui::QgsOWSSourceSelectBase
class QgsOWSSourceSelect : QgsSourceSelect, protected Ui::QgsOWSSourceSelectBase
{
%Docstring
Dialog to create connections and add layers from WMS, WFS, WCS etc.
Dialog to create connections and add layers WCS etc.

This dialog allows the user to define and save connection information
for WMS servers, etc.

The user can then connect and add
layers from the WMS server to the map canvas.
layers from the WCS server to the map canvas.
%End

%TypeHeaderCode
Expand All @@ -42,6 +42,12 @@ Constructor

public slots:

virtual void refresh( );

%Docstring
Triggered when the provider's connections need to be refreshed
%End

void on_mNewButton_clicked();
%Docstring
Opens the create connection dialog to build a new connection
Expand Down Expand Up @@ -110,7 +116,6 @@ Add some default wms servers to the list
void addRasterLayer( const QString &rasterLayerPath,
const QString &baseName,
const QString &providerKey );
void connectionsChanged();

protected:

Expand Down Expand Up @@ -198,8 +203,6 @@ Add a few example servers to the list.
%End




virtual void populateLayerList();
%Docstring
Populate the layer list.
Expand Down
10 changes: 5 additions & 5 deletions python/gui/qgssourceselect.sip
Expand Up @@ -13,7 +13,7 @@
class QgsSourceSelect : QDialog
{
%Docstring
Abstract base Dialog to create connections and add layers
Abstract base Data Source Widget 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.
Expand All @@ -30,9 +30,9 @@ class QgsSourceSelect : QDialog
Constructor
%End

~QgsSourceSelect( );
virtual ~QgsSourceSelect( ) = 0;
%Docstring
Destructor
Pure Virtual Destructor
%End

QgsProviderRegistry::WidgetMode widgetMode( );
Expand All @@ -43,9 +43,9 @@ Return the widget mode

public slots:

virtual void refresh( ) = 0;
virtual void refresh( );
%Docstring
Triggered when the provider's connections need to be refreshed
The default implementation does nothing
%End

signals:
Expand Down
21 changes: 13 additions & 8 deletions src/gui/qgsarcgisservicesourceselect.cpp
Expand Up @@ -37,9 +37,9 @@
#include <QRadioButton>
#include <QImageReader>

/** \ingroup gui
/**
* Item delegate with tweaked sizeHint.
* @note not available in Python bindings */
*/
class QgsSourceSelectItemDelegate : public QItemDelegate
{
public:
Expand All @@ -49,12 +49,12 @@ class QgsSourceSelectItemDelegate : public QItemDelegate
};


QgsArcGisServiceSourceSelect::QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl ),
mServiceName( serviceName ),
mServiceType( serviceType ),
mBuildQueryButton( 0 ),
mImageEncodingGroup( 0 )
QgsArcGisServiceSourceSelect::QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
QgsSourceSelect( parent, fl, widgetMode ),
mServiceName( serviceName ),
mServiceType( serviceType ),
mBuildQueryButton( 0 ),
mImageEncodingGroup( 0 )
{
setupUi( this );
setWindowTitle( QStringLiteral( "Add %1 Layer from a Server" ).arg( mServiceName ) );
Expand Down Expand Up @@ -221,6 +221,11 @@ QString QgsArcGisServiceSourceSelect::getPreferredCrs( const QSet<QString> &crsS
return *( crsSet.constBegin() );
}

void QgsArcGisServiceSourceSelect::refresh()
{
populateConnectionList();
}

void QgsArcGisServiceSourceSelect::addEntryToServerList()
{

Expand Down
29 changes: 21 additions & 8 deletions src/gui/qgsarcgisservicesourceselect.h
Expand Up @@ -16,22 +16,32 @@
#ifndef QGSARCGISSERVICESOURCESELECTDIALOG_H
#define QGSARCGISSERVICESOURCESELECTDIALOG_H

/// @cond PRIVATE

//
// W A R N I N G
// -------------
//
// This file is not part of the QGIS API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//

#include "ui_qgsarcgisservicesourceselectbase.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"

#include "qgssourceselect.h"
#include "qgis_gui.h"

class QStandardItemModel;
class QSortFilterProxyModel;
class QgsProjectionSelectionDialog;
class QgsOwsConnection;

/** \ingroup gui
* Generic class listing layers available from a remote service.
* \since QGIS 3.0
/**
* Base class for listing ArcGis layers available from a remote service.
*/
class GUI_EXPORT QgsArcGisServiceSourceSelect : public QDialog, protected Ui::QgsArcGisServiceSourceSelectBase
class GUI_EXPORT QgsArcGisServiceSourceSelect : public QgsSourceSelect, protected Ui::QgsArcGisServiceSourceSelectBase
{
Q_OBJECT

Expand All @@ -40,7 +50,7 @@ class GUI_EXPORT QgsArcGisServiceSourceSelect : public QDialog, protected Ui::Qg
enum ServiceType { MapService, FeatureService };

//! Constructor
QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl );
QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );

~QgsArcGisServiceSourceSelect();
//! Sets the current extent and CRS. Used to select an appropriate CRS and possibly to retrieve data only in the current extent
Expand All @@ -49,8 +59,6 @@ class GUI_EXPORT QgsArcGisServiceSourceSelect : public QDialog, protected Ui::Qg
signals:
//! Emitted when a layer is added from the dialog
void addLayer( QString uri, QString typeName );
//! Emitted when the connections for the service were changed
void connectionsChanged();

protected:
QString mServiceName;
Expand Down Expand Up @@ -92,6 +100,11 @@ class GUI_EXPORT QgsArcGisServiceSourceSelect : public QDialog, protected Ui::Qg
\returns the authority id of the crs or an empty string in case of error*/
QString getPreferredCrs( const QSet<QString> &crsSet ) const;

public slots:

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

private slots:
void addEntryToServerList();
void deleteEntryOfServerList();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsbrowserdockwidget_p.h
Expand Up @@ -50,7 +50,7 @@ class QgsLayerItem;
class QgsDataItem;
class QgsBrowserTreeFilterProxyModel;

SIP_NO_FILE
#define SIP_NO_FILE

/**
* Hack to show wrapped text without spaces
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsdatasourcemanagerdialog.cpp
Expand Up @@ -117,6 +117,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) );
} );
connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) );
connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) );
}

addRasterProviderDialog( QStringLiteral( "arcgismapserver" ), tr( "ArcGIS Map Server" ), QStringLiteral( "/mActionAddAmsLayer.svg" ) );
Expand All @@ -129,6 +130,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
afss->setCurrentExtentAndCrs( mMapCanvas->extent(), mMapCanvas->mapSettings().destinationCrs() );
// Forward (if only a common interface for the signals had been used in the providers ...)
connect( afss, SIGNAL( addLayer( QString, QString ) ), this, SIGNAL( addAfsLayer( QString, QString ) ) );
connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), afss, SLOT( refresh( ) ) );
connect( this, &QgsDataSourceManagerDialog::addAfsLayer,
this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "arcgisfeatureserver" ) ); } );
Expand Down Expand Up @@ -234,6 +236,5 @@ 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( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) );
}
}
12 changes: 8 additions & 4 deletions src/gui/qgsowssourceselect.cpp
Expand Up @@ -55,14 +55,13 @@
#include <QNetworkReply>

QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QDialog( parent, fl )
: QgsSourceSelect( parent, fl, widgetMode )
, mService( service )
, mWidgetMode( widgetMode )
, mCurrentTileset( nullptr )
{
setupUi( this );

if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::None )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}
Expand All @@ -89,7 +88,7 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
// 'Prefer network' is the default noted in the combobox's tool tip
mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );

if ( mWidgetMode != QgsProviderRegistry::WidgetMode::Manager )
if ( QgsSourceSelect::widgetMode( ) != QgsProviderRegistry::WidgetMode::Manager )
{
connect( mAddButton, &QAbstractButton::clicked, this, &QgsOWSSourceSelect::addClicked );
//set the current project CRS if available
Expand Down Expand Up @@ -126,6 +125,11 @@ QgsOWSSourceSelect::~QgsOWSSourceSelect()
settings.setValue( QStringLiteral( "Windows/WMSSourceSelect/geometry" ), saveGeometry() );
}

void QgsOWSSourceSelect::refresh()
{
populateConnectionList();
}

void QgsOWSSourceSelect::clearFormats()
{
mFormatComboBox->clear();
Expand Down
15 changes: 7 additions & 8 deletions src/gui/qgsowssourceselect.h
Expand Up @@ -26,6 +26,7 @@
#include "qgsguiutils.h"
#include "qgscontexthelp.h"
#include "qgsproviderregistry.h"
#include "qgssourceselect.h"

#include <QStringList>
#include <QPushButton>
Expand All @@ -40,15 +41,15 @@ class QDomElement;


/** \ingroup gui
* \brief Dialog to create connections and add layers from WMS, WFS, WCS etc.
* \brief Dialog to create connections and add layers WCS etc.
*
* This dialog allows the user to define and save connection information
* for WMS servers, etc.
*
* The user can then connect and add
* layers from the WMS server to the map canvas.
* layers from the WCS server to the map canvas.
*/
class GUI_EXPORT QgsOWSSourceSelect : public QDialog, protected Ui::QgsOWSSourceSelectBase
class GUI_EXPORT QgsOWSSourceSelect : public QgsSourceSelect, protected Ui::QgsOWSSourceSelectBase
{
Q_OBJECT

Expand All @@ -67,6 +68,9 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, protected Ui::QgsOWSSource

public slots:

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

//! Opens the create connection dialog to build a new connection
void on_mNewButton_clicked();
//! Opens a dialog to edit an existing connection
Expand Down Expand Up @@ -110,7 +114,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, protected Ui::QgsOWSSource
void addRasterLayer( const QString &rasterLayerPath,
const QString &baseName,
const QString &providerKey );
void connectionsChanged();

protected:

Expand Down Expand Up @@ -167,10 +170,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, protected Ui::QgsOWSSource
//! Service name
QString mService;

//! Embedded mode, without 'Close'
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;


/**
* \brief Populate the layer list.
*
Expand Down
9 changes: 5 additions & 4 deletions src/gui/qgssourceselect.h
Expand Up @@ -27,7 +27,7 @@
#include <QDialog>

/** \ingroup gui
* \brief Abstract base Dialog to create connections and add layers
* \brief Abstract base Data Source Widget 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.
Expand All @@ -42,16 +42,17 @@ class GUI_EXPORT QgsSourceSelect : public QDialog
//! Constructor
QgsSourceSelect( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );

//! Destructor
~QgsSourceSelect( );
//! Pure Virtual Destructor
virtual ~QgsSourceSelect( ) = 0;

//! 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;
//! The default implementation does nothing
virtual void refresh( ) {}

signals:

Expand Down

0 comments on commit aba9da5

Please sign in to comment.