Class: QgsExpressionContextUtils¶
-
class
qgis.core.
QgsExpressionContextUtils
¶ Bases:
sip.wrapper
Contains utilities for working with QgsExpressionContext objects, including methods for creating scopes for specific uses (e.g., project scopes, layer scopes).
New in version 2.12: Enums
Methods
Creates a new scope which contains variables and functions relating to a
QgsLayoutAtlas
.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
feature
.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
QgsMapLayer
.Creates a new scope which contains variables and functions relating to a
QgsLayoutItem
.Creates a new scope which contains variables and functions relating to a
QgsLayout
layout
.Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
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 variables and functions relating to a
QgsLayoutMultiFrame
.Creates a new scope which contains variables and functions relating to provider notifications
Creates a new scope which contains variables and functions relating to a processing
algorithm
, when used with the specifiedparameters
andcontext
.Creates a new scope which contains variables and functions relating to a processing
model
algorithm, when used with the specifiedparameters
andcontext
.Creates a new scope which contains variables and functions relating to a QGIS project.
Registers all known core functions provided by QgsExpressionContextScope objects.
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 givenname
andvalue
.Sets all layout item context variables for an
item
.Sets a layout multi
frame
context variable, with the givenname
andvalue
.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 QgsSymbol to an expression context.
Signals
Attributes
-
atlasScope
(atlas: QgsLayoutAtlas) → QgsExpressionContextScope¶ Creates a new scope which contains variables and functions relating to a
QgsLayoutAtlas
. For instance, current page name and number.- Parameters
atlas – source atlas. If
None
, a set of default atlas variables will be added to the scope.
-
createFeatureBasedContext
(feature: QgsFeature, fields: QgsFields) → QgsExpressionContext¶ 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.
-
formScope
(formFeature: QgsFeature = QgsFeature(), formMode: str = '') → QgsExpressionContextScope¶ Creates a new scope which contains functions and variables from the current attribute form/table
feature
. The variables and values in this scope will reflect the current state of the form/row being edited. TheformMode
(SingleEditMode etc.) is passed as textNew in version 3.2.
-
globalProjectLayerScopes
(layer: QgsMapLayer) → List[QgsExpressionContextScope]¶ Creates a list of three scopes: global, layer’s project and layer.
New in version 3.0.
-
globalScope
() → QgsExpressionContextScope¶ 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
-
layerScope
(layer: QgsMapLayer) → QgsExpressionContextScope¶ Creates a new scope which contains variables and functions relating to a
QgsMapLayer
. For instance, layer name, id and fields.
-
layoutItemScope
(item: QgsLayoutItem) → QgsExpressionContextScope¶ Creates a new scope which contains variables and functions relating to a
QgsLayoutItem
. For instance, item size and position.See also
See also
New in version 3.0.
-
layoutScope
(layout: QgsLayout) → QgsExpressionContextScope¶ Creates a new scope which contains variables and functions relating to a
QgsLayout
layout
. For instance, number of pages and page sizes.New in version 3.0.
-
mapSettingsScope
(mapSettings: QgsMapSettings) → QgsExpressionContextScope¶ Creates a new scope which contains variables and functions relating to a QgsMapSettings object. For instance, map scale and rotation.
-
mapToolCaptureScope
(matches: Iterable[QgsPointLocator.Match]) → QgsExpressionContextScope¶ Sets the expression context variables which are available for expressions triggered by a map tool capture like add feature.
New in version 3.0.
-
multiFrameScope
(frame: QgsLayoutMultiFrame) → QgsExpressionContextScope¶ Creates a new scope which contains variables and functions relating to a
QgsLayoutMultiFrame
.See also
See also
New in version 3.10.
-
notificationScope
(message: str = '') → QgsExpressionContextScope¶ Creates a new scope which contains variables and functions relating to provider notifications
- Parameters
message – the notification message
-
processingAlgorithmScope
(algorithm: QgsProcessingAlgorithm, parameters: Dict[str, Any], context: QgsProcessingContext) → QgsExpressionContextScope¶ 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
-
processingModelAlgorithmScope
(model: QgsProcessingModelAlgorithm, parameters: Dict[str, Any], context: QgsProcessingContext) → QgsExpressionContextScope¶ 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.New in version 3.6.
-
projectScope
(project: QgsProject) → QgsExpressionContextScope¶ 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 – What project to use
See also
-
registerContextFunctions
()¶ Registers all known core functions provided by QgsExpressionContextScope objects.
-
removeGlobalVariable
(name: str)¶ Remove a global context variable.
- Parameters
name – variable name
See also
See also
See also
-
removeProjectVariable
(project: QgsProject, name: str)¶ Remove project context variable.
- Parameters
project – Project to apply changes to
name – variable name
See also
See also
See also
-
setGlobalVariable
(name: str, value: Any)¶ Sets a global context variable. This variable will be contained within scopes retrieved via globalScope().
- Parameters
name – variable name
value – variable value
See also
See also
See also
-
setGlobalVariables
(variables: Dict[str, Any])¶ Sets all global context variables. Existing global variables will be removed and replaced with the variables specified.
- Parameters
variables – new set of global variables
See also
See also
See also
-
setLayerVariable
(layer: QgsMapLayer, name: str, value: Any)¶ Sets a layer context variable. This variable will be contained within scopes retrieved via layerScope().
- Parameters
layer – map layer
name – variable name
value – variable value
See also
See also
-
setLayerVariables
(layer: QgsMapLayer, variables: Dict[str, Any])¶ Sets all layer context variables. Existing layer variables will be removed and replaced with the variables specified.
- Parameters
layer – map layer
variables – new set of layer variables
See also
See also
-
setLayoutItemVariable
(item: QgsLayoutItem, name: str, value: Any)¶ Sets a layout
item
context variable, with the givenname
andvalue
. This variable will be contained within scopes retrieved via layoutItemScope().See also
See also
New in version 3.0.
-
setLayoutItemVariables
(item: QgsLayoutItem, variables: Dict[str, Any])¶ Sets all layout item context variables for an
item
. Existing variables will be removed and replaced with thevariables
specified.See also
See also
New in version 3.0.
-
setLayoutMultiFrameVariable
(frame: QgsLayoutMultiFrame, name: str, value: Any)¶ Sets a layout multi
frame
context variable, with the givenname
andvalue
. This variable will be contained within scopes retrieved via multiFrameScope().See also
See also
New in version 3.10.
-
setLayoutMultiFrameVariables
(frame: QgsLayoutMultiFrame, variables: Dict[str, Any])¶ Sets all layout multiframe context variables for an
frame
. Existing variables will be removed and replaced with thevariables
specified.See also
See also
New in version 3.10.
-
setLayoutVariable
(layout: QgsLayout, name: str, value: Any)¶ Sets a layout context variable. This variable will be contained within scopes retrieved via layoutScope().
- Parameters
layout – target layout
name – variable name
value – variable value
See also
See also
New in version 3.0.
-
setLayoutVariables
(layout: QgsLayout, variables: Dict[str, Any])¶ Sets all layout context variables. Existing layout variables will be removed and replaced with the variables specified.
- Parameters
layout – target layout
variables – new set of layer variables
See also
See also
New in version 3.0.
-
setProjectVariable
(project: QgsProject, name: str, value: Any)¶ Sets a project context variable. This variable will be contained within scopes retrieved via projectScope().
- Parameters
project – Project to apply changes to
name – variable name
value – variable value
See also
See also
See also
-
setProjectVariables
(project: QgsProject, variables: Dict[str, Any])¶ Sets all project context variables. Existing project variables will be removed and replaced with the variables specified.
- Parameters
project – Project to apply changes to
variables – new set of project variables
See also
See also
See also
-
updateSymbolScope
(symbol: QgsSymbol, symbolScope: QgsExpressionContextScope = None) → QgsExpressionContextScope¶ Updates a symbol scope related to a QgsSymbol to an expression context.
- Parameters
symbol – symbol to extract properties from
symbolScope – pointer to an existing scope to update
New in version 2.14.
-