Skip to content
Permalink
Browse files

[FEATURE] Add a subset string editor provider concept and registry

The aim of this work is to be able to provide custom subset string editor
GUI according to the layer. Typically, so that a WFS layer uses the same
editor than in its select source, or that a plugin can provide a custom
editor.

* Add QgsSubsetStringEditorInterface: abstract interface to define a dialog
  that can edit a subset string
* Make QgsQueryBuilder implement QgsSubsetStringEditorInterface
* Add QgsSubsetStringEditorProvider: interface for thos who want to provide
  a dialog to edit a subset string.
* Add QgsSubsetStringEditorProviderRegistry: keeps a list of subset string
  editor providers. Transposed from QgsDataItemGuiProviderRegistry
* Add QgsGui::subsetStringEditorProviderRegistry()
  • Loading branch information
rouault authored and nyalldawson committed Nov 16, 2020
1 parent e55107f commit 24eb319af201acf8571d6714b1023b61f9370747
@@ -116,6 +116,13 @@ Returns the global GUI-related project storage registry
Returns the registry of GUI-related components of data providers

.. versionadded:: 3.10
%End

static QgsSubsetStringEditorProviderRegistry *subsetStringEditorProviderRegistry() /KeepReference/;
%Docstring
Returns the registry of subset string editors of data providers

.. versionadded:: 3.18
%End

static void enableAutoGeometryRestore( QWidget *widget, const QString &key = QString() );
@@ -64,6 +64,17 @@ Returns source select providers
Ownership of created source select providers is passed to the caller.
%End

virtual QList<QgsSubsetStringEditorProvider *> subsetStringEditorProviders() /Factory/;
%Docstring
Returns subset string editor providers

.. note::

Ownership of created providers is passed to the caller.

.. versionadded:: 3.18
%End

QString key() const;
%Docstring
Returns unique provider key
@@ -81,6 +81,17 @@ Returns all project storage gui providers registered in provider with ``provider
Ownership of created project storage gui providers is passed to the caller.
%End

virtual QList<QgsSubsetStringEditorProvider *> subsetStringEditorProviders( const QString &providerKey ) /Factory/;
%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


};

@@ -7,7 +7,7 @@
************************************************************************/


