Class: QgsActionManager

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.

Class Hierarchy

Inheritance diagram of qgis.core.QgsActionManager

Base classes

QObject

Methods

action

Gets an action by its id.

actions

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

addAction

Add an action with the given name and action details.

clearActions

Removes all actions

defaultAction

Each scope can have a default action.

doAction

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

doActionFeature

Does the given action.

layer

Returns the layer

readXml

Reads the actions in in XML format

removeAction

Remove an action by its id.

setDefaultAction

Each scope can have a default action.

writeXml

Writes the actions out in XML format

class qgis.core.QgsActionManager[source]

Bases: QObject

__init__(layer: QgsVectorLayer | None)

Constructor

Parameters:

layer (Optional[QgsVectorLayer])

action(self, id: QUuid) QgsAction[source]

Gets an action by its id.

Parameters:

id (QUuid)

Return type:

QgsAction

action(self, id: str | None) QgsAction[source]

Gets an action by its id.

Added in version 3.28.

Parameters:

id (Optional[str])

Return type:

QgsAction

actions(self, actionScope: str | None = '') List[QgsAction]

Returns a list of actions that are available in the given action scope. If no action scope is provided, all actions will be returned.

Parameters:

actionScope (Optional[str] = '')

Return type:

List[QgsAction]

addAction(self, type: Qgis.AttributeActionType, name: str | None, command: str | None, capture: bool = False) QUuid[source]

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.

Parameters:
Return type:

QUuid

addAction(self, type: Qgis.AttributeActionType, name: str | None, command: str | None, icon: str | None, capture: bool = False) QUuid[source]

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.

Parameters:
  • type (Qgis.AttributeActionType)

  • name (Optional[str])

  • command (Optional[str])

  • icon (Optional[str])

  • capture (bool = False)

Return type:

QUuid

addAction(self, action: QgsAction)[source]

Add a new action to this list.

Parameters:

action (QgsAction)

clearActions(self)[source]

Removes all actions

defaultAction(self, actionScope: str | None) QgsAction[source]

Each scope can have a default action. This will be saved in the project file.

Parameters:

actionScope (Optional[str])

Return type:

QgsAction

doAction(self, actionId: QUuid, feature: QgsFeature, context: QgsExpressionContext)[source]

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

Parameters:
  • actionId (QUuid) – action id

  • feature (QgsFeature) – feature to run action for

  • context (QgsExpressionContext) – expression context to evaluate expressions under

doActionFeature(self, actionId: QUuid, feature: QgsFeature, defaultValueIndex: int = 0, scope: QgsExpressionContextScope = QgsExpressionContextScope())

Does the given action.

Parameters:
  • actionId (QUuid) – action id

  • feature (QgsFeature) – feature to run action for

  • defaultValueIndex (int = 0) – index of the field to be used if the action has a $currfield placeholder.

  • scope (QgsExpressionContextScope = QgsExpressionContextScope()) – expression context scope to add during expression evaluation

layer(self) QgsVectorLayer | None[source]

Returns the layer

Return type:

Optional[QgsVectorLayer]

readXml(self, layer_node: QDomNode) bool[source]

Reads the actions in in XML format

Parameters:

layer_node (QDomNode)

Return type:

bool

removeAction(self, actionId: QUuid)[source]

Remove an action by its id.

Parameters:

actionId (QUuid)

setDefaultAction(self, actionScope: str | None, actionId: QUuid)[source]

Each scope can have a default action. This will be saved in the project file.

Parameters:
  • actionScope (Optional[str])

  • actionId (QUuid)

writeXml(self, layer_node: QDomNode) bool[source]

Writes the actions out in XML format

Parameters:

layer_node (QDomNode)

Return type:

bool