Class: QgsExpressionContextUtils¶
Contains utilities for working with QgsExpressionContext
objects, including methods for creating scopes for specific uses (e.g.,
project scopes, layer scopes).
Static Methods
Creates a new scope which contains variables and functions relating to a |
|
Helper function for creating an expression context which contains just a feature and fields collection. |
|
Creates a new scope which contains functions and variables from the current attribute form/table formFeature. |
|
Creates a list of three scopes: global, layer's project and layer. |
|
Creates a new scope which contains variables and functions relating to the global QGIS context. |
|
Creates a new scope which contains variables and functions relating to a |
|
Creates a new scope which contains variables and functions relating to a |
|
Creates a new scope which contains variables and functions relating to a |
|
Sets the expression context variables which are available for expressions triggered by moving the mouse over a feature of the currently selected layer. |
|
Creates a new scope which contains variables and functions relating to a |
|
Sets the expression context variables which are available for expressions triggered by a map tool capture like add feature. |
|
Creates a new scope which contains functions relating to mesh layer element elementType |
|
Creates a new scope which contains variables and functions relating to a |
|
Creates a new scope which contains variables and functions relating to provider notifications |
|
Creates a new scope which contains functions and variables from the current parent attribute form/table formFeature. |
|
Creates a new scope which contains variables and functions relating to a processing algorithm, when used with the specified parameters and context. |
|
Creates a new scope which contains variables and functions relating to a processing model algorithm, when used with the specified parameters and context. |
|
Creates a new scope which contains variables and functions relating to a QGIS project. |
|
Registers all known core functions provided by |
|
Remove a global context variable. |
|
Remove project context variable. |
|
Sets a global context variable. |
|
Sets all global context variables. |
|
Sets a layer context variable. |
|
Sets all layer context variables. |
|
Sets a layout item context variable, with the given name and value. |
|
Sets all layout item context variables for an item. |
|
Sets a layout multi frame context variable, with the given name and value. |
|
Sets all layout multiframe context variables for an frame. |
|
Sets a layout context variable. |
|
Sets all layout context variables. |
|
Sets a project context variable. |
|
Sets all project context variables. |
|
Updates a symbol scope related to a |
- class qgis.core.QgsExpressionContextUtils[source]¶
Bases:
object
- static atlasScope(atlas: QgsLayoutAtlas | None) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to a
QgsLayoutAtlas
. For instance, current page name and number.- Parameters:
atlas (Optional[QgsLayoutAtlas]) – source atlas. If
None
, a set of default atlas variables will be added to the scope.- Return type:
Optional[QgsExpressionContextScope]
- static createFeatureBasedContext(feature: QgsFeature, fields: QgsFields) QgsExpressionContext [source]¶
Helper function for creating an expression context which contains just a feature and fields collection. Generally this method should not be used as the created context does not include standard scopes such as the global and project scopes.
- Parameters:
feature (QgsFeature)
fields (QgsFields)
- Return type:
- static formScope(formFeature: QgsFeature = QgsFeature(), formMode: str | None = '') QgsExpressionContextScope | None [source]¶
Creates a new scope which contains functions and variables from the current attribute form/table
formFeature
. The variables and values in this scope will reflect the current state of the form/row being edited. TheformMode
(SingleEditMode etc.) is passed as textAdded in version 3.2.
- Parameters:
formFeature (
QgsFeature
= QgsFeature())formMode (Optional[str] = '')
- Return type:
Optional[QgsExpressionContextScope]
- static globalProjectLayerScopes(layer: QgsMapLayer | None) List[QgsExpressionContextScope] ¶
Creates a list of three scopes: global, layer’s project and layer.
- Parameters:
layer (Optional[QgsMapLayer])
- Return type:
- static globalScope() QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to the global QGIS context. For instance, QGIS version numbers and variables specified through QGIS options.
See also
- Return type:
Optional[QgsExpressionContextScope]
- static layerScope(layer: QgsMapLayer | None) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to a
QgsMapLayer
. For instance, layer name, id and fields.- Parameters:
layer (Optional[QgsMapLayer])
- Return type:
Optional[QgsExpressionContextScope]
- static layoutItemScope(item: QgsLayoutItem | None) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to a
QgsLayoutItem
. For instance, item size and position.See also
See also
- Parameters:
item (Optional[QgsLayoutItem])
- Return type:
Optional[QgsExpressionContextScope]
- static layoutScope(layout: QgsLayout | None) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to a
QgsLayout
layout
. For instance, number of pages and page sizes.- Parameters:
layout (Optional[QgsLayout])
- Return type:
Optional[QgsExpressionContextScope]
- static mapLayerPositionScope(position: QgsPointXY) QgsExpressionContextScope | None [source]¶
Sets the expression context variables which are available for expressions triggered by moving the mouse over a feature of the currently selected layer.
- Parameters:
position (QgsPointXY) – map coordinates of the current pointer position in the CRS of the layer which triggered the action.
Added in version 3.30.
- Return type:
Optional[QgsExpressionContextScope]
- static mapSettingsScope(mapSettings: QgsMapSettings) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to a
QgsMapSettings
object. For instance, map scale and rotation.- Parameters:
mapSettings (QgsMapSettings)
- Return type:
Optional[QgsExpressionContextScope]
- static mapToolCaptureScope(matches: Iterable[QgsPointLocator.Match]) QgsExpressionContextScope | None [source]¶
Sets the expression context variables which are available for expressions triggered by a map tool capture like add feature.
- Parameters:
matches (Iterable[QgsPointLocator.Match])
- Return type:
Optional[QgsExpressionContextScope]
- static meshExpressionScope(elementType: QgsMesh.ElementType) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains functions relating to mesh layer element
elementType
Added in version 3.22.
- Parameters:
elementType (QgsMesh.ElementType)
- Return type:
Optional[QgsExpressionContextScope]
- static multiFrameScope(frame: QgsLayoutMultiFrame | None) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to a
QgsLayoutMultiFrame
.See also
See also
Added in version 3.10.
- Parameters:
frame (Optional[QgsLayoutMultiFrame])
- Return type:
Optional[QgsExpressionContextScope]
- static notificationScope(message: str | None = '') QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to provider notifications
- Parameters:
message (Optional[str] = '') – the notification message
- Return type:
Optional[QgsExpressionContextScope]
- static parentFormScope(formFeature: QgsFeature = QgsFeature(), formMode: str | None = '') QgsExpressionContextScope | None [source]¶
Creates a new scope which contains functions and variables from the current parent attribute form/table
formFeature
. The variables and values in this scope will reflect the current state of the parent form/row being edited. TheformMode
(SingleEditMode etc.) is passed as textAdded in version 3.14.
- Parameters:
formFeature (
QgsFeature
= QgsFeature())formMode (Optional[str] = '')
- Return type:
Optional[QgsExpressionContextScope]
- static processingAlgorithmScope(algorithm: QgsProcessingAlgorithm | None, parameters: Dict[str, Any], context: QgsProcessingContext) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to a processing
algorithm
, when used with the specifiedparameters
andcontext
. For instance, algorithm name and parameter functions.See also
- Parameters:
algorithm (Optional[QgsProcessingAlgorithm])
parameters (Dict[str, Any])
context (QgsProcessingContext)
- Return type:
Optional[QgsExpressionContextScope]
- static processingModelAlgorithmScope(model: QgsProcessingModelAlgorithm | None, parameters: Dict[str, Any], context: QgsProcessingContext) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to a processing
model
algorithm, when used with the specifiedparameters
andcontext
. For instance, model name and path variables.Added in version 3.6.
- Parameters:
model (Optional[QgsProcessingModelAlgorithm])
parameters (Dict[str, Any])
context (QgsProcessingContext)
- Return type:
Optional[QgsExpressionContextScope]
- static projectScope(project: QgsProject | None) QgsExpressionContextScope | None [source]¶
Creates a new scope which contains variables and functions relating to a QGIS project. For instance, project path and title, and variables specified through the project properties.
- Parameters:
project (Optional[QgsProject]) – What project to use
See also
- Return type:
Optional[QgsExpressionContextScope]
- static registerContextFunctions()[source]¶
Registers all known core functions provided by
QgsExpressionContextScope
objects.
- static removeGlobalVariable(name: str | None)[source]¶
Remove a global context variable.
- Parameters:
name (Optional[str]) – variable name
See also
See also
See also
- static removeProjectVariable(project: QgsProject | None, name: str | None)[source]¶
Remove project context variable.
- Parameters:
project (Optional[QgsProject]) – Project to apply changes to
name (Optional[str]) – variable name
See also
See also
See also
- static setGlobalVariable(name: str | None, value: Any)[source]¶
Sets a global context variable. This variable will be contained within scopes retrieved via
globalScope()
.- Parameters:
name (Optional[str]) – variable name
value (Any) – variable value
See also
See also
See also
- static setGlobalVariables(variables: Dict[str, Any])[source]¶
Sets all global context variables. Existing global variables will be removed and replaced with the variables specified.
- Parameters:
variables (Dict[str, Any]) – new set of global variables
See also
See also
See also
- static setLayerVariable(layer: QgsMapLayer | None, name: str | None, value: Any)[source]¶
Sets a layer context variable. This variable will be contained within scopes retrieved via
layerScope()
.- Parameters:
layer (Optional[QgsMapLayer]) – map layer
name (Optional[str]) – variable name
value (Any) – variable value
See also
See also
- static setLayerVariables(layer: QgsMapLayer | None, variables: Dict[str, Any])[source]¶
Sets all layer context variables. Existing layer variables will be removed and replaced with the variables specified.
- Parameters:
layer (Optional[QgsMapLayer]) – map layer
variables (Dict[str, Any]) – new set of layer variables
See also
See also
- static setLayoutItemVariable(item: QgsLayoutItem | None, name: str | None, value: Any)[source]¶
Sets a layout
item
context variable, with the givenname
andvalue
. This variable will be contained within scopes retrieved vialayoutItemScope()
.See also
See also
- Parameters:
item (Optional[QgsLayoutItem])
name (Optional[str])
value (Any)
- static setLayoutItemVariables(item: QgsLayoutItem | None, variables: Dict[str, Any])[source]¶
Sets all layout item context variables for an
item
. Existing variables will be removed and replaced with thevariables
specified.See also
See also
- Parameters:
item (Optional[QgsLayoutItem])
variables (Dict[str, Any])
- static setLayoutMultiFrameVariable(frame: QgsLayoutMultiFrame | None, name: str | None, value: Any)[source]¶
Sets a layout multi
frame
context variable, with the givenname
andvalue
. This variable will be contained within scopes retrieved viamultiFrameScope()
.See also
See also
Added in version 3.10.
- Parameters:
frame (Optional[QgsLayoutMultiFrame])
name (Optional[str])
value (Any)
- static setLayoutMultiFrameVariables(frame: QgsLayoutMultiFrame | None, variables: Dict[str, Any])[source]¶
Sets all layout multiframe context variables for an
frame
. Existing variables will be removed and replaced with thevariables
specified.See also
See also
Added in version 3.10.
- Parameters:
frame (Optional[QgsLayoutMultiFrame])
variables (Dict[str, Any])
- static setLayoutVariable(layout: QgsLayout | None, name: str | None, value: Any)[source]¶
Sets a layout context variable. This variable will be contained within scopes retrieved via
layoutScope()
.- Parameters:
layout (Optional[QgsLayout]) – target layout
name (Optional[str]) – variable name
value (Any) – variable value
See also
See also
- static setLayoutVariables(layout: QgsLayout | None, variables: Dict[str, Any])[source]¶
Sets all layout context variables. Existing layout variables will be removed and replaced with the variables specified.
- Parameters:
layout (Optional[QgsLayout]) – target layout
variables (Dict[str, Any]) – new set of layer variables
See also
See also
- static setProjectVariable(project: QgsProject | None, name: str | None, value: Any)[source]¶
Sets a project context variable. This variable will be contained within scopes retrieved via
projectScope()
.- Parameters:
project (Optional[QgsProject]) – Project to apply changes to
name (Optional[str]) – variable name
value (Any) – variable value
See also
See also
See also
- static setProjectVariables(project: QgsProject | None, variables: Dict[str, Any])[source]¶
Sets all project context variables. Existing project variables will be removed and replaced with the variables specified.
- Parameters:
project (Optional[QgsProject]) – Project to apply changes to
variables (Dict[str, Any]) – new set of project variables
See also
See also
See also
- static updateSymbolScope(symbol: QgsSymbol | None, symbolScope: QgsExpressionContextScope | None = None) QgsExpressionContextScope | None [source]¶
Updates a symbol scope related to a
QgsSymbol
to an expression context.- Parameters:
symbol (Optional[QgsSymbol]) – symbol to extract properties from
symbolScope (Optional[QgsExpressionContextScope] = None) – pointer to an existing scope to update
- Return type:
Optional[QgsExpressionContextScope]