QgsActionManager class

Storage and management of actions associated with a layer.

Actions can trigger custom code or applications to be executed based on attributes of a given feature.

Constructors, destructors, conversion operators

QgsActionManager(QgsVectorLayer* layer)
Constructor.

Public functions

auto action(QUuid id) -> QgsAction
Gets an action by its id.
auto actions(const QString& actionScope = QString()) const -> QList<QgsAction>
Returns a list of actions that are available in the given action scope.
auto addAction(QgsAction::ActionType type, const QString& name, const QString& command, bool capture = false) -> QUuid
Add an action with the given name and action details.
auto addAction(QgsAction::ActionType type, const QString& name, const QString& command, const QString& icon, bool capture = false) -> QUuid
Add an action with the given name and action details.
void addAction(const QgsAction& action)
Add a new action to this list.
void clearActions()
Removes all actions.
auto defaultAction(const QString& actionScope) -> QgsAction
Each scope can have a default action.
void doAction(QUuid actionId, const QgsFeature& feature, int defaultValueIndex = 0, const QgsExpressionContextScope& scope = QgsExpressionContextScope())
Does the given action.
void doAction(QUuid actionId, const QgsFeature& feature, const QgsExpressionContext& context)
Does the action using the expression engine to replace any embedded expressions in the action definition.
auto layer() const -> QgsVectorLayer*
Returns the layer.
auto readXml(const QDomNode& layer_node) -> bool
Reads the actions in in XML format.
void removeAction(QUuid actionId)
Remove an action by its id.
void setDefaultAction(const QString& actionScope, QUuid actionId)
Each scope can have a default action.
auto writeXml(QDomNode& layer_node) const -> bool
Writes the actions out in XML format.

Function documentation

QgsAction QgsActionManager::action(QUuid id)

Gets an action by its id.

QList<QgsAction> QgsActionManager::actions(const QString& actionScope = QString()) const

Returns a list of actions that are available in the given action scope.

If no action scope is provided, all actions will be returned.

QUuid QgsActionManager::addAction(QgsAction::ActionType type, const QString& name, const QString& command, bool capture = false)

Add an action with the given name and action details.

Will happily have duplicate names and actions. If capture is true, when running the action using doAction(), any stdout from the process will be captured and displayed in a dialog box.

QUuid QgsActionManager::addAction(QgsAction::ActionType type, const QString& name, const QString& command, const QString& icon, bool capture = false)

Add an action with the given name and action details.

Will happily have duplicate names and actions. If capture is true, when running the action using doAction(), any stdout from the process will be captured and displayed in a dialog box.

QgsAction QgsActionManager::defaultAction(const QString& actionScope)

Each scope can have a default action.

This will be saved in the project file.

void QgsActionManager::doAction(QUuid actionId, const QgsFeature& feature, int defaultValueIndex = 0, const QgsExpressionContextScope& scope = QgsExpressionContextScope())

Does the given action.

Parameters
actionId action id
feature feature to run action for
defaultValueIndex index of the field to be used if the action has a $currfield placeholder.
scope expression context scope to add during expression evaluation

void QgsActionManager::doAction(QUuid actionId, const QgsFeature& feature, const QgsExpressionContext& context)

Does the action using the expression engine to replace any embedded expressions in the action definition.

Parameters
actionId action id
feature feature to run action for
context expression context to evaluate expressions under

void QgsActionManager::removeAction(QUuid actionId)

Remove an action by its id.

void QgsActionManager::setDefaultAction(const QString& actionScope, QUuid actionId)

Each scope can have a default action.

This will be saved in the project file.