From fe0ab98ee02caaaed1bfa3df80e6f373acbd7e57 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 24 Nov 2022 08:28:19 +1000 Subject: [PATCH] Manually monkey patch compatibility, since we can't auto patch to gui classes --- python/core/auto_additions/qgis.py | 37 ++++++-------------------- python/core/auto_generated/qgis.sip.in | 6 ++--- python/gui/__init__.py.in | 35 ++++++++++++++++++++++++ src/core/qgis.h | 16 +++++------ 4 files changed, 54 insertions(+), 40 deletions(-) diff --git a/python/core/auto_additions/qgis.py b/python/core/auto_additions/qgis.py index e5c7c832c4e..18348e5628a 100644 --- a/python/core/auto_additions/qgis.py +++ b/python/core/auto_additions/qgis.py @@ -2197,49 +2197,28 @@ Qgis.LayerTreeInsertionMethod.OptimalInInsertionGroup.__doc__ = "Layers are adde Qgis.LayerTreeInsertionMethod.__doc__ = 'Layer tree insertion methods\n\n.. versionadded:: 3.30\n\n' + '* ``AboveInsertionPoint``: ' + Qgis.LayerTreeInsertionMethod.AboveInsertionPoint.__doc__ + '\n' + '* ``TopOfTree``: ' + Qgis.LayerTreeInsertionMethod.TopOfTree.__doc__ + '\n' + '* ``OptimalInInsertionGroup``: ' + Qgis.LayerTreeInsertionMethod.OptimalInInsertionGroup.__doc__ # -- Qgis.LayerTreeInsertionMethod.baseClass = Qgis -QgsActionMenu.ActionType = Qgis.ActionType # monkey patching scoped based enum -QgsActionMenu.Invalid = Qgis.ActionType.Invalid -QgsActionMenu.Invalid.is_monkey_patched = True -QgsActionMenu.Invalid.__doc__ = "Invalid" -QgsActionMenu.MapLayerAction = Qgis.ActionType.MapLayerAction -QgsActionMenu.MapLayerAction.is_monkey_patched = True -QgsActionMenu.MapLayerAction.__doc__ = "Standard actions (defined by core or plugins), corresponds to QgsMapLayerAction class." -QgsActionMenu.AttributeAction = Qgis.ActionType.AttributeAction -QgsActionMenu.AttributeAction.is_monkey_patched = True -QgsActionMenu.AttributeAction.__doc__ = "Custom actions (manually defined in layer properties), corresponds to QgsAction class." +Qgis.ActionType.Invalid.__doc__ = "Invalid" +Qgis.ActionType.MapLayerAction.__doc__ = "Standard actions (defined by core or plugins), corresponds to QgsMapLayerAction class." +Qgis.ActionType.AttributeAction.__doc__ = "Custom actions (manually defined in layer properties), corresponds to QgsAction class." Qgis.ActionType.__doc__ = 'Action types.\n\nPrior to QGIS 3.30 this was available as :py:class:`QgsActionMenu`.ActionType\n\n.. versionadded:: 3.30\n\n' + '* ``Invalid``: ' + Qgis.ActionType.Invalid.__doc__ + '\n' + '* ``MapLayerAction``: ' + Qgis.ActionType.MapLayerAction.__doc__ + '\n' + '* ``AttributeAction``: ' + Qgis.ActionType.AttributeAction.__doc__ # -- Qgis.ActionType.baseClass = Qgis -QgsMapLayerAction.Target = Qgis.MapLayerActionTarget # monkey patching scoped based enum -QgsMapLayerAction.Layer = Qgis.MapLayerActionTarget.Layer -QgsMapLayerAction.Layer.is_monkey_patched = True -QgsMapLayerAction.Layer.__doc__ = "Action targets a complete layer" -QgsMapLayerAction.SingleFeature = Qgis.MapLayerActionTarget.SingleFeature -QgsMapLayerAction.SingleFeature.is_monkey_patched = True -QgsMapLayerAction.SingleFeature.__doc__ = "Action targets a single feature from a layer" -QgsMapLayerAction.MultipleFeatures = Qgis.MapLayerActionTarget.MultipleFeatures -QgsMapLayerAction.MultipleFeatures.is_monkey_patched = True -QgsMapLayerAction.MultipleFeatures.__doc__ = "Action targets multiple features from a layer" -QgsMapLayerAction.AllActions = Qgis.MapLayerActionTarget.AllActions -QgsMapLayerAction.AllActions.is_monkey_patched = True -QgsMapLayerAction.AllActions.__doc__ = "" +Qgis.MapLayerActionTarget.Layer.__doc__ = "Action targets a complete layer" +Qgis.MapLayerActionTarget.SingleFeature.__doc__ = "Action targets a single feature from a layer" +Qgis.MapLayerActionTarget.MultipleFeatures.__doc__ = "Action targets multiple features from a layer" +Qgis.MapLayerActionTarget.AllActions.__doc__ = "" Qgis.MapLayerActionTarget.__doc__ = 'Map layer action targets.\n\nPrior to QGIS 3.30 this was available as :py:class:`QgsMapLayerAction`.Target\n\n.. versionadded:: 3.30\n\n' + '* ``Layer``: ' + Qgis.MapLayerActionTarget.Layer.__doc__ + '\n' + '* ``SingleFeature``: ' + Qgis.MapLayerActionTarget.SingleFeature.__doc__ + '\n' + '* ``MultipleFeatures``: ' + Qgis.MapLayerActionTarget.MultipleFeatures.__doc__ + '\n' + '* ``AllActions``: ' + Qgis.MapLayerActionTarget.AllActions.__doc__ # -- Qgis.MapLayerActionTarget.baseClass = Qgis -QgsMapLayerAction.Targets = Qgis.MapLayerActionTargets Qgis.MapLayerActionTargets.baseClass = Qgis MapLayerActionTargets = Qgis # dirty hack since SIP seems to introduce the flags in module -QgsMapLayerAction.Flag = Qgis.MapLayerActionFlag # monkey patching scoped based enum -QgsMapLayerAction.EnabledOnlyWhenEditable = Qgis.MapLayerActionFlag.EnabledOnlyWhenEditable -QgsMapLayerAction.EnabledOnlyWhenEditable.is_monkey_patched = True -QgsMapLayerAction.EnabledOnlyWhenEditable.__doc__ = "Action should be shown only for editable layers" +Qgis.MapLayerActionFlag.EnabledOnlyWhenEditable.__doc__ = "Action should be shown only for editable layers" Qgis.MapLayerActionFlag.__doc__ = 'Map layer action flags.\n\nPrior to QGIS 3.30 this was available as :py:class:`QgsMapLayerAction`.Flag\n\n.. versionadded:: 3.30\n\n' + '* ``EnabledOnlyWhenEditable``: ' + Qgis.MapLayerActionFlag.EnabledOnlyWhenEditable.__doc__ # -- Qgis.MapLayerActionFlag.baseClass = Qgis -QgsMapLayerAction.Flags = Qgis.MapLayerActionFlags Qgis.MapLayerActionFlags.baseClass = Qgis MapLayerActionFlags = Qgis # dirty hack since SIP seems to introduce the flags in module QgsAction.ActionType = Qgis.AttributeActionType diff --git a/python/core/auto_generated/qgis.sip.in b/python/core/auto_generated/qgis.sip.in index 8bf03ad4d35..e0ff39fba9f 100644 --- a/python/core/auto_generated/qgis.sip.in +++ b/python/core/auto_generated/qgis.sip.in @@ -1449,14 +1449,14 @@ The development version }; enum class ActionType - { + { Invalid, MapLayerAction, AttributeAction }; enum class MapLayerActionTarget - { + { Layer, SingleFeature, MultipleFeatures, @@ -1467,7 +1467,7 @@ The development version enum class MapLayerActionFlag - { + { EnabledOnlyWhenEditable, }; diff --git a/python/gui/__init__.py.in b/python/gui/__init__.py.in index 67c586697b3..acbe197441d 100644 --- a/python/gui/__init__.py.in +++ b/python/gui/__init__.py.in @@ -39,3 +39,38 @@ QgsMapToolCapture.Streaming.__doc__ = "Streaming points digitizing mode (points QgsMapToolCapture.Shape = Qgis.CaptureTechnique.Shape QgsMapToolCapture.Shape.is_monkey_patched = True QgsMapToolCapture.Shape.__doc__ = "Digitize shapes." + +QgsActionMenu.ActionType = Qgis.ActionType +# monkey patching scoped based enum +QgsActionMenu.Invalid = Qgis.ActionType.Invalid +QgsActionMenu.Invalid.is_monkey_patched = True +QgsActionMenu.Invalid.__doc__ = "Invalid" +QgsActionMenu.MapLayerAction = Qgis.ActionType.MapLayerAction +QgsActionMenu.MapLayerAction.is_monkey_patched = True +QgsActionMenu.MapLayerAction.__doc__ = "Standard actions (defined by core or plugins), corresponds to QgsMapLayerAction class." +QgsActionMenu.AttributeAction = Qgis.ActionType.AttributeAction +QgsActionMenu.AttributeAction.is_monkey_patched = True +QgsActionMenu.AttributeAction.__doc__ = "Custom actions (manually defined in layer properties), corresponds to QgsAction class." + +QgsMapLayerAction.Target = Qgis.MapLayerActionTarget +# monkey patching scoped based enum +QgsMapLayerAction.Layer = Qgis.MapLayerActionTarget.Layer +QgsMapLayerAction.Layer.is_monkey_patched = True +QgsMapLayerAction.Layer.__doc__ = "Action targets a complete layer" +QgsMapLayerAction.SingleFeature = Qgis.MapLayerActionTarget.SingleFeature +QgsMapLayerAction.SingleFeature.is_monkey_patched = True +QgsMapLayerAction.SingleFeature.__doc__ = "Action targets a single feature from a layer" +QgsMapLayerAction.MultipleFeatures = Qgis.MapLayerActionTarget.MultipleFeatures +QgsMapLayerAction.MultipleFeatures.is_monkey_patched = True +QgsMapLayerAction.MultipleFeatures.__doc__ = "Action targets multiple features from a layer" +QgsMapLayerAction.AllActions = Qgis.MapLayerActionTarget.AllActions +QgsMapLayerAction.AllActions.is_monkey_patched = True +QgsMapLayerAction.AllActions.__doc__ = "" +QgsMapLayerAction.Targets = Qgis.MapLayerActionTargets + +QgsMapLayerAction.Flag = Qgis.MapLayerActionFlag +# monkey patching scoped based enum +QgsMapLayerAction.EnabledOnlyWhenEditable = Qgis.MapLayerActionFlag.EnabledOnlyWhenEditable +QgsMapLayerAction.EnabledOnlyWhenEditable.is_monkey_patched = True +QgsMapLayerAction.EnabledOnlyWhenEditable.__doc__ = "Action should be shown only for editable layers" +QgsMapLayerAction.Flags = Qgis.MapLayerActionFlags diff --git a/src/core/qgis.h b/src/core/qgis.h index b5ce80e5d1c..c9a9348f94e 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -2504,8 +2504,8 @@ class CORE_EXPORT Qgis * * \since QGIS 3.30 */ - enum class ActionType SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsActionMenu, ActionType ) : int - { + enum class ActionType : int + { Invalid, //!< Invalid MapLayerAction, //!< Standard actions (defined by core or plugins), corresponds to QgsMapLayerAction class. AttributeAction //!< Custom actions (manually defined in layer properties), corresponds to QgsAction class. @@ -2519,8 +2519,8 @@ class CORE_EXPORT Qgis * * \since QGIS 3.30 */ - enum class MapLayerActionTarget SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsMapLayerAction, Target ) : int - { + enum class MapLayerActionTarget : int + { Layer = 1 << 0, //!< Action targets a complete layer SingleFeature = 1 << 1, //!< Action targets a single feature from a layer MultipleFeatures = 1 << 2, //!< Action targets multiple features from a layer @@ -2535,7 +2535,7 @@ class CORE_EXPORT Qgis * * \since QGIS 3.30 */ - Q_DECLARE_FLAGS( MapLayerActionTargets, MapLayerActionTarget ) SIP_MONKEYPATCH_FLAGS_UNNEST( QgsMapLayerAction, Targets ) + Q_DECLARE_FLAGS( MapLayerActionTargets, MapLayerActionTarget ) Q_FLAG( MapLayerActionTargets ) /** @@ -2545,8 +2545,8 @@ class CORE_EXPORT Qgis * * \since QGIS 3.30 */ - enum class MapLayerActionFlag SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsMapLayerAction, Flag ) : int - { + enum class MapLayerActionFlag : int + { EnabledOnlyWhenEditable = 1 << 1, //!< Action should be shown only for editable layers }; Q_ENUM( MapLayerActionFlag ) @@ -2558,7 +2558,7 @@ class CORE_EXPORT Qgis * * \since QGIS 3.30 */ - Q_DECLARE_FLAGS( MapLayerActionFlags, MapLayerActionFlag ) SIP_MONKEYPATCH_FLAGS_UNNEST( QgsMapLayerAction, Flags ) + Q_DECLARE_FLAGS( MapLayerActionFlags, MapLayerActionFlag ) Q_FLAG( MapLayerActionFlags ) /**