Skip to content
Permalink
Browse files

Add API to allow creation of widgets for customising a layer's source

This adds api in the provider gui to allow a provider to create a custom
widget which exposes options to customise and change the layer's source.

E.g. a file based layer provider could expose a widget for selecting
a new file path, and an online one could expose widgets for changing
the host, authentication, etc.
  • Loading branch information
nyalldawson committed Dec 25, 2020
1 parent 0dc0ca5 commit d5c3b4b8a5d15682a20b0e2c0e6428e2e0a3c9c9
@@ -122,6 +122,13 @@ Returns the registry of GUI-related components of data providers
%Docstring
Returns the registry of subset string editors of data providers

.. versionadded:: 3.18
%End

static QgsProviderSourceWidgetProviderRegistry *sourceWidgetProviderRegistry() /KeepReference/;
%Docstring
Returns the registry of provider source widget providers.

.. versionadded:: 3.18
%End

@@ -70,7 +70,18 @@ Returns subset string editor providers

.. note::

Ownership of created providers is passed to the caller.
Ownership of created providers is passed to the caller.

.. versionadded:: 3.18
%End

virtual QList<QgsProviderSourceWidgetProvider *> sourceWidgetProviders() /Factory/;
%Docstring
Returns source widget providers

.. note::

Ownership of created providers is passed to the caller.

.. versionadded:: 3.18
%End
@@ -85,6 +85,17 @@ Returns all project storage gui providers registered in provider with ``provider
%Docstring
Returns all subset string editor providers registered in provider with ``providerKey``

.. note::

Ownership of providers is passed to the caller.

.. versionadded:: 3.18
%End

virtual QList<QgsProviderSourceWidgetProvider *> sourceWidgetProviders( const QString &providerKey ) /Factory/;
%Docstring
Returns all source widget providers registered in provider with ``providerKey``

.. note::