class QgsQueryBuilder : QDialog
class QgsQueryBuilder : QgsSubsetStringEditorInterface
{
%Docstring
Query Builder for layers.
@@ -38,9 +38,12 @@ vector layer properties dialog
virtual void showEvent( QShowEvent *event );


QString sql();
QString sql() const;
void setSql( const QString &sqlStatement );

virtual QString subsetString() const;
virtual void setSubsetString( const QString &subsetString );

%If (HAVE_QSCI_SIP)

QgsCodeEditor *codeEditorWidget() const;
@@ -0,0 +1,46 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgssubsetstringeditorinterface.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsSubsetStringEditorInterface: QDialog
{
%Docstring
Interface for a dialog that can edit subset strings

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgssubsetstringeditorinterface.h"
%End
public:
QgsSubsetStringEditorInterface( QWidget *parent /TransferThis/ = 0,
Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
%Docstring
Constructor
%End

virtual QString subsetString() const = 0;
%Docstring
Returns the subset string entered in the dialog.
%End

virtual void setSubsetString( const QString &subsetString ) = 0;
%Docstring
Sets a subset string into the dialog.
%End
};

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




class QgsSubsetStringEditorProvider
{
%Docstring
This is the interface for those who want to provide a dialog to edit a
subset string.

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgssubsetstringeditorprovider.h"
%End
public:
virtual ~QgsSubsetStringEditorProvider();

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

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

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

virtual bool canHandleLayer( QgsVectorLayer *layer ) const = 0;
%Docstring
Returns true if the provider can handle the layer
%End

virtual bool canHandleLayerStorageType( QgsVectorLayer *layer ) const;
%Docstring
Returns true if the provider can handle specifically the
layer->:py:func:`~QgsSubsetStringEditorProvider.provider`->:py:func:`~QgsSubsetStringEditorProvider.storageType`
This method will only be called if :py:func:`~QgsSubsetStringEditorProvider.canHandleLayer` returned true.
Typically a generic SQL provider for the OGR provider will return false,
whereas a dedicated plugin with a specific behavior for a OGR driver
will return true.
%End

virtual QgsSubsetStringEditorInterface *createDialog( QgsVectorLayer *layer, QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags ) = 0 /Factory/;
%Docstring
Creates a new dialog to edit the subset string of the provided ``layer``.
It may return None if it cannot handle the layer.
The returned object must be destroyed by the caller.
On successful :py:func:`~QgsSubsetStringEditorProvider.accept`, the QgsSubsetStringEditorInterface implementation
is responsible for setting the updated string on layer.
%End
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgssubsetstringeditorprovider.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/qgssubsetstringeditorproviderregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsSubsetStringEditorProviderRegistry
{
%Docstring
This class keeps a list of subset string editor providers.

QgsSubsetStringEditorProviderRegistry is not usually directly created, but rather accessed through
:py:func:`QgsGui.subsetStringEditorProvideRegistry()`.

.. versionadded:: 3.18
%End

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

QgsSubsetStringEditorProviderRegistry();
~QgsSubsetStringEditorProviderRegistry();


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

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

bool removeProvider( QgsSubsetStringEditorProvider *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

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

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

QgsSubsetStringEditorInterface *createDialog( QgsVectorLayer *layer, QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags ) /TransferBack/;
%Docstring
Creates a new dialog to edit the subset string of the provided ``layer``.
It will default to returning a :py:class:`QgsQueryBuilder`* if no provider was found.
The returned object must be destroyed by the caller.
%End

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

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgssubsetstringeditorproviderregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -183,6 +183,9 @@
%Include auto_generated/qgsscalewidget.sip
%Include auto_generated/qgsscrollarea.sip
%Include auto_generated/qgssearchquerybuilder.sip
%Include auto_generated/qgssubsetstringeditorinterface.sip
%Include auto_generated/qgssubsetstringeditorprovider.sip
%Include auto_generated/qgssubsetstringeditorproviderregistry.sip
%Include auto_generated/qgsshortcutsmanager.sip
%Include auto_generated/qgsslider.sip
%Include auto_generated/qgssnapindicator.sip
@@ -558,6 +558,9 @@ set(QGIS_GUI_SRCS
qgsscalewidget.cpp
qgsscrollarea.cpp
qgssearchquerybuilder.cpp
qgssubsetstringeditorinterface.cpp
qgssubsetstringeditorprovider.cpp
qgssubsetstringeditorproviderregistry.cpp
qgsshortcutsmanager.cpp
qgsslider.cpp
qgssnapindicator.cpp
@@ -796,6 +799,9 @@ set(QGIS_GUI_HDRS
qgsscalewidget.h
qgsscrollarea.h
qgssearchquerybuilder.h
qgssubsetstringeditorinterface.h
qgssubsetstringeditorprovider.h
qgssubsetstringeditorproviderregistry.h
qgsshortcutsmanager.h
qgsslider.h
qgssnapindicator.h
@@ -58,7 +58,7 @@
#include "qgsmessagebaritem.h"
#include "qgsnumericformatguiregistry.h"
#include "qgscodeeditorcolorschemeregistry.h"

#include "qgssubsetstringeditorproviderregistry.h"

QgsGui *QgsGui::instance()
{
@@ -81,6 +81,11 @@ QgsSourceSelectProviderRegistry *QgsGui::sourceSelectProviderRegistry()
return instance()->mSourceSelectProviderRegistry;
}

QgsSubsetStringEditorProviderRegistry *QgsGui::subsetStringEditorProviderRegistry()
{
return instance()->mSubsetStringEditorProviderRegistry;
}

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

QColor QgsGui::sampleColor( QPoint point )
@@ -238,10 +244,12 @@ QgsGui::QgsGui()
mDataItemGuiProviderRegistry = new QgsDataItemGuiProviderRegistry();
mSourceSelectProviderRegistry = new QgsSourceSelectProviderRegistry();
mNumericFormatGuiRegistry = new QgsNumericFormatGuiRegistry();
mSubsetStringEditorProviderRegistry = new QgsSubsetStringEditorProviderRegistry();

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

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

/**
* \ingroup gui
@@ -154,6 +155,12 @@ class GUI_EXPORT QgsGui : public QObject
*/
static QgsProviderGuiRegistry *providerGuiRegistry() SIP_KEEPREFERENCE;

/**
* Returns the registry of subset string editors of data providers
* \since QGIS 3.18
*/
static QgsSubsetStringEditorProviderRegistry *subsetStringEditorProviderRegistry() 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.
@@ -255,6 +262,7 @@ class GUI_EXPORT QgsGui : public QObject
QgsDataItemGuiProviderRegistry *mDataItemGuiProviderRegistry = nullptr;
QgsCodeEditorColorSchemeRegistry *mCodeEditorColorSchemeRegistry = nullptr;
QgsProjectStorageGuiRegistry *mProjectStorageGuiRegistry = nullptr;
QgsSubsetStringEditorProviderRegistry *mSubsetStringEditorProviderRegistry = nullptr;
std::unique_ptr< QgsWindowManagerInterface > mWindowManager;

#ifdef SIP_RUN
@@ -42,6 +42,11 @@ QList<QgsSourceSelectProvider *> QgsProviderGuiMetadata::sourceSelectProviders()
return QList<QgsSourceSelectProvider *>();
}

QList<QgsSubsetStringEditorProvider *> QgsProviderGuiMetadata::subsetStringEditorProviders()
{
return QList<QgsSubsetStringEditorProvider *>();
}

QString QgsProviderGuiMetadata::key() const
{
return mKey;

0 comments on commit 24eb319

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