Skip to content

Commit

Permalink
Move action enums to Qgis, promote to enum class, and considerably thin
Browse files Browse the repository at this point in the history
includes as a result
  • Loading branch information
nyalldawson committed Nov 28, 2022
1 parent 81ca6f2 commit 3efb1e6
Show file tree
Hide file tree
Showing 44 changed files with 433 additions and 369 deletions.
74 changes: 74 additions & 0 deletions python/core/auto_additions/qgis.py
Expand Up @@ -2197,3 +2197,77 @@
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.__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.__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.__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
# monkey patching scoped based enum
QgsAction.Generic = Qgis.AttributeActionType.Generic
QgsAction.Generic.is_monkey_patched = True
QgsAction.Generic.__doc__ = "Generic"
QgsAction.GenericPython = Qgis.AttributeActionType.GenericPython
QgsAction.GenericPython.is_monkey_patched = True
QgsAction.GenericPython.__doc__ = "Python"
QgsAction.Mac = Qgis.AttributeActionType.Mac
QgsAction.Mac.is_monkey_patched = True
QgsAction.Mac.__doc__ = "MacOS specific"
QgsAction.Windows = Qgis.AttributeActionType.Windows
QgsAction.Windows.is_monkey_patched = True
QgsAction.Windows.__doc__ = "Windows specific"
QgsAction.Unix = Qgis.AttributeActionType.Unix
QgsAction.Unix.is_monkey_patched = True
QgsAction.Unix.__doc__ = "Unix specifc"
QgsAction.OpenUrl = Qgis.AttributeActionType.OpenUrl
QgsAction.OpenUrl.is_monkey_patched = True
QgsAction.OpenUrl.__doc__ = "Open URL action"
QgsAction.SubmitUrlEncoded = Qgis.AttributeActionType.SubmitUrlEncoded
QgsAction.SubmitUrlEncoded.is_monkey_patched = True
QgsAction.SubmitUrlEncoded.__doc__ = "POST data to an URL, using \"application/x-www-form-urlencoded\" or \"application/json\" if the body is valid JSON \since QGIS 3.24"
QgsAction.SubmitUrlMultipart = Qgis.AttributeActionType.SubmitUrlMultipart
QgsAction.SubmitUrlMultipart.is_monkey_patched = True
QgsAction.SubmitUrlMultipart.__doc__ = "POST data to an URL using \"multipart/form-data\" \since QGIS 3.24"
Qgis.AttributeActionType.__doc__ = 'Attribute action types.\n\nPrior to QGIS 3.30 this was available as :py:class:`QgsAction`.ActionType\n\n.. versionadded:: 3.30\n\n' + '* ``Generic``: ' + Qgis.AttributeActionType.Generic.__doc__ + '\n' + '* ``GenericPython``: ' + Qgis.AttributeActionType.GenericPython.__doc__ + '\n' + '* ``Mac``: ' + Qgis.AttributeActionType.Mac.__doc__ + '\n' + '* ``Windows``: ' + Qgis.AttributeActionType.Windows.__doc__ + '\n' + '* ``Unix``: ' + Qgis.AttributeActionType.Unix.__doc__ + '\n' + '* ``OpenUrl``: ' + Qgis.AttributeActionType.OpenUrl.__doc__ + '\n' + '* ``SubmitUrlEncoded``: ' + Qgis.AttributeActionType.SubmitUrlEncoded.__doc__ + '\n' + '* ``SubmitUrlMultipart``: ' + Qgis.AttributeActionType.SubmitUrlMultipart.__doc__
# --
Qgis.AttributeActionType.baseClass = Qgis
20 changes: 5 additions & 15 deletions python/core/auto_generated/actions/qgsaction.sip.in
Expand Up @@ -9,6 +9,7 @@




class QgsAction
{
%Docstring(signature="appended")
Expand All @@ -19,24 +20,13 @@ Utility class that encapsulates an action based on vector attributes.
#include "qgsaction.h"
%End
public:
enum ActionType
{
Generic,
GenericPython,
Mac,
Windows,
Unix,
OpenUrl,
SubmitUrlEncoded,
SubmitUrlMultipart,
};

QgsAction();
%Docstring
Default constructor
%End

QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false);
QgsAction( Qgis::AttributeActionType type, const QString &description, const QString &command, bool capture = false);
%Docstring
Create a new QgsAction

Expand All @@ -46,7 +36,7 @@ Create a new QgsAction
:param capture: If this is set to ``True``, the output will be captured when an action is run
%End

QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString());
QgsAction( Qgis::AttributeActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString());
%Docstring
Create a new QgsAction

Expand All @@ -60,7 +50,7 @@ Create a new QgsAction
:param notificationMessage: A particular message which reception will trigger the action
%End

QgsAction( const QUuid &id, ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString());
QgsAction( const QUuid &id, Qgis::AttributeActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString());
%Docstring
Create a new QgsAction

Expand Down Expand Up @@ -126,7 +116,7 @@ Returns the notification message that triggers the action
.. versionadded:: 3.0
%End