Ownership of providers is passed to the caller.
@@ -0,0 +1,50 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsprovidersourcewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsProviderSourceWidget : QWidget
{
%Docstring
Base class for widgets which allow customisation of a provider's source URI.

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgsprovidersourcewidget.h"
%End
public:

QgsProviderSourceWidget( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsProviderSourceWidget with the specified ``parent`` widget.
%End

virtual void setSourceUri( const QString &uri ) = 0;
%Docstring
Sets the source ``uri`` to show in the widget.

.. seealso:: :py:func:`sourceUri`
%End

virtual QString sourceUri() const = 0;
%Docstring
Returns the source URI as currently defined by the widget.

.. seealso:: :py:func:`setSourceUri`
%End

};
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsprovidersourcewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,61 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsprovidersourcewidgetprovider.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsProviderSourceWidgetProvider
{
%Docstring

An interface for providers of widgets designed to configure a data provider's source.

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgsprovidersourcewidgetprovider.h"
%End
public:

virtual ~QgsProviderSourceWidgetProvider();

virtual QString providerKey() const = 0;
%Docstring
Provider key
%End

virtual QString name() const;
%Docstring
Source widget provider name, this is useful to retrieve
a particular source widget provider in case the provider has more
than one, it should be unique among all providers.

The default implementation returns the :py:func:`~QgsProviderSourceWidgetProvider.providerKey`
%End

virtual bool canHandleLayer( QgsMapLayer *layer ) const = 0;
%Docstring
Returns ``True`` if the provider can handle the specified ``layer``.
%End

virtual QgsProviderSourceWidget *createWidget( QgsMapLayer *layer, QWidget *parent /TransferThis/ = 0 ) = 0 /Factory/;
%Docstring
Creates a new widget to configure the source of the specified ``layer``.
It may return ``None`` if it cannot handle the layer.
The returned object must be destroyed by the caller.
%End
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsprovidersourcewidgetprovider.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,83 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsprovidersourcewidgetproviderregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsProviderSourceWidgetProviderRegistry
{
%Docstring
This class keeps a list of provider source widget providers.

QgsProviderSourceWidgetProviderRegistry is not usually directly created, but rather accessed through
QgsGui.QgsProviderSourceWidgetProviderRegistry().

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgsprovidersourcewidgetproviderregistry.h"
%End
public:

QgsProviderSourceWidgetProviderRegistry();
~QgsProviderSourceWidgetProviderRegistry();


QList< QgsProviderSourceWidgetProvider *> providers();
%Docstring
Gets list of available providers
%End

void addProvider( QgsProviderSourceWidgetProvider *provider /Transfer/ );
%Docstring
Add a ``provider`` implementation. Takes ownership of the object.
%End

bool removeProvider( QgsProviderSourceWidgetProvider *provider /Transfer/ );
%Docstring
Remove ``provider`` implementation from the list (``provider`` object is deleted)

:return: ``True`` if the provider was actually removed and deleted
%End

void initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry );
%Docstring
Initializes the registry. The registry needs to be passed explicitly
(instead of using singleton) because this gets called from QgsGui constructor.
%End

QgsProviderSourceWidgetProvider *providerByName( const QString &name );
%Docstring
Returns a provider by ``name`` or ``None`` if not found
%End

QList<QgsProviderSourceWidgetProvider *> providersByKey( const QString &providerKey );
%Docstring
Returns a (possibly empty) list of providers by data ``providerkey``
%End

QgsProviderSourceWidget *createWidget( QgsMapLayer *layer, QWidget *parent /TransferThis/ = 0 ) /TransferBack/;
%Docstring
Creates a new widget to configure the source of the specified ``layer``.
It may return ``None`` if no provider was found.
The returned object must be destroyed by the caller.
%End

private:
QgsProviderSourceWidgetProviderRegistry( const QgsProviderSourceWidgetProviderRegistry &rh );
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsprovidersourcewidgetproviderregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -170,6 +170,9 @@
%Include auto_generated/qgsproviderconnectioncombobox.sip
%Include auto_generated/qgsproviderguimetadata.sip
%Include auto_generated/qgsproviderguiregistry.sip
%Include auto_generated/qgsprovidersourcewidget.sip
%Include auto_generated/qgsprovidersourcewidgetprovider.sip
%Include auto_generated/qgsprovidersourcewidgetproviderregistry.sip
%Include auto_generated/qgsproxystyle.sip
%Include auto_generated/qgsquerybuilder.sip
%Include auto_generated/qgsrangeslider.sip
@@ -552,6 +552,9 @@ set(QGIS_GUI_SRCS
qgspropertyoverridebutton.cpp
qgsproviderguiregistry.cpp
qgsproviderguimetadata.cpp
qgsprovidersourcewidget.cpp
qgsprovidersourcewidgetprovider.cpp
qgsprovidersourcewidgetproviderregistry.cpp
qgsprojectstorageguiregistry.cpp
qgsproviderconnectioncombobox.cpp
qgsproxystyle.cpp
@@ -796,6 +799,9 @@ set(QGIS_GUI_HDRS
qgsproviderconnectioncombobox.h
qgsproviderguimetadata.h
qgsproviderguiregistry.h
qgsprovidersourcewidget.h
qgsprovidersourcewidgetprovider.h
qgsprovidersourcewidgetproviderregistry.h
qgsproxystyle.h
qgsquerybuilder.h
qgsrangeslider.h
@@ -59,6 +59,7 @@
#include "qgsnumericformatguiregistry.h"
#include "qgscodeeditorcolorschemeregistry.h"
#include "qgssubsetstringeditorproviderregistry.h"
#include "qgsprovidersourcewidgetproviderregistry.h"

QgsGui *QgsGui::instance()
{
@@ -86,6 +87,11 @@ QgsSubsetStringEditorProviderRegistry *QgsGui::subsetStringEditorProviderRegistr
return instance()->mSubsetStringEditorProviderRegistry;
}

QgsProviderSourceWidgetProviderRegistry *QgsGui::sourceWidgetProviderRegistry()
{
return instance()->mProviderSourceWidgetProviderRegistry;
}

QgsShortcutsManager *QgsGui::shortcutsManager()
{
return instance()->mShortcutsManager;
@@ -191,6 +197,7 @@ QgsGui::~QgsGui()
delete mProviderGuiRegistry;
delete mCodeEditorColorSchemeRegistry;
delete mSubsetStringEditorProviderRegistry;
delete mProviderSourceWidgetProviderRegistry;
}

QColor QgsGui::sampleColor( QPoint point )
@@ -245,11 +252,13 @@ QgsGui::QgsGui()
mSourceSelectProviderRegistry = new QgsSourceSelectProviderRegistry();
mNumericFormatGuiRegistry = new QgsNumericFormatGuiRegistry();
mSubsetStringEditorProviderRegistry = new QgsSubsetStringEditorProviderRegistry();
mProviderSourceWidgetProviderRegistry = new QgsProviderSourceWidgetProviderRegistry();

mProjectStorageGuiRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry );
mDataItemGuiProviderRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry );
mSourceSelectProviderRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry );
mSubsetStringEditorProviderRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry );
mProviderSourceWidgetProviderRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry );

mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
mShortcutsManager = new QgsShortcutsManager();
@@ -41,6 +41,7 @@ class QgsNumericFormatGuiRegistry;
class QgsCodeEditorColorSchemeRegistry;
class QgsMessageBar;
class QgsSubsetStringEditorProviderRegistry;
class QgsProviderSourceWidgetProviderRegistry;

/**
* \ingroup gui
@@ -161,6 +162,12 @@ class GUI_EXPORT QgsGui : public QObject
*/
static QgsSubsetStringEditorProviderRegistry *subsetStringEditorProviderRegistry() SIP_KEEPREFERENCE;

/**
* Returns the registry of provider source widget providers.
* \since QGIS 3.18
*/
static QgsProviderSourceWidgetProviderRegistry *sourceWidgetProviderRegistry() SIP_KEEPREFERENCE;

/**
* Register the widget to allow its position to be automatically saved and restored when open and closed.
* Use this to avoid needing to call saveGeometry() and restoreGeometry() on your widget.
@@ -263,6 +270,7 @@ class GUI_EXPORT QgsGui : public QObject
QgsCodeEditorColorSchemeRegistry *mCodeEditorColorSchemeRegistry = nullptr;
QgsProjectStorageGuiRegistry *mProjectStorageGuiRegistry = nullptr;
QgsSubsetStringEditorProviderRegistry *mSubsetStringEditorProviderRegistry = nullptr;
QgsProviderSourceWidgetProviderRegistry *mProviderSourceWidgetProviderRegistry = nullptr;
std::unique_ptr< QgsWindowManagerInterface > mWindowManager;

#ifdef SIP_RUN
@@ -47,6 +47,11 @@ QList<QgsSubsetStringEditorProvider *> QgsProviderGuiMetadata::subsetStringEdito
return QList<QgsSubsetStringEditorProvider *>();
}

QList<QgsProviderSourceWidgetProvider *> QgsProviderGuiMetadata::sourceWidgetProviders()
{
return QList<QgsProviderSourceWidgetProvider *>();
}

QString QgsProviderGuiMetadata::key() const
{
return mKey;
@@ -28,6 +28,7 @@ class QgsDataItemGuiProvider;
class QgsSourceSelectProvider;
class QgsProjectStorageGuiProvider;
class QgsSubsetStringEditorProvider;
class QgsProviderSourceWidgetProvider;

/**
* \ingroup gui
@@ -72,11 +73,18 @@ class GUI_EXPORT QgsProviderGuiMetadata

/**
* Returns subset string editor providers
* \note Ownership of created providers is passed to the caller.
* \note Ownership of created providers is passed to the caller.
* \since QGIS 3.18
*/
virtual QList<QgsSubsetStringEditorProvider *> subsetStringEditorProviders() SIP_FACTORY;

/**
* Returns source widget providers
* \note Ownership of created providers is passed to the caller.
* \since QGIS 3.18
*/
virtual QList<QgsProviderSourceWidgetProvider *> sourceWidgetProviders() SIP_FACTORY;

//! Returns unique provider key
QString key() const;

0 comments on commit d5c3b4b

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