Class: QgsMapLayerAction

An action which can run on map layers.

The class can be used in two manners:

  • by instantiating it and connecting to its signals to perform an action

  • by subclassing and reimplementing its method (only since QGIS 3.18.2)

Class Hierarchy

Inheritance diagram of qgis.gui.QgsMapLayerAction

Base classes

QAction

QObject

Enums

Flag

alias of MapLayerActionFlag

Target

alias of MapLayerActionTarget

Methods

flags

Layer behavior flags.

isEnabledOnlyWhenEditable

Returns True if the action is only enabled for layers in editable mode.

setTargets

Define the targets of the action

targets

Returns availibity of action

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsMapLayerAction. See the FAQ for more details.

canRunUsingLayer

Returns True if the action can run using the specified layer.

triggerForFeature

Triggers the action with the specified layer and feature.

triggerForFeatures

Triggers the action with the specified layer and list of feature.

triggerForLayer

Triggers the action with the specified layer.

Signals

triggeredForFeature

Triggered when action has been run for a specific feature

triggeredForFeatureV2

Triggered when action has been run for a specific feature.

triggeredForFeatures

Triggered when action has been run for a specific list of features

triggeredForFeaturesV2

Triggered when action has been run for a specific list of features

triggeredForLayer

Triggered when action has been run for a specific layer

triggeredForLayerV2

Triggered when action has been run for a specific layer.

class qgis.gui.QgsMapLayerAction[source]

Bases: QAction

__init__(name: str | None, parent: QObject | None, targets: Qgis.MapLayerActionTargets | Qgis.MapLayerActionTarget = Qgis.MapLayerActionTarget.AllActions, icon: QIcon = QIcon(), flags: Qgis.MapLayerActionFlags | Qgis.MapLayerActionFlag = Qgis.MapLayerActionFlags())

Creates a map layer action which can run on any layer

Note

using AllActions as a target probably does not make a lot of sense. This default action was settled for API compatibility reasons.

Parameters:
__init__(name: str | None, parent: QObject | None, layer: QgsMapLayer | None, targets: Qgis.MapLayerActionTargets | Qgis.MapLayerActionTarget = Qgis.MapLayerActionTarget.AllActions, icon: QIcon = QIcon(), flags: Qgis.MapLayerActionFlags | Qgis.MapLayerActionFlag = Qgis.MapLayerActionFlags())

Creates a map layer action which can run only on a specific layer

Parameters:
__init__(name: str | None, parent: QObject | None, layerType: Qgis.LayerType, targets: Qgis.MapLayerActionTargets | Qgis.MapLayerActionTarget = Qgis.MapLayerActionTarget.AllActions, icon: QIcon = QIcon(), flags: Qgis.MapLayerActionFlags | Qgis.MapLayerActionFlag = Qgis.MapLayerActionFlags())

Creates a map layer action which can run on a specific type of layer

Parameters:
Flag

alias of MapLayerActionFlag

Flags

alias of MapLayerActionFlags

Target

alias of MapLayerActionTarget

Targets

alias of MapLayerActionTargets

virtual canRunUsingLayer(self, layer: QgsMapLayer | None) bool[source]

Returns True if the action can run using the specified layer.

Deprecated since version 3.40: Use the version with QgsMapLayerActionContext instead.

Parameters:

layer (Optional[QgsMapLayer])

Return type:

bool

virtual canRunUsingLayer(self, layer: QgsMapLayer | None, context: QgsMapLayerActionContext) bool[source]

Returns True if the action can run using the specified layer.

Note

Classes which implement this should return False to the deprecated canRunUsingLayer() method which does not accept a QgsMapLayerActionContext argument.

Added in version 3.30.

Parameters:
Return type:

bool

flags(self) Qgis.MapLayerActionFlags[source]

Layer behavior flags.

Return type:

Qgis.MapLayerActionFlags

isEnabledOnlyWhenEditable(self) bool[source]

Returns True if the action is only enabled for layers in editable mode.

Return type:

bool

setTargets(self, targets: Qgis.MapLayerActionTargets | Qgis.MapLayerActionTarget)[source]

Define the targets of the action

Parameters:

targets (Union[Qgis.MapLayerActionTargets, Qgis.MapLayerActionTarget])

targets(self) Qgis.MapLayerActionTargets[source]

Returns availibity of action

Return type:

Qgis.MapLayerActionTargets

virtual triggerForFeature(self, layer: QgsMapLayer | None, feature: QgsFeature)[source]

Triggers the action with the specified layer and feature.

Deprecated since version 3.40: Use the version with QgsMapLayerActionContext instead.

Parameters:
virtual triggerForFeature(self, layer: QgsMapLayer | None, feature: QgsFeature, context: QgsMapLayerActionContext)[source]

Triggers the action with the specified layer and feature.

Added in version 3.30.

Parameters:
virtual triggerForFeatures(self, layer: QgsMapLayer | None, featureList: Iterable[QgsFeature])[source]

Triggers the action with the specified layer and list of feature.

Deprecated since version 3.40: Use the version with QgsMapLayerActionContext instead.

Parameters:
virtual triggerForFeatures(self, layer: QgsMapLayer | None, featureList: Iterable[QgsFeature], context: QgsMapLayerActionContext)[source]

Triggers the action with the specified layer and list of feature.

Added in version 3.30.

Parameters:
virtual triggerForLayer(self, layer: QgsMapLayer | None)[source]

Triggers the action with the specified layer.

Deprecated since version 3.40: Use the version with QgsMapLayerActionContext instead.

Parameters:

layer (Optional[QgsMapLayer])

virtual triggerForLayer(self, layer: QgsMapLayer | None, context: QgsMapLayerActionContext)[source]

Triggers the action with the specified layer.

Added in version 3.30.

Parameters:
signal triggeredForFeature[source]

Triggered when action has been run for a specific feature

Deprecated since version 3.40: Use the version with QgsMapLayerActionContext instead.

signal triggeredForFeatureV2(layer: QgsMapLayer, feature: QgsFeature, context: QgsMapLayerActionContext)[source]

Triggered when action has been run for a specific feature.

Added in version 3.30.

Parameters:
signal triggeredForFeatures[source]

Triggered when action has been run for a specific list of features

Deprecated since version 3.40: Use the version with QgsMapLayerActionContext instead.

signal triggeredForFeaturesV2(layer: QgsMapLayer, featureList: List[QgsFeature], context: QgsMapLayerActionContext)[source]

Triggered when action has been run for a specific list of features

Added in version 3.30.

Parameters:
signal triggeredForLayer[source]

Triggered when action has been run for a specific layer

Deprecated since version 3.40: Use the version with QgsMapLayerActionContext instead.

signal triggeredForLayerV2(layer: QgsMapLayer, context: QgsMapLayerActionContext)[source]

Triggered when action has been run for a specific layer.

Added in version 3.30.

Parameters: