Skip to content

Commit

Permalink
move QgsSettingsEditorWidgetWrapper to core + allow to specify a spec…
Browse files Browse the repository at this point in the history
…ific editor for a setting
  • Loading branch information
3nids committed Oct 8, 2024
1 parent 553e077 commit 440d1e7
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 22 deletions.
10 changes: 9 additions & 1 deletion python/PyQt6/core/additions/qgssettingsentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def __init__(self, key, pluginName, defaultValue, description=str(), options=Qgi
parent = pluginName
super().__init__(key, parent, defaultValueStr, description, options)

def metaEnum(self):
return self.__metaEnum

def typeId(self):
"""
Defines a custom id since this class has not the same API as the cpp implementation
"""
return "py-enumflag"

def value(self, dynamicKeyPart=None):
"""
Get settings value.
Expand Down Expand Up @@ -138,5 +147,4 @@ def settingsType(self):
"""
Get the settings entry type.
"""

return self.SettingsType.EnumFlag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The following has been generated automatically from src/gui/settings/qgssettingseditorwidgetwrapper.h
# The following has been generated automatically from src/core/settings/qgssettingseditorwidgetwrapper.h
try:
QgsSettingsEditorWidgetWrapper.fromWidget = staticmethod(QgsSettingsEditorWidgetWrapper.fromWidget)
QgsSettingsEditorWidgetWrapper.__group__ = ['settings']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/settings/qgssettingseditorwidgetwrapper.h *
* src/core/settings/qgssettingseditorwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
Expand Down Expand Up @@ -98,6 +98,13 @@ If not, the setting will be updated directly at each widget value change.
%End


QStringList dynamicKeyPartList() const;
%Docstring
Returns the dynamic key parts

.. versionadded:: 3.40
%End

protected:
virtual QWidget *createEditorPrivate( QWidget *parent = 0 ) const = 0;
%Docstring
Expand All @@ -124,7 +131,7 @@ value is changed.
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/settings/qgssettingseditorwidgetwrapper.h *
* src/core/settings/qgssettingseditorwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
18 changes: 18 additions & 0 deletions python/PyQt6/core/auto_generated/settings/qgssettingsentry.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,24 @@ Returns ``True`` if the given ``value`` is valid towards the setting definition
Returns ``True`` if the setting was changed during the current QGIS session.

.. versionadded:: 3.36
%End

void setEditorWidgetWrapper( QgsSettingsEditorWidgetWrapper *editorWrapper /Transfer/ );
%Docstring
Sets an editor widget wrapper for the setting
Normally, editor widgets are automatically determined and build using :py:class:`QgsSettingsEditorWidgetRegistry`.
This might be useful for plugins to define a custom implementation.

.. versionadded:: 3.40
%End

QgsSettingsEditorWidgetWrapper *editorWidgetWrapper() const;
%Docstring
Returns the editor widget wrapper for the setting
Normally, editor widgets are automatically determined and build using :py:class:`QgsSettingsEditorWidgetRegistry` and
this method will then return a null pointer.

.. versionadded:: 3.40
%End

};
Expand Down
1 change: 1 addition & 0 deletions python/PyQt6/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@
%Include auto_generated/sensor/qgsabstractsensor.sip
%Include auto_generated/sensor/qgsiodevicesensor.sip
%Include auto_generated/settings/qgssettings.sip
%Include auto_generated/settings/qgssettingseditorwidgetwrapper.sip
%Include auto_generated/settings/qgssettingsentry.sip
%Include auto_generated/settings/qgssettingsentrygroup.sip
%Include auto_generated/settings/qgssettingsentryimpl.sip
Expand Down
1 change: 0 additions & 1 deletion python/PyQt6/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@
%Include auto_generated/symbology/qgsvectorfieldsymbollayerwidget.sip
%Include auto_generated/sensor/qgssensorguiregistry.sip
%Include auto_generated/sensor/qgssensorwidget.sip
%Include auto_generated/settings/qgssettingseditorwidgetwrapper.sip
%Include auto_generated/settings/qgssettingseditorwidgetwrapperimpl.sip
%Include auto_generated/settings/qgssettingseditorwidgetregistry.sip
%Include auto_generated/settings/qgssettingsregistrygui.sip
Expand Down
15 changes: 9 additions & 6 deletions python/core/additions/qgssettingsentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def __init__(self, key, pluginName, defaultValue, description=str(), options=Qgi
parent = pluginName
super().__init__(key, parent, defaultValueStr, description, options)

def metaEnum(self):
return self.__metaEnum

def typeId(self):
"""
Defines a custom id since this class has not the same API as the cpp implementation
"""
return "py-enumflag"

def value(self, dynamicKeyPart=None):
"""
Get settings value.
Expand Down Expand Up @@ -139,9 +148,3 @@ def settingsType(self):
Get the settings entry type.
"""
return self.SettingsType.EnumFlag

def typeId(self):
"""
Defines a custom id since this class has not the same API as the cpp implementation
"""
return "py-enum"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The following has been generated automatically from src/gui/settings/qgssettingseditorwidgetwrapper.h
# The following has been generated automatically from src/core/settings/qgssettingseditorwidgetwrapper.h
try:
QgsSettingsEditorWidgetWrapper.fromWidget = staticmethod(QgsSettingsEditorWidgetWrapper.fromWidget)
QgsSettingsEditorWidgetWrapper.__group__ = ['settings']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/settings/qgssettingseditorwidgetwrapper.h *
* src/core/settings/qgssettingseditorwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
Expand Down Expand Up @@ -98,6 +98,13 @@ If not, the setting will be updated directly at each widget value change.
%End


QStringList dynamicKeyPartList() const;
%Docstring
Returns the dynamic key parts

.. versionadded:: 3.40
%End

protected:
virtual QWidget *createEditorPrivate( QWidget *parent = 0 ) const = 0;
%Docstring
Expand All @@ -124,7 +131,7 @@ value is changed.
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/settings/qgssettingseditorwidgetwrapper.h *
* src/core/settings/qgssettingseditorwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
18 changes: 18 additions & 0 deletions python/core/auto_generated/settings/qgssettingsentry.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,24 @@ Returns ``True`` if the given ``value`` is valid towards the setting definition
Returns ``True`` if the setting was changed during the current QGIS session.

.. versionadded:: 3.36
%End

void setEditorWidgetWrapper( QgsSettingsEditorWidgetWrapper *editorWrapper /Transfer/ );
%Docstring
Sets an editor widget wrapper for the setting
Normally, editor widgets are automatically determined and build using :py:class:`QgsSettingsEditorWidgetRegistry`.
This might be useful for plugins to define a custom implementation.

.. versionadded:: 3.40
%End

QgsSettingsEditorWidgetWrapper *editorWidgetWrapper() const;
%Docstring
Returns the editor widget wrapper for the setting
Normally, editor widgets are automatically determined and build using :py:class:`QgsSettingsEditorWidgetRegistry` and
this method will then return a null pointer.

.. versionadded:: 3.40
%End

};
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@
%Include auto_generated/sensor/qgsabstractsensor.sip
%Include auto_generated/sensor/qgsiodevicesensor.sip
%Include auto_generated/settings/qgssettings.sip
%Include auto_generated/settings/qgssettingseditorwidgetwrapper.sip
%Include auto_generated/settings/qgssettingsentry.sip
%Include auto_generated/settings/qgssettingsentrygroup.sip
%Include auto_generated/settings/qgssettingsentryimpl.sip
Expand Down
3 changes: 2 additions & 1 deletion python/gui/__init__.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ __copyright__ = '(C) 2014, Nathan Woodrow'

from qgis.PyQt import QtCore
from qgis._gui import *
from qgis.core import Qgis as _Qgis
from qgis.core import Qgis as _Qgis, QgsSettingsEditorWidgetWrapper as _QgsSettingsEditorWidgetWrapper

@MONKEYPATCH_INJECTIONS@

Expand Down Expand Up @@ -78,6 +78,7 @@ QgsMapLayerAction.EnabledOnlyWhenEditable.__doc__ = "Action should be shown only
QgsMapLayerAction.Flags = _Qgis.MapLayerActionFlags

# monkey patch old settings wrappers
QgsSettingsEditorWidgetWrapper = _QgsSettingsEditorWidgetWrapper # moved from gui to core
QgsSettingsStringEditorWidgetWrapper = QgsSettingsStringLineEditWrapper
QgsSettingsBoolEditorWidgetWrapper = QgsSettingsBoolCheckBoxWrapper
QgsSettingsIntegerEditorWidgetWrapper = QgsSettingsIntegerSpinBoxWrapper
Expand Down
1 change: 0 additions & 1 deletion python/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@
%Include auto_generated/symbology/qgsvectorfieldsymbollayerwidget.sip
%Include auto_generated/sensor/qgssensorguiregistry.sip
%Include auto_generated/sensor/qgssensorwidget.sip
%Include auto_generated/settings/qgssettingseditorwidgetwrapper.sip
%Include auto_generated/settings/qgssettingseditorwidgetwrapperimpl.sip
%Include auto_generated/settings/qgssettingseditorwidgetregistry.sip
%Include auto_generated/settings/qgssettingsregistrygui.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ set(QGIS_CORE_SRCS
fieldformatter/qgsvaluerelationfieldformatter.cpp

settings/qgssettings.cpp
settings/qgssettingseditorwidgetwrapper.cpp
settings/qgssettingsentry.cpp
settings/qgssettingsentrygroup.cpp
settings/qgssettingsentryimpl.cpp
Expand Down Expand Up @@ -2036,6 +2037,7 @@ set(QGIS_CORE_HDRS
sensor/qgsiodevicesensor.h

settings/qgssettings.h
settings/qgssettingseditorwidgetwrapper.h
settings/qgssettingsentry.h
settings/qgssettingsentrygroup.h
settings/qgssettingsentryenumflag.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
#include <QVariant>

#include "qgis_sip.h"
#include "qgis_gui.h"
#include "qgis_core.h"

class QgsSettingsEntryBase;

class QDialog;

/**
* \ingroup gui
* \ingroup core
* \brief Base class for settings editor wrappers
*
* \since QGIS 3.32
*/
class GUI_EXPORT QgsSettingsEditorWidgetWrapper : public QObject
class CORE_EXPORT QgsSettingsEditorWidgetWrapper : public QObject
{
Q_OBJECT
public:
Expand Down Expand Up @@ -95,6 +95,12 @@ class GUI_EXPORT QgsSettingsEditorWidgetWrapper : public QObject
void configureAutomaticUpdate( QDialog *dialog = nullptr );


/**
* Returns the dynamic key parts
* \since QGIS 3.40
*/
QStringList dynamicKeyPartList() const {return mDynamicKeyPartList;}

protected:
//! Creates the widgets
virtual QWidget *createEditorPrivate( QWidget *parent = nullptr ) const = 0;
Expand Down
18 changes: 18 additions & 0 deletions src/core/settings/qgssettingsentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


class QgsSettingsTreeNode;
class QgsSettingsEditorWidgetWrapper;


static const inline QMetaEnum sSettingsTypeMetaEnum = QMetaEnum::fromType<Qgis::SettingsType>() SIP_SKIP;
Expand Down Expand Up @@ -352,6 +353,22 @@ class CORE_EXPORT QgsSettingsEntryBase
*/
bool hasChanged() const { return mHasChanged; }

/**
* Sets an editor widget wrapper for the setting
* Normally, editor widgets are automatically determined and build using QgsSettingsEditorWidgetRegistry.
* This might be useful for plugins to define a custom implementation.
* \since QGIS 3.40
*/
void setEditorWidgetWrapper( QgsSettingsEditorWidgetWrapper *editorWrapper SIP_TRANSFER ) {mEditorWrapper = editorWrapper; }

/**
* Returns the editor widget wrapper for the setting
* Normally, editor widgets are automatically determined and build using QgsSettingsEditorWidgetRegistry and
* this method will then return a null pointer.
* \since QGIS 3.40
*/
QgsSettingsEditorWidgetWrapper *editorWidgetWrapper() const {return mEditorWrapper;}

private:
QString formerValuekey( const QStringList &dynamicKeyPartList ) const;

Expand All @@ -364,6 +381,7 @@ class CORE_EXPORT QgsSettingsEntryBase
QString mDescription;
Qgis::SettingsOptions mOptions;
mutable bool mHasChanged = false;
QgsSettingsEditorWidgetWrapper *mEditorWrapper = nullptr;
};

/**
Expand Down
2 changes: 0 additions & 2 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ set(QGIS_GUI_SRCS
sensor/qgssensorguiregistry.cpp
sensor/qgssensorwidget.cpp

settings/qgssettingseditorwidgetwrapper.cpp
settings/qgssettingseditorwidgetwrapperimpl.cpp
settings/qgssettingseditorwidgetregistry.cpp
settings/qgssettingsregistrygui.cpp
Expand Down Expand Up @@ -1552,7 +1551,6 @@ set(QGIS_GUI_HDRS
sensor/qgssensorguiregistry.h
sensor/qgssensorwidget.h

settings/qgssettingseditorwidgetwrapper.h
settings/qgssettingseditorwidgetwrapperimpl.h
settings/qgssettingsenumflageditorwidgetwrapper.h
settings/qgssettingseditorwidgetregistry.h
Expand Down
5 changes: 4 additions & 1 deletion src/gui/settings/qgssettingseditorwidgetregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ QgsSettingsEditorWidgetWrapper *QgsSettingsEditorWidgetRegistry::createWrapper(

QWidget *QgsSettingsEditorWidgetRegistry::createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent ) const
{
QgsSettingsEditorWidgetWrapper *eww = createWrapper( setting->typeId(), parent );

QgsSettingsEditorWidgetWrapper *eww = setting->editorWidgetWrapper();
if ( !eww )
eww = createWrapper( setting->typeId(), parent );
if ( eww )
return eww->createEditor( setting, dynamicKeyPartList, parent );
else
Expand Down

0 comments on commit 440d1e7

Please sign in to comment.