From 73b66fa1f5003aae7e9bca96c703eadf88f838d0 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Mon, 17 Jul 2017 16:59:33 +0200 Subject: [PATCH] Homogenize signals from different source select dialogs, move to base class --- python/gui/gui_auto.sip | 1 - python/gui/qgsabstractdatasourcewidget.sip | 65 +++++++++++-- python/gui/qgsarcgisservicesourceselect.sip | 91 ------------------- python/gui/qgsowssourceselect.sip | 6 +- src/app/qgisapp.cpp | 2 +- src/gui/qgsabstractdatasourcewidget.cpp | 25 ++++- src/gui/qgsabstractdatasourcewidget.h | 63 ++++++++++--- src/gui/qgsarcgisservicesourceselect.cpp | 2 +- src/gui/qgsarcgisservicesourceselect.h | 16 ++-- src/gui/qgsdatasourcemanagerdialog.cpp | 66 ++++++-------- src/gui/qgsdatasourcemanagerdialog.h | 27 +++--- src/gui/qgsowssourceselect.h | 6 +- src/providers/db2/qgsdb2sourceselect.h | 1 - src/providers/mssql/qgsmssqlsourceselect.h | 1 - src/providers/postgres/qgspgsourceselect.h | 1 - .../spatialite/qgsspatialitesourceselect.h | 5 - src/providers/wfs/qgswfssourceselect.cpp | 2 +- src/providers/wfs/qgswfssourceselect.h | 3 - src/providers/wms/qgswmssourceselect.h | 5 - 19 files changed, 188 insertions(+), 200 deletions(-) delete mode 100644 python/gui/qgsarcgisservicesourceselect.sip diff --git a/python/gui/gui_auto.sip b/python/gui/gui_auto.sip index ffa91b9c1aaa..852a58077280 100644 --- a/python/gui/gui_auto.sip +++ b/python/gui/gui_auto.sip @@ -158,7 +158,6 @@ %Include qgsoptionswidgetfactory.sip %Include qgsorderbydialog.sip %Include qgsowssourceselect.sip -%Include qgsarcgisservicesourceselect.sip %Include qgspanelwidget.sip %Include qgspanelwidgetstack.sip %Include qgspasswordlineedit.sip diff --git a/python/gui/qgsabstractdatasourcewidget.sip b/python/gui/qgsabstractdatasourcewidget.sip index 301ddef3cbe2..e50d3fbf4691 100644 --- a/python/gui/qgsabstractdatasourcewidget.sip +++ b/python/gui/qgsabstractdatasourcewidget.sip @@ -14,7 +14,7 @@ class QgsAbstractDataSourceWidget : QDialog { %Docstring Abstract base Data Source Widget to create connections and add layers - This class must provide common functionality and the interface for all + This class provides common functionality and the interface for all source select dialogs used by data providers to configure data sources and add layers. .. versionadded:: 3.0 @@ -25,34 +25,79 @@ class QgsAbstractDataSourceWidget : QDialog %End public: - QgsAbstractDataSourceWidget( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); + ~QgsAbstractDataSourceWidget( ); %Docstring -Constructor +Destructor %End - virtual ~QgsAbstractDataSourceWidget( ) = 0; + QgsProviderRegistry::WidgetMode widgetMode( ) const; %Docstring -Pure Virtual Destructor +Return the widget mode + :rtype: QgsProviderRegistry.WidgetMode %End - QgsProviderRegistry::WidgetMode widgetMode( ); + void setCurrentCrs( const QgsCoordinateReferenceSystem &crs ); %Docstring -Return the widget mode - :rtype: QgsProviderRegistry.WidgetMode + Set the current CRS + The CRS is normally the CRS of the map canvas, and it can be used + by the provider dialog to transform the extent and constraint the service +%End + + void setCurrentExtent( const QgsRectangle &extent ); +%Docstring + Set the current extent + The extent is normally the extent of the map canvas, and it can be used + by the provider dialog to constraint the service +%End + + QgsRectangle currentExtent( ) const; +%Docstring +Return the current extent + :rtype: QgsRectangle +%End + + QgsCoordinateReferenceSystem currentCrs( ) const; +%Docstring +Return the current CRS + :rtype: QgsCoordinateReferenceSystem %End public slots: virtual void refresh( ); %Docstring -The default implementation does nothing + Triggered when the provider's connections need to be refreshed + The default implementation does nothing %End signals: void connectionsChanged(); %Docstring -This signal is normally forwarded the app and used to refresh browser items + Emitted when the provider's connections have changed + This signal is normally forwarded the app and used to refresh browser items +%End + + void addDatabaseLayers( const QStringList &paths, const QString &providerKey ); +%Docstring +Emitted when a DB layer has been selected for addition +%End + + void addRasterLayer( const QString &rasterLayerPath, const QString &baseName, const QString &providerKey ); +%Docstring +Emitted when a raster layer has been selected for addition +%End + + void addVectorLayer( const QString &uri, const QString &layerName ); +%Docstring +Emitted when a vector layer has been selected for addition +%End + + protected: + + QgsAbstractDataSourceWidget( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); +%Docstring +Constructor %End }; diff --git a/python/gui/qgsarcgisservicesourceselect.sip b/python/gui/qgsarcgisservicesourceselect.sip deleted file mode 100644 index f49a3f9e2d1e..000000000000 --- a/python/gui/qgsarcgisservicesourceselect.sip +++ /dev/null @@ -1,91 +0,0 @@ -/************************************************************************ - * This file has been generated automatically from * - * * - * src/gui/qgsarcgisservicesourceselect.h * - * * - * Do not edit manually ! Edit header and run scripts/sipify.pl again * - ************************************************************************/ - - - - - - -class QgsArcGisServiceSourceSelect : QgsAbstractDataSourceWidget, protected Ui::QgsArcGisServiceSourceSelectBase -{ -%Docstring - Base class for listing ArcGis layers available from a remote service. -%End - -%TypeHeaderCode -#include "qgsarcgisservicesourceselect.h" -%End - public: - enum ServiceType { MapService, FeatureService }; - - QgsArcGisServiceSourceSelect( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); -%Docstring -Constructor -%End - - ~QgsArcGisServiceSourceSelect(); - void setCurrentExtentAndCrs( const QgsRectangle &canvasExtent, const QgsCoordinateReferenceSystem &canvasCrs ); -%Docstring -Sets the current extent and CRS. Used to select an appropriate CRS and possibly to retrieve data only in the current extent -%End - - signals: - void addLayer( QString uri, QString typeName ); -%Docstring -Emitted when a layer is added from the dialog -%End - - protected: - - virtual bool connectToService( const QgsOwsConnection &connection ) = 0; -%Docstring -To be implemented in the child class. Called when a new connection is initiated. - :rtype: bool -%End - virtual void buildQuery( const QgsOwsConnection &, const QModelIndex & ); -%Docstring -May be implemented in child classes for services which support customized queries. -%End - virtual QString getLayerURI( const QgsOwsConnection &connection, - const QString &layerTitle, - const QString &layerName, - const QString &crs = QString(), - const QString &filter = QString(), - const QgsRectangle &bBox = QgsRectangle() ) const = 0; -%Docstring -To be implemented in the child class. Constructs an URI for the specified service layer. - :rtype: str -%End - void populateImageEncodings( const QStringList &availableEncodings ); -%Docstring -Updates the UI for the list of available image encodings from the specified list. -%End - QString getSelectedImageEncoding() const; -%Docstring -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 - -}; - - -/************************************************************************ - * This file has been generated automatically from * - * * - * src/gui/qgsarcgisservicesourceselect.h * - * * - * Do not edit manually ! Edit header and run scripts/sipify.pl again * - ************************************************************************/ diff --git a/python/gui/qgsowssourceselect.sip b/python/gui/qgsowssourceselect.sip index 45b1009822fb..02b394ef496b 100644 --- a/python/gui/qgsowssourceselect.sip +++ b/python/gui/qgsowssourceselect.sip @@ -112,10 +112,7 @@ Stores the selected datasource whenerver it is changed Add some default wms servers to the list %End - signals: - void addRasterLayer( const QString &rasterLayerPath, - const QString &baseName, - const QString &providerKey ); + void on_mDialogButtonBox_helpRequested(); protected: @@ -256,6 +253,7 @@ Returns currently selected cache load control + }; /************************************************************************ diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 6c57310cc0b2..3a4e84666649 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1596,7 +1596,7 @@ void QgisApp::dataSourceManager( QString pageName ) { if ( ! mDataSourceManagerDialog ) { - mDataSourceManagerDialog = new QgsDataSourceManagerDialog( mapCanvas( ), this ); + mDataSourceManagerDialog = new QgsDataSourceManagerDialog( this, mapCanvas( ) ); // Forward signals to this connect( this, &QgisApp::connectionsChanged, mDataSourceManagerDialog, &QgsDataSourceManagerDialog::refresh ); connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::connectionsChanged, this, &QgisApp::connectionsChanged ); diff --git a/src/gui/qgsabstractdatasourcewidget.cpp b/src/gui/qgsabstractdatasourcewidget.cpp index 1e714a9ab309..b6bab91dca07 100644 --- a/src/gui/qgsabstractdatasourcewidget.cpp +++ b/src/gui/qgsabstractdatasourcewidget.cpp @@ -2,7 +2,8 @@ qgsabstractdatasourcewidget.cpp - base class for source selector widgets ------------------- begin : 10 July 2017 - original : (C) 2017 by Alessandro Pasotti email : apasotti at boundlessgeo dot com + original : (C) 2017 by Alessandro Pasotti + email : apasotti at boundlessgeo dot com ***************************************************************************/ @@ -24,7 +25,27 @@ QgsAbstractDataSourceWidget::QgsAbstractDataSourceWidget( QWidget *parent, Qt::W } -QgsAbstractDataSourceWidget::~QgsAbstractDataSourceWidget() +QgsProviderRegistry::WidgetMode QgsAbstractDataSourceWidget::widgetMode() const { + return mWidgetMode; +} + +void QgsAbstractDataSourceWidget::setCurrentCrs( const QgsCoordinateReferenceSystem &crs ) +{ + mCurrentCrs = crs; +} +void QgsAbstractDataSourceWidget::setCurrentExtent( const QgsRectangle &extent ) +{ + mCurrentExtent = extent; +} + +QgsRectangle QgsAbstractDataSourceWidget::currentExtent() const +{ + return mCurrentExtent; +} + +QgsCoordinateReferenceSystem QgsAbstractDataSourceWidget::currentCrs() const +{ + return mCurrentCrs; } diff --git a/src/gui/qgsabstractdatasourcewidget.h b/src/gui/qgsabstractdatasourcewidget.h index 349ca26580ea..7b57132f5146 100644 --- a/src/gui/qgsabstractdatasourcewidget.h +++ b/src/gui/qgsabstractdatasourcewidget.h @@ -2,7 +2,8 @@ qgsabstractdatasourcewidget.h - base class for source selector widgets ------------------- begin : 10 July 2017 - original : (C) 2017 by Alessandro Pasotti email : apasotti at boundlessgeo dot com + original : (C) 2017 by Alessandro Pasotti + email : apasotti at boundlessgeo dot com ***************************************************************************/ @@ -17,18 +18,20 @@ #ifndef QGSABSTRACTDATASOURCEWIDGET_H #define QGSABSTRACTDATASOURCEWIDGET_H + #include "qgis_sip.h" #include "qgis.h" #include "qgis_gui.h" #include "qgsproviderregistry.h" #include "qgsguiutils.h" - +#include "qgsrectangle.h" +#include "qgscoordinatereferencesystem.h" #include /** \ingroup gui * \brief Abstract base Data Source Widget to create connections and add layers - * This class must provide common functionality and the interface for all + * This class provides common functionality and the interface for all * source select dialogs used by data providers to configure data sources * and add layers. * \since QGIS 3.0 @@ -39,30 +42,64 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog public: - //! Constructor - QgsAbstractDataSourceWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); - - //! Pure Virtual Destructor - virtual ~QgsAbstractDataSourceWidget( ) = 0; + //! Destructor + ~QgsAbstractDataSourceWidget( ) = default; //! Return the widget mode - QgsProviderRegistry::WidgetMode widgetMode( ) { return mWidgetMode; } + QgsProviderRegistry::WidgetMode widgetMode( ) const; + + /** Set the current CRS + * The CRS is normally the CRS of the map canvas, and it can be used + * by the provider dialog to transform the extent and constraint the service + */ + void setCurrentCrs( const QgsCoordinateReferenceSystem &crs ); + + /** Set the current extent + * The extent is normally the extent of the map canvas, and it can be used + * by the provider dialog to constraint the service + */ + void setCurrentExtent( const QgsRectangle &extent ); + + //! Return the current extent + QgsRectangle currentExtent( ) const; + + //! Return the current CRS + QgsCoordinateReferenceSystem currentCrs( ) const; public slots: - //! Triggered when the provider's connections need to be refreshed - //! The default implementation does nothing + /** Triggered when the provider's connections need to be refreshed + * The default implementation does nothing + */ virtual void refresh( ) {} signals: - //! Emitted when the provider's connections have changed - //! This signal is normally forwarded the app and used to refresh browser items + /** Emitted when the provider's connections have changed + * This signal is normally forwarded the app and used to refresh browser items + */ void connectionsChanged(); + //! Emitted when a DB layer has been selected for addition + void addDatabaseLayers( const QStringList &paths, const QString &providerKey ); + + //! Emitted when a raster layer has been selected for addition + void addRasterLayer( const QString &rasterLayerPath, const QString &baseName, const QString &providerKey ); + + //! Emitted when a vector layer has been selected for addition + void addVectorLayer( const QString &uri, const QString &layerName ); + + protected: + + //! Constructor + QgsAbstractDataSourceWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); + private: QgsProviderRegistry::WidgetMode mWidgetMode; + QgsCoordinateReferenceSystem mCurrentCrs; + QgsRectangle mCurrentExtent; + }; #endif // QGSABSTRACTDATASOURCEWIDGET_H diff --git a/src/gui/qgsarcgisservicesourceselect.cpp b/src/gui/qgsarcgisservicesourceselect.cpp index 650d6141e50d..1bae28f0a2c1 100644 --- a/src/gui/qgsarcgisservicesourceselect.cpp +++ b/src/gui/qgsarcgisservicesourceselect.cpp @@ -25,10 +25,10 @@ #include "qgscoordinatereferencesystem.h" #include "qgscoordinatetransform.h" #include "qgslogger.h" -#include "qgsmapcanvas.h" #include "qgsmanageconnectionsdialog.h" #include "qgsexception.h" #include "qgssettings.h" +#include "qgsmapcanvas.h" #include #include diff --git a/src/gui/qgsarcgisservicesourceselect.h b/src/gui/qgsarcgisservicesourceselect.h index dfa19e79e91c..6560aa984912 100644 --- a/src/gui/qgsarcgisservicesourceselect.h +++ b/src/gui/qgsarcgisservicesourceselect.h @@ -13,8 +13,8 @@ * * ***************************************************************************/ -#ifndef QGSARCGISSERVICESOURCESELECTDIALOG_H -#define QGSARCGISSERVICESOURCESELECTDIALOG_H +#ifndef QGSARCGISSERVICESOURCESELECT_H +#define QGSARCGISSERVICESOURCESELECT_H /// @cond PRIVATE @@ -27,6 +27,9 @@ // version without notice, or even be removed. // + +#define SIP_NO_FILE + #include "ui_qgsarcgisservicesourceselectbase.h" #include "qgsrectangle.h" #include "qgscoordinatereferencesystem.h" @@ -52,9 +55,8 @@ class GUI_EXPORT QgsArcGisServiceSourceSelect : public QgsAbstractDataSourceWidg //! Constructor 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 - void setCurrentExtentAndCrs( const QgsRectangle &canvasExtent, const QgsCoordinateReferenceSystem &canvasCrs ); + //! Destructor + ~QgsArcGisServiceSourceSelect() override; signals: //! Emitted when a layer is added from the dialog @@ -89,6 +91,8 @@ class GUI_EXPORT QgsArcGisServiceSourceSelect : public QgsAbstractDataSourceWidg void populateImageEncodings( const QStringList &availableEncodings ); //! Returns the selected image encoding. QString getSelectedImageEncoding() const; + //! Sets the current extent and CRS. Used to select an appropriate CRS and possibly to retrieve data only in the current extent + void setCurrentExtentAndCrs( const QgsRectangle &canvasExtent, const QgsCoordinateReferenceSystem &canvasCrs ); private: void populateConnectionList(); @@ -122,4 +126,4 @@ class GUI_EXPORT QgsArcGisServiceSourceSelect : public QgsAbstractDataSourceWidg }; -#endif // QGSARCGISSERVICESOURCESELECTDIALOG_H +#endif // QGSARCGISSERVICESOURCESELECT_H diff --git a/src/gui/qgsdatasourcemanagerdialog.cpp b/src/gui/qgsdatasourcemanagerdialog.cpp index 6b06c846c080..4b6c43f2cf2d 100644 --- a/src/gui/qgsdatasourcemanagerdialog.cpp +++ b/src/gui/qgsdatasourcemanagerdialog.cpp @@ -23,15 +23,14 @@ #include "qgssettings.h" #include "qgsproviderregistry.h" #include "qgsopenvectorlayerdialog.h" -#include "qgsarcgisservicesourceselect.h" +#include "qgsabstractdatasourcewidget.h" #include "qgsmapcanvas.h" - -QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent, Qt::WindowFlags fl ) : +QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent, QgsMapCanvas *canvas, Qt::WindowFlags fl ) : QgsOptionsDialogBase( QStringLiteral( "Data Source Manager" ), parent, fl ), ui( new Ui::QgsDataSourceManagerDialog ), - mMapCanvas( mapCanvas ), - mPreviousRow( -1 ) + mPreviousRow( -1 ), + mMapCanvas( canvas ) { ui->setupUi( this ); @@ -71,7 +70,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, mPageNames.append( QStringLiteral( "raster" ) ); // Add data provider dialogs - QDialog *dlg = nullptr; + QWidget *dlg = nullptr; dlg = providerDialog( QStringLiteral( "delimitedtext" ), tr( "Delimited Text" ), QStringLiteral( "/mActionAddDelimitedTextLayer.svg" ) ); @@ -106,35 +105,11 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, addRasterProviderDialog( QStringLiteral( "wcs" ), tr( "WCS" ), QStringLiteral( "/mActionAddWcsLayer.svg" ) ); - dlg = providerDialog( QStringLiteral( "WFS" ), tr( "WFS" ), QStringLiteral( "/mActionAddWfsLayer.svg" ) ); - - if ( dlg ) - { - // Forward (if only a common interface for the signals had been used in the providers ...) - connect( dlg, SIGNAL( addWfsLayer( QString, QString ) ), this, SIGNAL( addWfsLayer( QString, QString ) ) ); - connect( this, &QgsDataSourceManagerDialog::addWfsLayer, this, [ = ]( const QString & vectorLayerPath, const QString & baseName ) - { - this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) ); - } ); - connect( dlg, SIGNAL( connectionsChanged( ) ), this, SIGNAL( connectionsChanged( ) ) ); - connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) ); - } + addVectorProviderDialog( QStringLiteral( "WFS" ), tr( "WFS" ), QStringLiteral( "/mActionAddWfsLayer.svg" ) ); addRasterProviderDialog( QStringLiteral( "arcgismapserver" ), tr( "ArcGIS Map Server" ), QStringLiteral( "/mActionAddAmsLayer.svg" ) ); - QgsArcGisServiceSourceSelect *afss = dynamic_cast( providerDialog( QStringLiteral( "arcgisfeatureserver" ), - tr( "ArcGIS Feature Server" ), - QStringLiteral( "/mActionAddAfsLayer.svg" ) ) ); - if ( afss && mMapCanvas ) - { - 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" ) ); } ); - } + addVectorProviderDialog( QStringLiteral( "arcgisfeatureserver" ), tr( "ArcGIS Feature Server" ), QStringLiteral( "/mActionAddAfsLayer.svg" ) ); } @@ -192,9 +167,9 @@ void QgsDataSourceManagerDialog::vectorLayersAdded( const QStringList &layerQStr } -QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, const QString providerName, const QString icon, QString title ) +QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, const QString providerName, const QString icon, QString title ) { - QDialog *dlg = dynamic_cast( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded ) ); + QgsAbstractDataSourceWidget *dlg = dynamic_cast( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded ) ); if ( !dlg ) { QMessageBox::warning( this, providerName, tr( "Cannot get %1 select dialog from provider %2." ).arg( providerName, providerKey ) ); @@ -207,13 +182,19 @@ QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, QListWidgetItem *layerItem = new QListWidgetItem( providerName, ui->mOptionsListWidget ); layerItem->setToolTip( title.isEmpty() ? tr( "Add %1 layer" ).arg( providerName ) : title ); layerItem->setIcon( QgsApplication::getThemeIcon( icon ) ); + // Set crs and extent from canvas + if ( mMapCanvas ) + { + dlg->setCurrentExtent( mMapCanvas->extent() ); + dlg->setCurrentCrs( mMapCanvas->mapSettings().destinationCrs( ) ); + } return dlg; } } void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title ) { - QDialog *dlg = providerDialog( providerKey, providerName, icon, title ); + QgsAbstractDataSourceWidget *dlg = providerDialog( providerKey, providerName, icon, title ); if ( dlg ) { connect( dlg, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ), @@ -229,12 +210,23 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey, void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title ) { - QDialog *dlg = providerDialog( providerKey, providerName, icon, title ); + QgsAbstractDataSourceWidget *dlg = providerDialog( providerKey, providerName, icon, title ); if ( dlg ) { - // 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( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) ); + } +} + +void QgsDataSourceManagerDialog::addVectorProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title ) +{ + QgsAbstractDataSourceWidget *dlg = providerDialog( providerKey, providerName, icon, title ); + if ( dlg ) + { + connect( dlg, &QgsAbstractDataSourceWidget::addVectorLayer, this, [ = ]( const QString & vectorLayerPath, const QString & baseName ) + { this->vectorLayerAdded( vectorLayerPath, baseName, providerKey ); } ); + connect( this, SIGNAL( providerDialogsRefreshRequested( ) ), dlg, SLOT( refresh( ) ) ); } } diff --git a/src/gui/qgsdatasourcemanagerdialog.h b/src/gui/qgsdatasourcemanagerdialog.h index ff41601f862d..e47eb3f78750 100644 --- a/src/gui/qgsdatasourcemanagerdialog.h +++ b/src/gui/qgsdatasourcemanagerdialog.h @@ -31,6 +31,7 @@ class QgsBrowserDockWidget; class QgsRasterLayer; class QgsMapCanvas; +class QgsAbstractDataSourceWidget; /** \ingroup gui * The QgsDataSourceManagerDialog class embeds the browser panel and all @@ -47,11 +48,10 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva public: /** QgsDataSourceManagerDialog constructor - * @param mapCanvas the map canvas * @param parent the object * @param fl window flags */ - explicit QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags ); + explicit QgsDataSourceManagerDialog( QWidget *parent = nullptr, QgsMapCanvas *canvas = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags ); ~QgsDataSourceManagerDialog(); /** @@ -67,6 +67,7 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva void setCurrentPage( int index ); //! A raster layer was added: for signal forwarding to QgisApp + //! TODO: use this with an internal source select dialog instead of forwarding the whole raster selection to app void rasterLayerAdded( QString const &uri, QString const &baseName, QString const &providerKey ); //! A vector layer was added: for signal forwarding to QgisApp void vectorLayerAdded( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey ); @@ -79,17 +80,13 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva signals: //! Emitted when a raster layer was selected for addition: for signal forwarding to QgisApp - void addRasterLayer( QString const &uri, QString const &baseName, QString const &providerKey ); + void addRasterLayer( const QString &uri, const QString &baseName, const QString &providerKey ); //! Emitted when the user wants to select a raster layer: for signal forwarding to QgisApp void addRasterLayer(); //! Emitted when a vector layer was selected for addition: for signal forwarding to QgisApp void addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey ); //! Replace the selected layer by a vector layer defined by uri, layer name, data source uri void replaceSelectedVectorLayer( const QString &oldId, const QString &uri, const QString &layerName, const QString &provider ); - //! Emitted when a WFS layer was selected for addition: for signal forwarding to QgisApp - void addWfsLayer( const QString &uri, const QString &typeName ); - //! Emitted when a AFS layer was selected for addition: for signal forwarding to QgisApp - void addAfsLayer( const QString &uri, const QString &typeName ); //! Emitted when a one or more layer were selected for addition: for signal forwarding to QgisApp void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType ); //! Emitted when the dialog is busy: for signal forwarding to QgisApp @@ -97,30 +94,34 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva //! Emitted when a status message needs to be shown: for signal forwarding to QgisApp void showStatusMessage( const QString &message ); //! Emitted when a DB layer was selected for addition: for signal forwarding to QgisApp - void addDatabaseLayers( QStringList const &layerPathList, QString const &providerKey ); + void addDatabaseLayers( const QStringList &layerPathList, const QString &providerKey ); //! Emitted when a file needs to be opened void openFile( const QString & ); //! Emitted when drop uri list needs to be handled from the browser void handleDropUriList( const QgsMimeDataUtils::UriList & ); //! Update project home directory void updateProjectHome(); - //! Connections changed + //! Emitted when a connection has changed inside the provider dialogs + //! This signal is normally forwarded to the application to notify other + //! browsers that they need to refresh their connections list void connectionsChanged( ); //! One or more provider connections have changed and the //! dialogs should be refreshed void providerDialogsRefreshRequested( ); private: - //! Return the dialog from the provider - QDialog *providerDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString( ) ); + // Return the dialog from the provider + QgsAbstractDataSourceWidget *providerDialog( const QString providerKey, const QString providerName, const QString icon, QString title = QString( ) ); void addDbProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString( ) ); void addRasterProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString( ) ); + void addVectorProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString( ) ); Ui::QgsDataSourceManagerDialog *ui; QgsBrowserDockWidget *mBrowserWidget = nullptr; - //! Map canvas - QgsMapCanvas *mMapCanvas = nullptr; int mPreviousRow; QStringList mPageNames; + // Map canvas + QgsMapCanvas *mMapCanvas = nullptr; + }; diff --git a/src/gui/qgsowssourceselect.h b/src/gui/qgsowssourceselect.h index 50358e2dd484..0ef2047a3f87 100644 --- a/src/gui/qgsowssourceselect.h +++ b/src/gui/qgsowssourceselect.h @@ -110,10 +110,7 @@ class GUI_EXPORT QgsOWSSourceSelect : public QgsAbstractDataSourceWidget, protec //! Add some default wms servers to the list void on_mAddDefaultButton_clicked(); - signals: - void addRasterLayer( const QString &rasterLayerPath, - const QString &baseName, - const QString &providerKey ); + void on_mDialogButtonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); } protected: @@ -225,6 +222,7 @@ class GUI_EXPORT QgsOWSSourceSelect : public QgsAbstractDataSourceWidget, protec //! URI for selected connection QgsDataSourceUri mUri; + private: //! Selected CRS QString mSelectedCRS; diff --git a/src/providers/db2/qgsdb2sourceselect.h b/src/providers/db2/qgsdb2sourceselect.h index 81a9db2c8a35..f3155923efa0 100644 --- a/src/providers/db2/qgsdb2sourceselect.h +++ b/src/providers/db2/qgsdb2sourceselect.h @@ -109,7 +109,6 @@ class QgsDb2SourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDb QString connectionInfo(); signals: - void addDatabaseLayers( QStringList const &layerPathList, QString const &providerKey ); void addGeometryColumn( QgsDb2LayerProperty ); void progress( int, int ); void progressMessage( QString ); diff --git a/src/providers/mssql/qgsmssqlsourceselect.h b/src/providers/mssql/qgsmssqlsourceselect.h index c4580481ebf6..b0e4b81998f0 100644 --- a/src/providers/mssql/qgsmssqlsourceselect.h +++ b/src/providers/mssql/qgsmssqlsourceselect.h @@ -79,7 +79,6 @@ class QgsMssqlSourceSelect : public QgsAbstractDataSourceWidget, private Ui::Qgs QString connectionInfo(); signals: - void addDatabaseLayers( QStringList const &layerPathList, QString const &providerKey ); void addGeometryColumn( const QgsMssqlLayerProperty & ); void progress( int, int ); void progressMessage( QString ); diff --git a/src/providers/postgres/qgspgsourceselect.h b/src/providers/postgres/qgspgsourceselect.h index 5ad750f5e6cc..1fa5ce3fff1f 100644 --- a/src/providers/postgres/qgspgsourceselect.h +++ b/src/providers/postgres/qgspgsourceselect.h @@ -78,7 +78,6 @@ class QgsPgSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDbS QgsDataSourceUri dataSourceUri(); signals: - void addDatabaseLayers( QStringList const &layerPathList, QString const &providerKey ); void addGeometryColumn( const QgsPostgresLayerProperty & ); void progress( int, int ); void progressMessage( const QString & ); diff --git a/src/providers/spatialite/qgsspatialitesourceselect.h b/src/providers/spatialite/qgsspatialitesourceselect.h index 9be162a7962e..281d6d2ffd4b 100644 --- a/src/providers/spatialite/qgsspatialitesourceselect.h +++ b/src/providers/spatialite/qgsspatialitesourceselect.h @@ -98,11 +98,6 @@ class QgsSpatiaLiteSourceSelect: public QgsAbstractDataSourceWidget, private Ui: void on_buttonBox_helpRequested() { QgsHelp::openHelp( QStringLiteral( "working_with_vector/supported_data.html#spatialite-layers" ) ); } - signals: - void addDatabaseLayers( QStringList const &paths, QString const &providerKey ); - void progress( int, int ); - void progressMessage( QString ); - private: enum Columns { diff --git a/src/providers/wfs/qgswfssourceselect.cpp b/src/providers/wfs/qgswfssourceselect.cpp index dfb9d1f52e92..760b84451dd1 100644 --- a/src/providers/wfs/qgswfssourceselect.cpp +++ b/src/providers/wfs/qgswfssourceselect.cpp @@ -405,7 +405,7 @@ void QgsWFSSourceSelect::addLayer() mUri = QgsWFSDataSourceURI::build( connection.uri().uri(), typeName, pCrsString, sql, cbxFeatureCurrentViewExtent->isChecked() ); - emit addWfsLayer( mUri, layerName ); + emit addVectorLayer( mUri, layerName ); } if ( ! mHoldDialogOpen->isChecked() && QgsAbstractDataSourceWidget::widgetMode( ) == QgsProviderRegistry::WidgetMode::None ) diff --git a/src/providers/wfs/qgswfssourceselect.h b/src/providers/wfs/qgswfssourceselect.h index c775711c00be..959b8de9b98b 100644 --- a/src/providers/wfs/qgswfssourceselect.h +++ b/src/providers/wfs/qgswfssourceselect.h @@ -52,9 +52,6 @@ class QgsWFSSourceSelect: public QgsAbstractDataSourceWidget, private Ui::QgsWFS QgsWFSSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); ~QgsWFSSourceSelect(); - signals: - void addWfsLayer( const QString &uri, const QString &layerName ); - private: QgsWFSSourceSelect(); //default constructor is forbidden QgsProjectionSelectionDialog *mProjectionSelector = nullptr; diff --git a/src/providers/wms/qgswmssourceselect.h b/src/providers/wms/qgswmssourceselect.h index ed1fd698b2ee..e80a5be2f0c8 100644 --- a/src/providers/wms/qgswmssourceselect.h +++ b/src/providers/wms/qgswmssourceselect.h @@ -188,11 +188,6 @@ class QgsWMSSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsWM QList mTileLayers; - signals: - void addRasterLayer( QString const &rasterLayerPath, - QString const &baseName, - QString const &providerKey ); - void connectionsChanged(); private slots: void on_btnSearch_clicked(); void on_btnAddWMS_clicked();