mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Merge pull request #5124 from boundlessgeo/providers_gui_config
Providers gui config
This commit is contained in:
commit
5f5be25357
@ -21,6 +21,8 @@
|
||||
%Include qgsvertexmarker.sip
|
||||
%Include qgsfiledownloader.sip
|
||||
%Include qgsabstractdatasourcewidget.sip
|
||||
%Include qgssourceselectprovider.sip
|
||||
%Include qgssourceselectproviderregistry.sip
|
||||
%Include attributetable/qgsfeaturemodel.sip
|
||||
%Include auth/qgsauthauthoritieseditor.sip
|
||||
%Include auth/qgsauthcertificateinfo.sip
|
||||
|
@ -90,6 +90,16 @@ Emitted when a vector layer has been selected for addition
|
||||
\param dataSourceType string (can be "file" or "database")
|
||||
%End
|
||||
|
||||
void replaceVectorLayer( const QString &oldId, const QString &source, const QString &name, const QString &provider );
|
||||
%Docstring
|
||||
Emitted when a layer needs to be replaced
|
||||
\param oldId old layer ID
|
||||
\param source URI of the layer
|
||||
\param name of the layer
|
||||
\param provider key
|
||||
%End
|
||||
|
||||
|
||||
void progress( int, int );
|
||||
%Docstring
|
||||
Emitted when a progress dialog is shown by the provider dialog
|
||||
|
@ -38,6 +38,12 @@ class QgsGui
|
||||
:rtype: QgsEditorWidgetRegistry
|
||||
%End
|
||||
|
||||
static QgsSourceSelectProviderRegistry *sourceSelectProviderRegistry();
|
||||
%Docstring
|
||||
Returns the global source select provider registry, used for managing all known source select widget factories.
|
||||
:rtype: QgsSourceSelectProviderRegistry
|
||||
%End
|
||||
|
||||
static QgsShortcutsManager *shortcutsManager();
|
||||
%Docstring
|
||||
Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
|
||||
|
85
python/gui/qgssourceselectprovider.sip
Normal file
85
python/gui/qgssourceselectprovider.sip
Normal file
@ -0,0 +1,85 @@
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
* src/gui/qgssourceselectprovider.h *
|
||||
* *
|
||||
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||
************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
class QgsSourceSelectProvider
|
||||
{
|
||||
%Docstring
|
||||
This is the interface for those who want to add entries to the QgsDataSourceManagerDialog
|
||||
|
||||
.. versionadded:: 3.0
|
||||
%End
|
||||
|
||||
%TypeHeaderCode
|
||||
#include "qgssourceselectprovider.h"
|
||||
%End
|
||||
public:
|
||||
virtual ~QgsSourceSelectProvider();
|
||||
|
||||
virtual QString providerKey() const = 0;
|
||||
%Docstring
|
||||
Data Provider key
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
virtual QString name() const;
|
||||
%Docstring
|
||||
Source select provider name, this is useful to retrieve
|
||||
a particular source select in case the provider has more
|
||||
than one, it should be unique among all providers.
|
||||
|
||||
The default implementation returns the providerKey()
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
virtual QString text() const = 0;
|
||||
%Docstring
|
||||
Text for the menu item entry, it will be visible to the user so make sure it's translatable
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
virtual QString toolTip() const;
|
||||
%Docstring
|
||||
Text for the tooltip menu item entry, it will be visible to the user so make sure it's translatable
|
||||
|
||||
The default implementation returns an empty string.
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
virtual QIcon icon() const = 0;
|
||||
%Docstring
|
||||
Creates a new instance of an QIcon for the menu item entry
|
||||
:rtype: QIcon
|
||||
%End
|
||||
|
||||
virtual int ordering( ) const;
|
||||
%Docstring
|
||||
Ordering: the source select provider registry will be able to sort
|
||||
the source selects (ascending) using this integer value
|
||||
:rtype: int
|
||||
%End
|
||||
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = 0, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const = 0 /Factory/;
|
||||
%Docstring
|
||||
Create a new instance of QgsAbstractDataSourceWidget (or null).
|
||||
Caller takes responsibility of deleting created.
|
||||
:rtype: QgsAbstractDataSourceWidget
|
||||
%End
|
||||
|
||||
};
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
* src/gui/qgssourceselectprovider.h *
|
||||
* *
|
||||
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||
************************************************************************/
|
78
python/gui/qgssourceselectproviderregistry.sip
Normal file
78
python/gui/qgssourceselectproviderregistry.sip
Normal file
@ -0,0 +1,78 @@
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
* src/gui/qgssourceselectproviderregistry.h *
|
||||
* *
|
||||
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||
************************************************************************/
|
||||
|
||||
|
||||
|
||||
class QgsSourceSelectProviderRegistry
|
||||
{
|
||||
%Docstring
|
||||
This class keeps a list of source select providers that may add items to the QgsDataSourceManagerDialog
|
||||
When created, it automatically adds providers from data provider plugins (e.g. PostGIS, WMS, ...)
|
||||
|
||||
QgsSourceSelectProviderRegistry is not usually directly created, but rather accessed through
|
||||
QgsGui.sourceSelectProviderRegistry().
|
||||
|
||||
.. note::
|
||||
|
||||
This class access to QgsProviderRegistry instance to initialize, but QgsProviderRegistry is
|
||||
typically initialized after QgsGui is constructed, for this reason a delayed initialization has been
|
||||
implemented in the class.
|
||||
|
||||
.. versionadded:: 3.0
|
||||
%End
|
||||
|
||||
%TypeHeaderCode
|
||||
#include "qgssourceselectproviderregistry.h"
|
||||
%End
|
||||
public:
|
||||
QgsSourceSelectProviderRegistry();
|
||||
|
||||
~QgsSourceSelectProviderRegistry();
|
||||
|
||||
|
||||
QList< QgsSourceSelectProvider *> providers();
|
||||
%Docstring
|
||||
Get list of available providers
|
||||
:rtype: list of QgsSourceSelectProvider
|
||||
%End
|
||||
|
||||
void addProvider( QgsSourceSelectProvider *provider /Transfer/ );
|
||||
%Docstring
|
||||
Add a ``provider`` implementation. Takes ownership of the object.
|
||||
%End
|
||||
|
||||
bool removeProvider( QgsSourceSelectProvider *provider /Transfer/ );
|
||||
%Docstring
|
||||
:return: true if the provider was actually removed and deleted
|
||||
:rtype: bool
|
||||
%End
|
||||
|
||||
QgsSourceSelectProvider *providerByName( const QString &name );
|
||||
%Docstring
|
||||
Return a provider by ``name`` or None if not found
|
||||
:rtype: QgsSourceSelectProvider
|
||||
%End
|
||||
|
||||
QList<QgsSourceSelectProvider *> providersByKey( const QString &providerKey );
|
||||
%Docstring
|
||||
Return a (possibly empty) list of providers by data ``providerkey``
|
||||
:rtype: list of QgsSourceSelectProvider
|
||||
%End
|
||||
|
||||
|
||||
private:
|
||||
QgsSourceSelectProviderRegistry( const QgsSourceSelectProviderRegistry &rh );
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
* src/gui/qgssourceselectproviderregistry.h *
|
||||
* *
|
||||
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||
************************************************************************/
|
@ -349,6 +349,8 @@ SET(QGIS_GUI_SRCS
|
||||
qgsfiledownloader.cpp
|
||||
qgsdatasourcemanagerdialog.cpp
|
||||
qgsabstractdatasourcewidget.cpp
|
||||
qgssourceselectprovider.cpp
|
||||
qgssourceselectproviderregistry.cpp
|
||||
)
|
||||
|
||||
SET(QGIS_GUI_MOC_HDRS
|
||||
@ -711,6 +713,8 @@ SET(QGIS_GUI_HDRS
|
||||
qgsfiledownloader.h
|
||||
qgsdatasourcemanagerdialog.h
|
||||
qgsabstractdatasourcewidget.h
|
||||
qgssourceselectprovider.h
|
||||
qgssourceselectproviderregistry.h
|
||||
|
||||
ogr/qgsogrhelperfunctions.h
|
||||
ogr/qgsnewogrconnection.h
|
||||
|
@ -93,6 +93,15 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
|
||||
*/
|
||||
void addVectorLayers( const QStringList &layerList, const QString &encoding, const QString &dataSourceType );
|
||||
|
||||
/** Emitted when a layer needs to be replaced
|
||||
* \param oldId old layer ID
|
||||
* \param source URI of the layer
|
||||
* \param name of the layer
|
||||
* \param provider key
|
||||
*/
|
||||
void replaceVectorLayer( const QString &oldId, const QString &source, const QString &name, const QString &provider );
|
||||
|
||||
|
||||
//! Emitted when a progress dialog is shown by the provider dialog
|
||||
void progress( int, int );
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QListWidgetItem>
|
||||
|
||||
#include "qgsdatasourcemanagerdialog.h"
|
||||
@ -22,8 +21,12 @@
|
||||
#include "qgsbrowserdockwidget.h"
|
||||
#include "qgssettings.h"
|
||||
#include "qgsproviderregistry.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#include "qgssourceselectproviderregistry.h"
|
||||
#include "qgsabstractdatasourcewidget.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgsgui.h"
|
||||
|
||||
QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent, QgsMapCanvas *canvas, Qt::WindowFlags fl ) :
|
||||
QgsOptionsDialogBase( QStringLiteral( "Data Source Manager" ), parent, fl ),
|
||||
@ -55,49 +58,19 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent, QgsMapC
|
||||
connect( mBrowserWidget, &QgsBrowserDockWidget::connectionsChanged, this, &QgsDataSourceManagerDialog::connectionsChanged );
|
||||
connect( this, &QgsDataSourceManagerDialog::updateProjectHome, mBrowserWidget, &QgsBrowserDockWidget::updateProjectHome );
|
||||
|
||||
// Add data provider dialogs
|
||||
QWidget *dlg = nullptr;
|
||||
|
||||
addVectorProviderDialog( QStringLiteral( "ogr" ), tr( "Vector" ), QStringLiteral( "/mActionAddOgrLayer.svg" ) );
|
||||
|
||||
addRasterProviderDialog( QStringLiteral( "gdal" ), tr( "Raster" ), QStringLiteral( "/mActionAddRasterLayer.svg" ) );
|
||||
|
||||
addVectorProviderDialog( QStringLiteral( "delimitedtext" ), tr( "Delimited Text" ), QStringLiteral( "/mActionAddDelimitedTextLayer.svg" ) );
|
||||
|
||||
#ifdef HAVE_POSTGRESQL
|
||||
addDbProviderDialog( QStringLiteral( "postgres" ), tr( "PostgreSQL" ), QStringLiteral( "/mActionAddPostgisLayer.svg" ) );
|
||||
#endif
|
||||
|
||||
addDbProviderDialog( QStringLiteral( "spatialite" ), tr( "SpatiaLite" ), QStringLiteral( "/mActionAddSpatiaLiteLayer.svg" ) );
|
||||
|
||||
addDbProviderDialog( QStringLiteral( "mssql" ), tr( "MSSQL" ), QStringLiteral( "/mActionAddMssqlLayer.svg" ) );
|
||||
|
||||
addDbProviderDialog( QStringLiteral( "DB2" ), tr( "DB2" ), QStringLiteral( "/mActionAddDb2Layer.svg" ) );
|
||||
|
||||
#ifdef HAVE_ORACLE
|
||||
addDbProviderDialog( QStringLiteral( "oracle" ), tr( "Oracle" ), QStringLiteral( "/mActionAddOracleLayer.svg" ) );
|
||||
#endif
|
||||
|
||||
dlg = addVectorProviderDialog( QStringLiteral( "virtual" ), tr( "Virtual Layer" ), QStringLiteral( "/mActionAddVirtualLayer.svg" ) );
|
||||
|
||||
// Apparently this is the only provider using replaceVectorLayer, we should
|
||||
// move this in to the base abstract class when it is used by at least one
|
||||
// additional provider.
|
||||
if ( dlg )
|
||||
// Add provider dialogs
|
||||
const QList<QgsSourceSelectProvider *> sourceSelectProviders = QgsGui::sourceSelectProviderRegistry()->providers( ) ;
|
||||
for ( const auto provider : sourceSelectProviders )
|
||||
{
|
||||
connect( dlg, SIGNAL( replaceVectorLayer( QString, QString, QString, QString ) ), this, SIGNAL( replaceSelectedVectorLayer( QString, QString, QString, QString ) ) );
|
||||
QgsAbstractDataSourceWidget *dlg = provider->createDataSourceWidget( this );
|
||||
if ( !dlg )
|
||||
{
|
||||
QgsMessageLog::logMessage( tr( "Cannot get %1 select dialog from source select provider %2." ).arg( provider->name(), provider->providerKey() ), QStringLiteral( "DataSourceManager" ), QgsMessageLog::CRITICAL );
|
||||
continue;
|
||||
}
|
||||
addProviderDialog( dlg, provider->providerKey(), provider->text(), provider->icon( ), provider->toolTip( ) );
|
||||
}
|
||||
|
||||
addRasterProviderDialog( QStringLiteral( "wms" ), tr( "WMS" ), QStringLiteral( "/mActionAddWmsLayer.svg" ) );
|
||||
|
||||
addRasterProviderDialog( QStringLiteral( "wcs" ), tr( "WCS" ), QStringLiteral( "/mActionAddWcsLayer.svg" ) );
|
||||
|
||||
addVectorProviderDialog( QStringLiteral( "WFS" ), tr( "WFS" ), QStringLiteral( "/mActionAddWfsLayer.svg" ) );
|
||||
|
||||
addRasterProviderDialog( QStringLiteral( "arcgismapserver" ), tr( "ArcGIS Map Server" ), QStringLiteral( "/mActionAddAmsLayer.svg" ) );
|
||||
|
||||
addVectorProviderDialog( QStringLiteral( "arcgisfeatureserver" ), tr( "ArcGIS Feature Server" ), QStringLiteral( "/mActionAddAfsLayer.svg" ) );
|
||||
|
||||
}
|
||||
|
||||
QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
|
||||
@ -149,73 +122,51 @@ void QgsDataSourceManagerDialog::vectorLayersAdded( const QStringList &layerQStr
|
||||
}
|
||||
|
||||
|
||||
QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
|
||||
void QgsDataSourceManagerDialog::addProviderDialog( QgsAbstractDataSourceWidget *dlg, const QString &providerKey, const QString &providerName, const QIcon &icon, QString toolTip )
|
||||
{
|
||||
QgsAbstractDataSourceWidget *dlg = dynamic_cast<QgsAbstractDataSourceWidget *>( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded ) );
|
||||
if ( !dlg )
|
||||
mPageNames.append( providerKey );
|
||||
ui->mOptionsStackedWidget->addWidget( dlg );
|
||||
QListWidgetItem *layerItem = new QListWidgetItem( providerName, ui->mOptionsListWidget );
|
||||
layerItem->setToolTip( toolTip.isEmpty() ? tr( "Add %1 layer" ).arg( providerName ) : toolTip );
|
||||
layerItem->setIcon( icon );
|
||||
// Set crs and extent from canvas
|
||||
if ( mMapCanvas )
|
||||
{
|
||||
QMessageBox::warning( this, providerName, tr( "Cannot get %1 select dialog from provider %2." ).arg( providerName, providerKey ) );
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
mPageNames.append( providerKey );
|
||||
ui->mOptionsStackedWidget->addWidget( dlg );
|
||||
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->setMapCanvas( mMapCanvas );
|
||||
}
|
||||
connect( dlg, &QgsAbstractDataSourceWidget::rejected, this, &QgsDataSourceManagerDialog::reject );
|
||||
connect( dlg, &QgsAbstractDataSourceWidget::accepted, this, &QgsDataSourceManagerDialog::accept );
|
||||
return dlg;
|
||||
dlg->setMapCanvas( mMapCanvas );
|
||||
}
|
||||
connect( dlg, &QgsAbstractDataSourceWidget::rejected, this, &QgsDataSourceManagerDialog::reject );
|
||||
connect( dlg, &QgsAbstractDataSourceWidget::accepted, this, &QgsDataSourceManagerDialog::accept );
|
||||
makeConnections( dlg, providerKey );
|
||||
}
|
||||
|
||||
QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
|
||||
void QgsDataSourceManagerDialog::makeConnections( QgsAbstractDataSourceWidget *dlg, const QString &providerKey )
|
||||
{
|
||||
QgsAbstractDataSourceWidget *dlg = providerDialog( providerKey, providerName, icon, title );
|
||||
if ( dlg )
|
||||
// DB
|
||||
connect( dlg, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
|
||||
this, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ) );
|
||||
connect( dlg, SIGNAL( progress( int, int ) ),
|
||||
this, SIGNAL( showProgress( int, int ) ) );
|
||||
connect( dlg, SIGNAL( progressMessage( QString ) ),
|
||||
this, SIGNAL( showStatusMessage( QString ) ) );
|
||||
// Vector
|
||||
connect( dlg, &QgsAbstractDataSourceWidget::addVectorLayer, this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
|
||||
{
|
||||
connect( dlg, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
|
||||
this, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ) );
|
||||
connect( dlg, SIGNAL( progress( int, int ) ),
|
||||
this, SIGNAL( showProgress( int, int ) ) );
|
||||
connect( dlg, SIGNAL( progressMessage( QString ) ),
|
||||
this, SIGNAL( showStatusMessage( QString ) ) );
|
||||
connect( dlg, SIGNAL( connectionsChanged() ), this, SIGNAL( connectionsChanged() ) );
|
||||
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
|
||||
this->vectorLayerAdded( vectorLayerPath, baseName, providerKey );
|
||||
}
|
||||
return dlg;
|
||||
}
|
||||
);
|
||||
connect( dlg, &QgsAbstractDataSourceWidget::addVectorLayers,
|
||||
this, &QgsDataSourceManagerDialog::vectorLayersAdded );
|
||||
connect( dlg, SIGNAL( connectionsChanged() ), this, SIGNAL( connectionsChanged() ) );
|
||||
// Raster
|
||||
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
|
||||
this, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ) );
|
||||
|
||||
QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::addRasterProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
|
||||
{
|
||||
QgsAbstractDataSourceWidget *dlg = providerDialog( providerKey, providerName, icon, title );
|
||||
if ( dlg )
|
||||
{
|
||||
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() ) );
|
||||
}
|
||||
return dlg;
|
||||
}
|
||||
|
||||
QgsAbstractDataSourceWidget *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( dlg, &QgsAbstractDataSourceWidget::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );
|
||||
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
|
||||
}
|
||||
return dlg;
|
||||
// Virtual
|
||||
connect( dlg, SIGNAL( replaceVectorLayer( QString, QString, QString, QString ) ),
|
||||
this, SIGNAL( replaceSelectedVectorLayer( QString, QString, QString, QString ) ) );
|
||||
// Common
|
||||
connect( dlg, SIGNAL( connectionsChanged() ), this, SIGNAL( connectionsChanged() ) );
|
||||
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
|
||||
}
|
||||
|
||||
void QgsDataSourceManagerDialog::showEvent( QShowEvent *e )
|
||||
|
@ -114,11 +114,8 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
|
||||
void providerDialogsRefreshRequested();
|
||||
|
||||
private:
|
||||
// Return the dialog from the provider
|
||||
QgsAbstractDataSourceWidget *providerDialog( const QString providerKey, const QString providerName, const QString icon, QString title = QString() );
|
||||
QgsAbstractDataSourceWidget *addDbProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString() );
|
||||
QgsAbstractDataSourceWidget *addRasterProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString() );
|
||||
QgsAbstractDataSourceWidget *addVectorProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString() );
|
||||
void addProviderDialog( QgsAbstractDataSourceWidget *dlg, const QString &providerKey, const QString &providerName, const QIcon &icon, QString toolTip = QString() );
|
||||
void makeConnections( QgsAbstractDataSourceWidget *dlg, const QString &providerKey );
|
||||
Ui::QgsDataSourceManagerDialog *ui;
|
||||
QgsBrowserDockWidget *mBrowserWidget = nullptr;
|
||||
int mPreviousRow;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "qgseditorwidgetregistry.h"
|
||||
#include "qgslayertreeembeddedwidgetregistry.h"
|
||||
#include "qgsmaplayeractionregistry.h"
|
||||
#include "qgssourceselectproviderregistry.h"
|
||||
#include "qgslayoutitemregistry.h"
|
||||
#include "qgslayoutitemguiregistry.h"
|
||||
#include "qgslayoutviewrubberband.h"
|
||||
@ -45,6 +46,11 @@ QgsEditorWidgetRegistry *QgsGui::editorWidgetRegistry()
|
||||
return instance()->mEditorWidgetRegistry;
|
||||
}
|
||||
|
||||
QgsSourceSelectProviderRegistry *QgsGui::sourceSelectProviderRegistry()
|
||||
{
|
||||
return instance()->mSourceSelectProviderRegistry;
|
||||
}
|
||||
|
||||
QgsShortcutsManager *QgsGui::shortcutsManager()
|
||||
{
|
||||
return instance()->mShortcutsManager;
|
||||
@ -71,6 +77,7 @@ QgsGui::~QgsGui()
|
||||
delete mLayerTreeEmbeddedWidgetRegistry;
|
||||
delete mEditorWidgetRegistry;
|
||||
delete mMapLayerActionRegistry;
|
||||
delete mSourceSelectProviderRegistry;
|
||||
delete mShortcutsManager;
|
||||
delete mNative;
|
||||
}
|
||||
@ -87,6 +94,7 @@ QgsGui::QgsGui()
|
||||
mShortcutsManager = new QgsShortcutsManager();
|
||||
mLayerTreeEmbeddedWidgetRegistry = new QgsLayerTreeEmbeddedWidgetRegistry();
|
||||
mMapLayerActionRegistry = new QgsMapLayerActionRegistry();
|
||||
mSourceSelectProviderRegistry = new QgsSourceSelectProviderRegistry();
|
||||
mLayoutItemGuiRegistry = new QgsLayoutItemGuiRegistry();
|
||||
mLayoutItemGuiRegistry->populate();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ class QgsEditorWidgetRegistry;
|
||||
class QgsShortcutsManager;
|
||||
class QgsLayerTreeEmbeddedWidgetRegistry;
|
||||
class QgsMapLayerActionRegistry;
|
||||
class QgsSourceSelectProviderRegistry;
|
||||
class QgsNative;
|
||||
class QgsLayoutItemGuiRegistry;
|
||||
|
||||
@ -61,6 +62,11 @@ class GUI_EXPORT QgsGui
|
||||
*/
|
||||
static QgsEditorWidgetRegistry *editorWidgetRegistry();
|
||||
|
||||
/**
|
||||
* Returns the global source select provider registry, used for managing all known source select widget factories.
|
||||
*/
|
||||
static QgsSourceSelectProviderRegistry *sourceSelectProviderRegistry();
|
||||
|
||||
/**
|
||||
* Returns the global shortcuts manager, used for managing a QAction and QShortcut sequences.
|
||||
*/
|
||||
@ -89,6 +95,7 @@ class GUI_EXPORT QgsGui
|
||||
|
||||
QgsNative *mNative = nullptr;
|
||||
QgsEditorWidgetRegistry *mEditorWidgetRegistry = nullptr;
|
||||
QgsSourceSelectProviderRegistry *mSourceSelectProviderRegistry = nullptr;
|
||||
QgsShortcutsManager *mShortcutsManager = nullptr;
|
||||
QgsLayerTreeEmbeddedWidgetRegistry *mLayerTreeEmbeddedWidgetRegistry = nullptr;
|
||||
QgsMapLayerActionRegistry *mMapLayerActionRegistry = nullptr;
|
||||
|
20
src/gui/qgssourceselectprovider.cpp
Normal file
20
src/gui/qgssourceselectprovider.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
/***************************************************************************
|
||||
qgssourceselectprovider.cpp - QgsSourceSelectProvider
|
||||
|
||||
---------------------
|
||||
begin : 1.9.2017
|
||||
copyright : (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 "qgssourceselectprovider.h"
|
||||
|
||||
|
||||
// no implementation currently
|
||||
|
75
src/gui/qgssourceselectprovider.h
Normal file
75
src/gui/qgssourceselectprovider.h
Normal file
@ -0,0 +1,75 @@
|
||||
/***************************************************************************
|
||||
qgssourceselectprovider.h - QgsSourceSelectProvider
|
||||
|
||||
---------------------
|
||||
begin : 1.9.2017
|
||||
copyright : (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 QGSSOURCESELECTPROVIDER_H
|
||||
#define QGSSOURCESELECTPROVIDER_H
|
||||
|
||||
|
||||
#include "qgis_gui.h"
|
||||
#include "qgis.h"
|
||||
#include "qgsguiutils.h"
|
||||
#include "qgsproviderregistry.h"
|
||||
#include "qgsabstractdatasourcewidget.h"
|
||||
|
||||
class QString;
|
||||
class QWidget;
|
||||
|
||||
/** \ingroup gui
|
||||
* This is the interface for those who want to add entries to the QgsDataSourceManagerDialog
|
||||
*
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class GUI_EXPORT QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
virtual ~QgsSourceSelectProvider() = default;
|
||||
|
||||
//! Data Provider key
|
||||
virtual QString providerKey() const = 0;
|
||||
|
||||
/** Source select provider name, this is useful to retrieve
|
||||
* a particular source select in case the provider has more
|
||||
* than one, it should be unique among all providers.
|
||||
*
|
||||
* The default implementation returns the providerKey()
|
||||
*/
|
||||
virtual QString name() const { return providerKey(); }
|
||||
|
||||
//! Text for the menu item entry, it will be visible to the user so make sure it's translatable
|
||||
virtual QString text() const = 0;
|
||||
|
||||
/** Text for the tooltip menu item entry, it will be visible to the user so make sure it's translatable
|
||||
*
|
||||
* The default implementation returns an empty string.
|
||||
*/
|
||||
virtual QString toolTip() const { return QString(); }
|
||||
|
||||
//! Creates a new instance of an QIcon for the menu item entry
|
||||
virtual QIcon icon() const = 0;
|
||||
|
||||
/** Ordering: the source select provider registry will be able to sort
|
||||
* the source selects (ascending) using this integer value
|
||||
*/
|
||||
virtual int ordering( ) const { return 0; }
|
||||
|
||||
/** Create a new instance of QgsAbstractDataSourceWidget (or null).
|
||||
* Caller takes responsibility of deleting created.
|
||||
*/
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const = 0 SIP_FACTORY;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // QGSSOURCESELECTPROVIDER_H
|
115
src/gui/qgssourceselectproviderregistry.cpp
Normal file
115
src/gui/qgssourceselectproviderregistry.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/***************************************************************************
|
||||
qgssourceselectproviderregistry.cpp - QgsSourceSelectProviderRegistry
|
||||
|
||||
---------------------
|
||||
begin : 1.9.2017
|
||||
copyright : (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 "qgssourceselectprovider.h"
|
||||
#include "qgssourceselectproviderregistry.h"
|
||||
#include "qgsproviderregistry.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
typedef QList<QgsSourceSelectProvider *> *sourceSelectProviders_t();
|
||||
|
||||
|
||||
QgsSourceSelectProviderRegistry::QgsSourceSelectProviderRegistry()
|
||||
{
|
||||
// Initialization is delayed
|
||||
}
|
||||
|
||||
QgsSourceSelectProviderRegistry::~QgsSourceSelectProviderRegistry()
|
||||
{
|
||||
qDeleteAll( mProviders );
|
||||
}
|
||||
|
||||
QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providers()
|
||||
{
|
||||
init();
|
||||
return mProviders;
|
||||
}
|
||||
|
||||
void QgsSourceSelectProviderRegistry::addProvider( QgsSourceSelectProvider *provider )
|
||||
{
|
||||
mProviders.append( provider );
|
||||
std::sort( mProviders.begin(), mProviders.end(), [ ]( const QgsSourceSelectProvider * first, const QgsSourceSelectProvider * second ) -> bool
|
||||
{
|
||||
return first->ordering() < second->ordering();
|
||||
} );
|
||||
}
|
||||
|
||||
bool QgsSourceSelectProviderRegistry::removeProvider( QgsSourceSelectProvider *provider )
|
||||
{
|
||||
int index = mProviders.indexOf( provider );
|
||||
if ( index >= 0 )
|
||||
{
|
||||
delete mProviders.takeAt( index );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QgsSourceSelectProvider *QgsSourceSelectProviderRegistry::providerByName( const QString &name )
|
||||
{
|
||||
const QList<QgsSourceSelectProvider *> providerList = providers();
|
||||
for ( const auto provider : providerList )
|
||||
{
|
||||
if ( provider->name() == name )
|
||||
{
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providersByKey( const QString &providerKey )
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> result;
|
||||
const QList<QgsSourceSelectProvider *> providerList = providers();
|
||||
for ( const auto provider : providerList )
|
||||
{
|
||||
if ( provider->providerKey() == providerKey )
|
||||
{
|
||||
result << provider;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void QgsSourceSelectProviderRegistry::init()
|
||||
{
|
||||
if ( mInitialized )
|
||||
{
|
||||
return;
|
||||
}
|
||||
const QStringList providersList = QgsProviderRegistry::instance()->providerList();
|
||||
for ( const QString &key : providersList )
|
||||
{
|
||||
std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->createProviderLibrary( key ) );
|
||||
if ( !library )
|
||||
continue;
|
||||
|
||||
sourceSelectProviders_t *sourceSelectProvidersFn = reinterpret_cast< sourceSelectProviders_t * >( cast_to_fptr( library->resolve( "sourceSelectProviders" ) ) );
|
||||
if ( sourceSelectProvidersFn )
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providerList = sourceSelectProvidersFn();
|
||||
// the function is a factory - we keep ownership of the returned providers
|
||||
for ( auto provider : qgsAsConst( *providerList ) )
|
||||
{
|
||||
addProvider( provider );
|
||||
}
|
||||
delete providerList;
|
||||
}
|
||||
}
|
||||
mInitialized = true;
|
||||
}
|
||||
|
80
src/gui/qgssourceselectproviderregistry.h
Normal file
80
src/gui/qgssourceselectproviderregistry.h
Normal file
@ -0,0 +1,80 @@
|
||||
/***************************************************************************
|
||||
qgssourceselectproviderregistry.h - QgsSourceSelectProviderRegistry
|
||||
|
||||
---------------------
|
||||
begin : 1.9.2017
|
||||
copyright : (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 QGSSOURCESELECTPROVIDERREGISTRY_H
|
||||
#define QGSSOURCESELECTPROVIDERREGISTRY_H
|
||||
|
||||
#include "qgis_gui.h"
|
||||
#include "qgis.h"
|
||||
|
||||
class QgsSourceSelectProvider;
|
||||
|
||||
/** \ingroup gui
|
||||
* This class keeps a list of source select providers that may add items to the QgsDataSourceManagerDialog
|
||||
* When created, it automatically adds providers from data provider plugins (e.g. PostGIS, WMS, ...)
|
||||
*
|
||||
* QgsSourceSelectProviderRegistry is not usually directly created, but rather accessed through
|
||||
* QgsGui::sourceSelectProviderRegistry().
|
||||
*
|
||||
* \note This class access to QgsProviderRegistry instance to initialize, but QgsProviderRegistry is
|
||||
* typically initialized after QgsGui is constructed, for this reason a delayed initialization has been
|
||||
* implemented in the class.
|
||||
*
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class GUI_EXPORT QgsSourceSelectProviderRegistry
|
||||
{
|
||||
public:
|
||||
QgsSourceSelectProviderRegistry();
|
||||
|
||||
~QgsSourceSelectProviderRegistry();
|
||||
|
||||
//! QgsDataItemProviderRegistry cannot be copied.
|
||||
QgsSourceSelectProviderRegistry( const QgsSourceSelectProviderRegistry &rh ) = delete;
|
||||
//! QgsDataItemProviderRegistry cannot be copied.
|
||||
QgsSourceSelectProviderRegistry &operator=( const QgsSourceSelectProviderRegistry &rh ) = delete;
|
||||
|
||||
//! Get list of available providers
|
||||
QList< QgsSourceSelectProvider *> providers();
|
||||
|
||||
//! Add a \a provider implementation. Takes ownership of the object.
|
||||
void addProvider( QgsSourceSelectProvider *provider SIP_TRANSFER );
|
||||
|
||||
//! Remove \a provider implementation from the list (\a provider object is deleted)
|
||||
//! \returns true if the provider was actually removed and deleted
|
||||
bool removeProvider( QgsSourceSelectProvider *provider SIP_TRANSFER );
|
||||
|
||||
//! Return a provider by \a name or nullptr if not found
|
||||
QgsSourceSelectProvider *providerByName( const QString &name );
|
||||
|
||||
//! Return a (possibly empty) list of providers by data \a providerkey
|
||||
QList<QgsSourceSelectProvider *> providersByKey( const QString &providerKey );
|
||||
|
||||
|
||||
private:
|
||||
//! Populate the providers list, this needs to happen after the data provider
|
||||
//! registry has been initialized.
|
||||
void init();
|
||||
bool mInitialized = false;
|
||||
#ifdef SIP_RUN
|
||||
QgsSourceSelectProviderRegistry( const QgsSourceSelectProviderRegistry &rh );
|
||||
#endif
|
||||
|
||||
//! available providers. this class owns the pointers
|
||||
QList<QgsSourceSelectProvider *> mProviders;
|
||||
|
||||
};
|
||||
|
||||
#endif // QGSSOURCESELECTPROVIDERREGISTRY_H
|
@ -23,6 +23,11 @@
|
||||
#include "geometry/qgsgeometry.h"
|
||||
#include "qgsnetworkaccessmanager.h"
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgsafssourceselect.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkRequest>
|
||||
@ -196,3 +201,33 @@ void QgsAfsProvider::reloadData()
|
||||
{
|
||||
mSharedData->mCache.clear();
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for AFS layers source select
|
||||
class QgsAfsSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "arcgisfeatureserver" ); }
|
||||
virtual QString text() const override { return QObject::tr( "ArcGIS Feature Server" ); }
|
||||
virtual int ordering() const override { return 140; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddAfsLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsAfsSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsAfsSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
#endif
|
||||
|
@ -24,6 +24,11 @@
|
||||
#include "qgsfeaturestore.h"
|
||||
#include "qgsgeometry.h"
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgsamssourceselect.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
#include <cstring>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
@ -449,3 +454,32 @@ void QgsAmsProvider::readBlock( int /*bandNo*/, const QgsRectangle &viewExtent,
|
||||
}
|
||||
std::memcpy( data, mCachedImage.constBits(), mCachedImage.bytesPerLine() * mCachedImage.height() );
|
||||
}
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for AMS layers source select
|
||||
class QgsAmsSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "arcgismapserver" ); }
|
||||
virtual QString text() const override { return QObject::tr( "ArcGIS Map Server" ); }
|
||||
virtual int ordering() const override { return 130; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddAmsLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsAmsSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsAmsSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
#endif
|
||||
|
@ -28,7 +28,7 @@ class QgsAmsSourceSelect: public QgsArcGisServiceSourceSelect
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QgsAmsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
|
||||
QgsAmsSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
|
||||
|
||||
protected:
|
||||
bool connectToService( const QgsOwsConnection &connection ) override;
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgsdb2sourceselect.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
static const QString PROVIDER_KEY = QStringLiteral( "DB2" );
|
||||
@ -1748,3 +1749,34 @@ QGISEXTERN QgsVectorLayerExporter::ExportError createEmptyLayer(
|
||||
oldToNewAttrIdxMap, errorMessage, options
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for DB2 source select
|
||||
class QgsDb2SourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "DB2" ); }
|
||||
virtual QString text() const override { return QObject::tr( "DB2" ); }
|
||||
virtual int ordering() const override { return 70; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddDb2Layer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsDb2SourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsDb2SourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -41,6 +41,9 @@
|
||||
#include "qgsspatialindex.h"
|
||||
#include "qgis.h"
|
||||
#include "qgsproviderregistry.h"
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
#include "qgsdelimitedtextfeatureiterator.h"
|
||||
#include "qgsdelimitedtextfile.h"
|
||||
@ -1196,4 +1199,33 @@ QGISEXTERN QgsDelimitedTextSourceSelect *selectWidget( QWidget *parent, Qt::Wind
|
||||
{
|
||||
return new QgsDelimitedTextSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
|
||||
//! Provider for delimited text source select
|
||||
class QgsDelimitedTextSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "delimitedtext" ); }
|
||||
virtual QString text() const override { return QObject::tr( "Delimited Text" ); }
|
||||
virtual int ordering() const override { return 30; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddDelimitedTextLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsDelimitedTextSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsDelimitedTextSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -35,6 +35,11 @@
|
||||
#include "qgspointxy.h"
|
||||
#include "qgssettings.h"
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgssourceselectprovider.h"
|
||||
#include "qgsgdalsourceselect.h"
|
||||
#endif
|
||||
|
||||
#include <QImage>
|
||||
#include <QColor>
|
||||
#include <QProcess>
|
||||
@ -3041,3 +3046,34 @@ QGISEXTERN void cleanupProvider()
|
||||
// nothing to do here, QgsApplication takes care of
|
||||
// calling GDALDestroyDriverManager()
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for gdal raster source select
|
||||
class QgsGdalRasterSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "gdal" ); }
|
||||
virtual QString text() const override { return QObject::tr( "Raster" ); }
|
||||
virtual int ordering() const override { return 20; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddRasterLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsGdalSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsGdalRasterSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgsmssqlsourceselect.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
static const QString TEXT_PROVIDER_KEY = QStringLiteral( "mssql" );
|
||||
@ -2307,3 +2308,34 @@ QGISEXTERN QString getStyleById( const QString &uri, QString styleId, QString &e
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for msssql raster source select
|
||||
class QgsMssqlSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "mssql" ); }
|
||||
virtual QString text() const override { return QObject::tr( "MSSQL" ); }
|
||||
virtual int ordering() const override { return 60; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMssqlLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsMssqlSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsMssqlSourceSelectProvider ;
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -50,4 +50,5 @@ class QgsOgrDataCollectionItem : public QgsDataCollectionItem
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // QGSOGRDATAITEMS_H
|
||||
|
@ -35,6 +35,12 @@ email : sherman at mrcc.com
|
||||
#include "qgsogrdataitems.h"
|
||||
#include "qgsgeopackagedataitems.h"
|
||||
#include "qgswkbtypes.h"
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgssourceselectprovider.h"
|
||||
#include "qgsogrsourceselect.h"
|
||||
#endif
|
||||
|
||||
#include "qgis.h"
|
||||
|
||||
|
||||
@ -4368,3 +4374,33 @@ QGISEXTERN bool deleteLayer( const QString &uri, QString &errCause )
|
||||
errCause = QObject::tr( "Layer not found: %1" ).arg( uri );
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for OGR vector source select
|
||||
class QgsOgrVectorSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "ogr" ); }
|
||||
virtual QString text() const override { return QObject::tr( "Vector" ); }
|
||||
virtual int ordering() const override { return 10; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOgrLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsOgrSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsOgrVectorSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgsoraclesourceselect.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
#include <QSqlRecord>
|
||||
@ -3582,4 +3583,36 @@ QGISEXTERN QString getStyleById( const QString &uri, QString styleId, QString &e
|
||||
return style;
|
||||
}
|
||||
|
||||
// vim: set sw=2 :
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for Oracle source select
|
||||
class QgsOracleSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "oracle" ); }
|
||||
virtual QString text() const override { return QObject::tr( "Oracle" ); }
|
||||
virtual int ordering() { return 80; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOracleLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsOracleSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsOracleSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// vim: set sw=2
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgspgsourceselect.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
const QString POSTGRES_KEY = QStringLiteral( "postgres" );
|
||||
@ -4752,6 +4753,36 @@ QGISEXTERN void cleanupProvider()
|
||||
QgsPostgresConnPool::cleanupInstance();
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for postgres source select
|
||||
class QgsPostgresSourceSelectProvider : public QgsSourceSelectProvider //#spellok
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "postgres" ); }
|
||||
virtual QString text() const override { return QObject::tr( "PostgreSQL" ); }
|
||||
virtual int ordering() const override { return 40; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPostgisLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsPgSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsPostgresSourceSelectProvider; //#spellok
|
||||
|
||||
return providers;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ----------
|
||||
|
||||
QgsPostgresSharedData::QgsPostgresSharedData()
|
||||
|
@ -34,6 +34,11 @@ email : a.furieri@lqt.it
|
||||
#include "qgsjsonutils.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgssourceselectprovider.h"
|
||||
#include "qgsspatialitesourceselect.h"
|
||||
#endif
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
@ -5917,3 +5922,31 @@ QGISEXTERN void cleanupProvider()
|
||||
QgsSqliteHandle::closeAll();
|
||||
}
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for spatialite source select
|
||||
class QgsSpatialiteSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "spatialite" ); }
|
||||
virtual QString text() const override { return QObject::tr( "SpatiaLite" ); }
|
||||
virtual int ordering() const override { return 50; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddSpatiaLiteLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsSpatiaLiteSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsSpatialiteSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
#endif
|
||||
|
@ -36,6 +36,11 @@ extern "C"
|
||||
#include "qgsvirtuallayersqlitemodule.h"
|
||||
#include "qgsvirtuallayerqueryparser.h"
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgssourceselectprovider.h"
|
||||
#include "qgsvirtuallayersourceselect.h"
|
||||
#endif
|
||||
|
||||
const QString VIRTUAL_LAYER_KEY = QStringLiteral( "virtual" );
|
||||
const QString VIRTUAL_LAYER_DESCRIPTION = QStringLiteral( "Virtual layer data provider" );
|
||||
|
||||
@ -647,3 +652,34 @@ QGISEXTERN bool isProvider()
|
||||
QGISEXTERN void cleanupProvider()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for virtual layers source select
|
||||
class QgsVirtualSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "virtual" ); }
|
||||
virtual QString text() const override { return QObject::tr( "Virtual Layer" ); }
|
||||
virtual int ordering() const override { return 90; }
|
||||
virtual QString toolTip() const override { return QObject::tr( "Add Virtual Layer" ); }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddVirtualLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsVirtualLayerSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsVirtualSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
#endif
|
||||
|
@ -53,9 +53,6 @@ class QgsVirtualLayerSourceSelect : public QgsAbstractDataSourceWidget, private
|
||||
void onTableRowChanged( const QModelIndex ¤t, const QModelIndex &previous );
|
||||
void updateLayersList();
|
||||
|
||||
signals:
|
||||
//! Old_id, source, name, provider
|
||||
void replaceVectorLayer( QString, QString, QString, QString );
|
||||
|
||||
private:
|
||||
QgsVirtualLayerDefinition getVirtualLayerDef();
|
||||
|
@ -32,6 +32,11 @@
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgsexception.h"
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgswcssourceselect.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkProxy>
|
||||
@ -1925,3 +1930,32 @@ void QgsWcsDownloadHandler::canceled()
|
||||
mCacheReply->abort();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for WCS layers source select
|
||||
class QgsWcsSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "wcs" ); }
|
||||
virtual QString text() const override { return QObject::tr( "WCS" ); }
|
||||
virtual int ordering() const override { return 110; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWcsLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsWCSSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsWcsSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
#endif
|
||||
|
@ -35,6 +35,11 @@
|
||||
#include "qgswfsutils.h"
|
||||
#include "qgssettings.h"
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgswfssourceselect.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QMessageBox>
|
||||
#include <QDomNodeList>
|
||||
@ -1698,3 +1703,32 @@ QGISEXTERN bool isProvider()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for WFS layers source select
|
||||
class QgsWfsSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "WFS" ); }
|
||||
virtual QString text() const override { return QObject::tr( "WFS" ); }
|
||||
virtual int ordering() const override { return 120; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWfsLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsWFSSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsWfsSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
#endif
|
||||
|
@ -64,17 +64,22 @@ TARGET_LINK_LIBRARIES(wmsprovider
|
||||
${GDAL_LIBRARY} # for OGR_G_CreateGeometryFromJson()
|
||||
)
|
||||
|
||||
IF (WITH_GUI)
|
||||
TARGET_LINK_LIBRARIES (wmsprovider
|
||||
qgis_gui
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
TARGET_LINK_LIBRARIES(wmsprovider_a
|
||||
qgis_core
|
||||
${QT_QTSCRIPT_LIBRARY}
|
||||
)
|
||||
|
||||
|
||||
IF (WITH_GUI)
|
||||
TARGET_LINK_LIBRARIES (wmsprovider
|
||||
qgis_gui
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (wmsprovider_a
|
||||
qgis_gui
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
INSTALL (TARGETS wmsprovider
|
||||
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
|
||||
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
|
||||
|
@ -47,6 +47,13 @@
|
||||
#include "qgsexception.h"
|
||||
#include "qgssettings.h"
|
||||
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "qgswmssourceselect.h"
|
||||
#include "qgssourceselectprovider.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkProxy>
|
||||
@ -4218,3 +4225,34 @@ QgsCachedImageFetcher::start()
|
||||
{
|
||||
QTimer::singleShot( 1, this, SLOT( send() ) );
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
|
||||
//! Provider for WMS layers source select
|
||||
class QgsWmsSourceSelectProvider : public QgsSourceSelectProvider
|
||||
{
|
||||
public:
|
||||
|
||||
virtual QString providerKey() const override { return QStringLiteral( "wms" ); }
|
||||
virtual QString text() const override { return QObject::tr( "WMS" ); }
|
||||
virtual int ordering() const override { return 100; }
|
||||
virtual QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWmsLayer.svg" ) ); }
|
||||
virtual QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
|
||||
{
|
||||
return new QgsWMSSourceSelect( parent, fl, widgetMode );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
|
||||
{
|
||||
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();
|
||||
|
||||
*providers
|
||||
<< new QgsWmsSourceSelectProvider;
|
||||
|
||||
return providers;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -176,6 +176,7 @@ ADD_PYTHON_TEST(PyQgsDBManagerGpkg test_db_manager_gpkg.py)
|
||||
ADD_PYTHON_TEST(PyQgsFileDownloader test_qgsfiledownloader.py)
|
||||
ADD_PYTHON_TEST(PyQgsSettings test_qgssettings.py)
|
||||
ADD_PYTHON_TEST(PyQgsZipUtils test_qgsziputils.py)
|
||||
ADD_PYTHON_TEST(PyQgsSourceSelectProvider test_qgssourceselectprovider.py)
|
||||
|
||||
IF (NOT WIN32)
|
||||
ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py)
|
||||
|
156
tests/src/python/test_qgssourceselectprovider.py
Normal file
156
tests/src/python/test_qgssourceselectprovider.py
Normal file
@ -0,0 +1,156 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test the QgsSourceSelectProvider
|
||||
and QgsSourceSelectProviderRegistry classes
|
||||
|
||||
Run with: ctest -V -R PyQgsSourceSelectProvider
|
||||
|
||||
.. note:: 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.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from qgis.gui import (QgsGui, QgsSourceSelectProvider, QgsSourceSelectProviderRegistry, QgsAbstractDataSourceWidget)
|
||||
from qgis.testing import start_app, unittest
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtWidgets import QWidget
|
||||
|
||||
__author__ = 'Alessandro Pasotti'
|
||||
__date__ = '01/09/2017'
|
||||
__copyright__ = 'Copyright 2017, The QGIS Project'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
|
||||
start_app()
|
||||
|
||||
|
||||
class ConcreteDataSourceWidget(QgsAbstractDataSourceWidget):
|
||||
pass
|
||||
|
||||
|
||||
class ConcreteSourceSelectProvider(QgsSourceSelectProvider):
|
||||
|
||||
def providerKey(self):
|
||||
return "MyTestProviderKey"
|
||||
|
||||
def text(self):
|
||||
return "MyTestProviderText"
|
||||
|
||||
def icon(self):
|
||||
return QIcon()
|
||||
|
||||
def createDataSourceWidget(self):
|
||||
return ConcreteDataSourceWidget()
|
||||
|
||||
def ordering(self):
|
||||
return 1
|
||||
|
||||
|
||||
class ConcreteSourceSelectProvider2(QgsSourceSelectProvider):
|
||||
|
||||
def providerKey(self):
|
||||
return "MyTestProviderKey2"
|
||||
|
||||
def text(self):
|
||||
return "MyTestProviderText2"
|
||||
|
||||
def name(self):
|
||||
return "MyName"
|
||||
|
||||
def toolTip(self):
|
||||
return "MyToolTip"
|
||||
|
||||
def icon(self):
|
||||
return QIcon()
|
||||
|
||||
def createDataSourceWidget(self):
|
||||
return ConcreteDataSourceWidget()
|
||||
|
||||
def ordering(self):
|
||||
return 2
|
||||
|
||||
|
||||
class TestQgsSourceSelectProvider(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def testConcreteClass(self):
|
||||
|
||||
provider = ConcreteSourceSelectProvider()
|
||||
self.assertTrue(isinstance(provider, ConcreteSourceSelectProvider))
|
||||
widget = provider.createDataSourceWidget()
|
||||
self.assertTrue(isinstance(widget, ConcreteDataSourceWidget))
|
||||
self.assertEqual(provider.providerKey(), "MyTestProviderKey")
|
||||
self.assertEqual(provider.name(), "MyTestProviderKey")
|
||||
self.assertEqual(provider.text(), "MyTestProviderText")
|
||||
self.assertEqual(provider.toolTip(), "")
|
||||
self.assertEqual(provider.ordering(), 1)
|
||||
self.assertTrue(isinstance(provider.icon(), QIcon))
|
||||
|
||||
# test toolTip
|
||||
provider = ConcreteSourceSelectProvider2()
|
||||
self.assertEqual(provider.toolTip(), "MyToolTip")
|
||||
|
||||
def _testRegistry(self, registry):
|
||||
|
||||
registry.addProvider(ConcreteSourceSelectProvider())
|
||||
registry.addProvider(ConcreteSourceSelectProvider2())
|
||||
|
||||
# Check order
|
||||
self.assertEqual(['MyTestProviderKey', 'MyName'], [p.name() for p in registry.providers() if p.providerKey().startswith('MyTestProviderKey')])
|
||||
|
||||
registry = QgsSourceSelectProviderRegistry()
|
||||
registry.addProvider(ConcreteSourceSelectProvider())
|
||||
registry.addProvider(ConcreteSourceSelectProvider2())
|
||||
|
||||
# Check order
|
||||
self.assertEqual(['MyTestProviderKey', 'MyName'], [p.name() for p in registry.providers() if p.providerKey().startswith('MyTestProviderKey')])
|
||||
|
||||
# Get provider by name
|
||||
self.assertTrue(registry.providerByName('MyTestProviderKey'))
|
||||
self.assertTrue(registry.providerByName('MyName'))
|
||||
|
||||
# Get not existent by name
|
||||
self.assertFalse(registry.providerByName('Oh This Is Missing!'))
|
||||
|
||||
# Get providers by data provider key
|
||||
self.assertGreater(len(registry.providersByKey('MyTestProviderKey')), 0)
|
||||
self.assertGreater(len(registry.providersByKey('MyTestProviderKey2')), 0)
|
||||
|
||||
# Get not existent by key
|
||||
self.assertEqual(len(registry.providersByKey('Oh This Is Missing!')), 0)
|
||||
|
||||
def testRemoveProvider(self):
|
||||
registry = QgsSourceSelectProviderRegistry()
|
||||
registry.addProvider(ConcreteSourceSelectProvider())
|
||||
registry.addProvider(ConcreteSourceSelectProvider2())
|
||||
self.assertEqual(['MyTestProviderKey', 'MyName'], [p.name() for p in registry.providers() if p.providerKey().startswith('MyTestProviderKey')])
|
||||
|
||||
self.assertTrue(registry.removeProvider(registry.providerByName('MyName')))
|
||||
self.assertEqual(['MyTestProviderKey'], [p.name() for p in registry.providers() if p.providerKey().startswith('MyTestProviderKey')])
|
||||
|
||||
self.assertTrue(registry.removeProvider(registry.providerByName('MyTestProviderKey')))
|
||||
self.assertEqual([], [p.name() for p in registry.providers() if p.providerKey().startswith('MyTestProviderKey')])
|
||||
|
||||
def testRegistry(self):
|
||||
registry = QgsSourceSelectProviderRegistry()
|
||||
self._testRegistry(registry)
|
||||
|
||||
def testRegistrySingleton(self):
|
||||
registry = QgsGui.sourceSelectProviderRegistry()
|
||||
self._testRegistry(registry)
|
||||
# Check that at least OGR and GDAL are here
|
||||
self.assertTrue(registry.providersByKey('ogr'))
|
||||
self.assertTrue(registry.providersByKey('gdal'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user