Skip to content

Commit

Permalink
Manually monkey patch compatibility, since we can't auto patch to gui…
Browse files Browse the repository at this point in the history
… classes
  • Loading branch information
nyalldawson committed Nov 28, 2022
1 parent 0c562b4 commit fe0ab98
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
41 changes: 10 additions & 31 deletions python/core/auto_additions/qgis.py
Expand Up @@ -2197,49 +2197,28 @@
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."
# monkey patching scoped based enum
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__ = ""
# monkey patching scoped based enum
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
Expand Down
6 changes: 3 additions & 3 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -1449,14 +1449,14 @@ The development version
};

enum class ActionType
{
{
Invalid,
MapLayerAction,
AttributeAction
};

enum class MapLayerActionTarget
{
{
Layer,
SingleFeature,
MultipleFeatures,
Expand All @@ -1467,7 +1467,7 @@ The development version


enum class MapLayerActionFlag
{
{
EnabledOnlyWhenEditable,
};

Expand Down
35 changes: 35 additions & 0 deletions python/gui/__init__.py.in
Expand Up @@ -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
16 changes: 8 additions & 8 deletions src/core/qgis.h
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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 )

/**
Expand All @@ -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 )
Expand All @@ -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 )

/**
Expand Down

0 comments on commit fe0ab98

Please sign in to comment.