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¶
Base classes¶
- 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:
name (Optional[str])
parent (Optional[QObject])
targets (Union[Qgis.MapLayerActionTargets, Qgis.MapLayerActionTarget] = Qgis.MapLayerActionTarget.AllActions)
icon (QIcon = QIcon())
flags (Union[Qgis.MapLayerActionFlags, Qgis.MapLayerActionFlag] = Qgis.MapLayerActionFlags())
- __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:
name (Optional[str])
parent (Optional[QObject])
layer (Optional[QgsMapLayer])
targets (Union[Qgis.MapLayerActionTargets, Qgis.MapLayerActionTarget] = Qgis.MapLayerActionTarget.AllActions)
icon (QIcon = QIcon())
flags (Union[Qgis.MapLayerActionFlags, Qgis.MapLayerActionFlag] = Qgis.MapLayerActionFlags())
- __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:
name (Optional[str])
parent (Optional[QObject])
layerType (Qgis.LayerType)
targets (Union[Qgis.MapLayerActionTargets, Qgis.MapLayerActionTarget] = Qgis.MapLayerActionTarget.AllActions)
icon (QIcon = QIcon())
flags (Union[Qgis.MapLayerActionFlags, Qgis.MapLayerActionFlag] = Qgis.MapLayerActionFlags())
- 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
Trueif the action can run using the specified layer.Deprecated since version 3.40: Use the version with
QgsMapLayerActionContextinstead.canRunUsingLayer(self, layer: Optional[QgsMapLayer], context:
QgsMapLayerActionContext) -> bool ReturnsTrueif the action can run using the specified layer.Note
Classes which implement this should return
Falseto the deprecatedcanRunUsingLayer()method which does not accept aQgsMapLayerActionContextargument.Added in version 3.30.
- Parameters:
layer (Optional[QgsMapLayer])
- Return type:
bool
- flags(self) Qgis.MapLayerActionFlags[source]¶
Layer behavior flags.
- Return type:
- isEnabledOnlyWhenEditable(self) bool[source]¶
Returns
Trueif 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:
- 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
QgsMapLayerActionContextinstead.triggerForFeature(self, layer: Optional[QgsMapLayer], feature:
QgsFeature, context:QgsMapLayerActionContext) Triggers the action with the specified layer and feature.Added in version 3.30.
- Parameters:
layer (Optional[QgsMapLayer])
feature (QgsFeature)
- 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
QgsMapLayerActionContextinstead.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:
layer (Optional[QgsMapLayer])
featureList (Iterable[QgsFeature])
- virtual triggerForLayer(self, layer: QgsMapLayer | None)[source]¶
Triggers the action with the specified layer.
Deprecated since version 3.40: Use the version with
QgsMapLayerActionContextinstead.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.