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

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.

canRunUsingLayer(self, layer: Optional[QgsMapLayer], context: QgsMapLayerActionContext) -> bool 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:

layer (Optional[QgsMapLayer])

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.

triggerForFeature(self, layer: Optional[QgsMapLayer], feature: QgsFeature, context: QgsMapLayerActionContext) 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.

triggerForFeatures(self, layer: Optional[QgsMapLayer], featureList: Iterable[QgsFeature], context: QgsMapLayerActionContext) 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.

triggerForLayer(self, layer: Optional[QgsMapLayer], context: QgsMapLayerActionContext) Triggers the action with the specified layer.

Added in version 3.30.

Parameters:

layer (Optional[QgsMapLayer])

signal triggeredForFeature[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

signal triggeredForFeatureV2[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

signal triggeredForFeatures[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

signal triggeredForFeaturesV2[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

signal triggeredForLayer[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

signal triggeredForLayerV2[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.