ActionType type() const;
Qgis::AttributeActionType type() const;
%Docstring
The action type
%End
Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_generated/actions/qgsactionmanager.sip.in
Expand Up @@ -30,7 +30,7 @@ based on attributes of a given feature.
Constructor
%End

QUuid addAction( QgsAction::ActionType type, const QString &name, const QString &command, bool capture = false );
QUuid addAction( Qgis::AttributeActionType type, const QString &name, const QString &command, bool capture = false );
%Docstring
Add an action with the given name and action details.
Will happily have duplicate names and actions. If
Expand All @@ -39,7 +39,7 @@ any stdout from the process will be captured and displayed in a
dialog box.
%End

QUuid addAction( QgsAction::ActionType type, const QString &name, const QString &command, const QString &icon, bool capture = false );
QUuid addAction( Qgis::AttributeActionType type, const QString &name, const QString &command, const QString &icon, bool capture = false );
%Docstring
Add an action with the given name and action details.
Will happily have duplicate names and actions. If
Expand Down
42 changes: 42 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -1448,6 +1448,44 @@ The development version
OptimalInInsertionGroup,
};

enum class ActionType
{
Invalid,
MapLayerAction,
AttributeAction
};

enum class MapLayerActionTarget
{
Layer,
SingleFeature,
MultipleFeatures,
AllActions
};

typedef QFlags<Qgis::MapLayerActionTarget> MapLayerActionTargets;


enum class MapLayerActionFlag
{
EnabledOnlyWhenEditable,
};

typedef QFlags<Qgis::MapLayerActionFlag> MapLayerActionFlags;


enum class AttributeActionType
{
Generic,
GenericPython,
Mac,
Windows,
Unix,
OpenUrl,
SubmitUrlEncoded,
SubmitUrlMultipart,
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
Expand Down Expand Up @@ -1580,6 +1618,10 @@ QFlags<Qgis::LabelingFlag> operator|(Qgis::LabelingFlag f1, QFlags<Qgis::Labelin

QFlags<Qgis::GpsInformationComponent> operator|(Qgis::GpsInformationComponent f1, QFlags<Qgis::GpsInformationComponent> f2);

QFlags<Qgis::MapLayerActionTarget> operator|(Qgis::MapLayerActionTarget f1, QFlags<Qgis::MapLayerActionTarget> f2);

QFlags<Qgis::MapLayerActionFlag> operator|(Qgis::MapLayerActionFlag f1, QFlags<Qgis::MapLayerActionFlag> f2);




Expand Down
5 changes: 0 additions & 5 deletions python/gui/auto_additions/qgsmaplayeraction.py

This file was deleted.

8 changes: 1 addition & 7 deletions python/gui/auto_generated/actions/qgsactionmenu.sip.in
Expand Up @@ -21,12 +21,6 @@ This class is a menu that is populated automatically with the actions defined fo
#include "qgsactionmenu.h"
%End
public:
enum ActionType
{
Invalid,
MapLayerAction,
AttributeAction
};

struct ActionData
{
Expand All @@ -38,7 +32,7 @@ Constructor for ActionData.
ActionData( const QgsAction &action, QgsFeatureId featureId, QgsMapLayer *mapLayer );
ActionData( QgsMapLayerAction *action, QgsFeatureId featureId, QgsMapLayer *mapLayer );

QgsActionMenu::ActionType actionType;
Qgis::ActionType actionType;
QVariant actionData;
QgsFeatureId featureId;
QgsMapLayer *mapLayer;
Expand Down
33 changes: 6 additions & 27 deletions python/gui/auto_generated/actions/qgsmaplayeraction.sip.in
Expand Up @@ -24,25 +24,8 @@ The class can be used in two manners:
#include "qgsmaplayeraction.h"
%End
public:
enum Target
{
Layer,
SingleFeature,
MultipleFeatures,
AllActions
};
typedef QFlags<QgsMapLayerAction::Target> Targets;


enum Flag
{
EnabledOnlyWhenEditable,
};

typedef QFlags<QgsMapLayerAction::Flag> Flags;


QgsMapLayerAction( const QString &name, QObject *parent /TransferThis/, Targets targets = AllActions, const QIcon &icon = QIcon(), QgsMapLayerAction::Flags flags = QgsMapLayerAction::Flags() );
QgsMapLayerAction( const QString &name, QObject *parent /TransferThis/, Qgis::MapLayerActionTargets targets = Qgis::MapLayerActionTarget::AllActions, const QIcon &icon = QIcon(), Qgis::MapLayerActionFlags flags = Qgis::MapLayerActionFlags() );
%Docstring
Creates a map layer action which can run on any layer

Expand All @@ -51,19 +34,19 @@ Creates a map layer action which can run on any layer
using AllActions as a target probably does not make a lot of sense. This default action was settled for API compatibility reasons.
%End

QgsMapLayerAction( const QString &name, QObject *parent /TransferThis/, QgsMapLayer *layer, Targets targets = AllActions, const QIcon &icon = QIcon(), QgsMapLayerAction::Flags flags = QgsMapLayerAction::Flags() );
QgsMapLayerAction( const QString &name, QObject *parent /TransferThis/, QgsMapLayer *layer, Qgis::MapLayerActionTargets targets = Qgis::MapLayerActionTarget::AllActions, const QIcon &icon = QIcon(), Qgis::MapLayerActionFlags flags = Qgis::MapLayerActionFlags() );
%Docstring
Creates a map layer action which can run only on a specific layer
%End

QgsMapLayerAction( const QString &name, QObject *parent /TransferThis/, QgsMapLayerType layerType, Targets targets = AllActions, const QIcon &icon = QIcon(), QgsMapLayerAction::Flags flags = QgsMapLayerAction::Flags() );
QgsMapLayerAction( const QString &name, QObject *parent /TransferThis/, QgsMapLayerType layerType, Qgis::MapLayerActionTargets targets = Qgis::MapLayerActionTarget::AllActions, const QIcon &icon = QIcon(), Qgis::MapLayerActionFlags flags = Qgis::MapLayerActionFlags() );
%Docstring
Creates a map layer action which can run on a specific type of layer
%End

~QgsMapLayerAction();

QgsMapLayerAction::Flags flags() const;
Qgis::MapLayerActionFlags flags() const;
%Docstring
Layer behavior flags.

Expand Down Expand Up @@ -134,11 +117,11 @@ Triggers the action with the specified layer.
.. versionadded:: 3.30
%End

void setTargets( Targets targets );
void setTargets( Qgis::MapLayerActionTargets targets );
%Docstring
Define the targets of the action
%End
const Targets &targets() const;
Qgis::MapLayerActionTargets targets() const;
%Docstring
Returns availibity of action
%End
Expand Down Expand Up @@ -199,10 +182,6 @@ Triggered when action has been run for a specific layer.

};

QFlags<QgsMapLayerAction::Target> operator|(QgsMapLayerAction::Target f1, QFlags<QgsMapLayerAction::Target> f2);

QFlags<QgsMapLayerAction::Flag> operator|(QgsMapLayerAction::Flag f1, QFlags<QgsMapLayerAction::Flag> f2);


/************************************************************************
* This file has been generated automatically from *
Expand Down
Expand Up @@ -38,7 +38,7 @@ QgsMapLayerActionRegistry is not usually directly created, but rather accessed t
Adds a map layer action to the registry
%End

QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer *layer, QgsMapLayerAction::Targets targets = QgsMapLayerAction::AllActions, const QgsMapLayerActionContext &context = QgsMapLayerActionContext() );
QList<QgsMapLayerAction *> mapLayerActions( QgsMapLayer *layer, Qgis::MapLayerActionTargets targets = Qgis::MapLayerActionTarget::AllActions, const QgsMapLayerActionContext &context = QgsMapLayerActionContext() );
%Docstring
Returns the map layer actions which can run on the specified layer.

Expand Down
4 changes: 1 addition & 3 deletions src/app/gps/qgsappgpsdigitizing.cpp
Expand Up @@ -20,7 +20,6 @@
#include "qgsgui.h"
#include "qgisapp.h"
#include "qgsmessagebar.h"
#include "qgspolygon.h"
#include "qgsmapcanvas.h"
#include "qgsfeatureaction.h"
#include "qgsgpsconnection.h"
Expand All @@ -30,12 +29,11 @@
#include "qgsattributeform.h"
#include "qgsattributedialog.h"
#include "qgshighlight.h"
#include "qgsidentifymenu.h"

#include <QTimeZone>

QgsUpdateGpsDetailsAction::QgsUpdateGpsDetailsAction( QgsAppGpsConnection *connection, QgsAppGpsDigitizing *digitizing, QObject *parent )
: QgsMapLayerAction( tr( "Update GPS Information" ), parent, QgsMapLayerAction::Target::SingleFeature, QgsApplication::getThemeIcon( QStringLiteral( "/gpsicons/mActionRecenter.svg" ) ) )
: QgsMapLayerAction( tr( "Update GPS Information" ), parent, Qgis::MapLayerActionTarget::SingleFeature, QgsApplication::getThemeIcon( QStringLiteral( "/gpsicons/mActionRecenter.svg" ) ) )
, mConnection( connection )
, mDigitizing( digitizing )
{
Expand Down
3 changes: 1 addition & 2 deletions src/app/gps/qgsappgpsdigitizing.h
Expand Up @@ -22,8 +22,7 @@
#include "qgis_app.h"
#include "qgssettingsentryimpl.h"
#include "qgsgpslogger.h"
#include "qgsmaplayeractionregistry.h"
#include "qgswkbtypes.h"
#include "qgsmaplayeraction.h"
#include "qgsattributes.h"

class QgsAppGpsConnection;
Expand Down

0 comments on commit 3efb1e6

Please sign in to comment.