QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
Classes | Static Public Member Functions | Friends | List of all members
QgsExpressionContextUtils Class Reference

Contains utilities for working with QgsExpressionContext objects, including methods for creating scopes for specific uses (e.g., project scopes, layer scopes). More...

#include <qgsexpressioncontextutils.h>

Static Public Member Functions

static QgsExpressionContextScopeatlasScope (const QgsLayoutAtlas *atlas)
 Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
 
static QgsExpressionContext createFeatureBasedContext (const QgsFeature &feature, const QgsFields &fields)
 Helper function for creating an expression context which contains just a feature and fields collection.
 
static QgsExpressionContextScopeformScope (const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
 Creates a new scope which contains functions and variables from the current attribute form/table formFeature.
 
static QList< QgsExpressionContextScope * > globalProjectLayerScopes (const QgsMapLayer *layer)
 Creates a list of three scopes: global, layer's project and layer.
 
static QgsExpressionContextScopeglobalScope ()
 Creates a new scope which contains variables and functions relating to the global QGIS context.
 
static QgsExpressionContextScopelayerScope (const QgsMapLayer *layer)
 Creates a new scope which contains variables and functions relating to a QgsMapLayer.
 
static QgsExpressionContextScopelayoutItemScope (const QgsLayoutItem *item)
 Creates a new scope which contains variables and functions relating to a QgsLayoutItem.
 
static QgsExpressionContextScopelayoutScope (const QgsLayout *layout)
 Creates a new scope which contains variables and functions relating to a QgsLayout layout.
 
static QgsExpressionContextScopemapLayerPositionScope (const QgsPointXY &position)
 Sets the expression context variables which are available for expressions triggered by moving the mouse over a feature of the currently selected layer.
 
static QgsExpressionContextScopemapSettingsScope (const QgsMapSettings &mapSettings)
 Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
 
static QgsExpressionContextScopemapToolCaptureScope (const QList< QgsPointLocator::Match > &matches)
 Sets the expression context variables which are available for expressions triggered by a map tool capture like add feature.
 
static QgsExpressionContextScopemeshExpressionScope (QgsMesh::ElementType elementType)
 Creates a new scope which contains functions relating to mesh layer element elementType.
 
static QgsExpressionContextScopemultiFrameScope (const QgsLayoutMultiFrame *frame)
 Creates a new scope which contains variables and functions relating to a QgsLayoutMultiFrame.
 
static QgsExpressionContextScopenotificationScope (const QString &message=QString())
 Creates a new scope which contains variables and functions relating to provider notifications.
 
static QgsExpressionContextScopeparentFormScope (const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
 Creates a new scope which contains functions and variables from the current parent attribute form/table formFeature.
 
static QgsExpressionContextScopeprocessingAlgorithmScope (const QgsProcessingAlgorithm *algorithm, const QVariantMap &parameters, QgsProcessingContext &context)
 Creates a new scope which contains variables and functions relating to a processing algorithm, when used with the specified parameters and context.
 
static QgsExpressionContextScopeprocessingModelAlgorithmScope (const QgsProcessingModelAlgorithm *model, const QVariantMap &parameters, QgsProcessingContext &context)
 Creates a new scope which contains variables and functions relating to a processing model algorithm, when used with the specified parameters and context.
 
static QgsExpressionContextScopeprojectScope (const QgsProject *project)
 Creates a new scope which contains variables and functions relating to a QGIS project.
 
static void registerContextFunctions ()
 Registers all known core functions provided by QgsExpressionContextScope objects.
 
static void removeGlobalVariable (const QString &name)
 Remove a global context variable.
 
static void removeProjectVariable (QgsProject *project, const QString &name)
 Remove project context variable.
 
static void setGlobalVariable (const QString &name, const QVariant &value)
 Sets a global context variable.
 
static void setGlobalVariables (const QVariantMap &variables)
 Sets all global context variables.
 
static void setLayerVariable (QgsMapLayer *layer, const QString &name, const QVariant &value)
 Sets a layer context variable.
 
static void setLayerVariables (QgsMapLayer *layer, const QVariantMap &variables)
 Sets all layer context variables.
 
static void setLayoutItemVariable (QgsLayoutItem *item, const QString &name, const QVariant &value)
 Sets a layout item context variable, with the given name and value.
 
static void setLayoutItemVariables (QgsLayoutItem *item, const QVariantMap &variables)
 Sets all layout item context variables for an item.
 
static void setLayoutMultiFrameVariable (QgsLayoutMultiFrame *frame, const QString &name, const QVariant &value)
 Sets a layout multi frame context variable, with the given name and value.
 
static void setLayoutMultiFrameVariables (QgsLayoutMultiFrame *frame, const QVariantMap &variables)
 Sets all layout multiframe context variables for an frame.
 
static void setLayoutVariable (QgsLayout *layout, const QString &name, const QVariant &value)
 Sets a layout context variable.
 
static void setLayoutVariables (QgsLayout *layout, const QVariantMap &variables)
 Sets all layout context variables.
 
static void setProjectVariable (QgsProject *project, const QString &name, const QVariant &value)
 Sets a project context variable.
 
static void setProjectVariables (QgsProject *project, const QVariantMap &variables)
 Sets all project context variables.
 
static QgsExpressionContextScopeupdateSymbolScope (const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
 Updates a symbol scope related to a QgsSymbol to an expression context.
 

Friends

class QgsLayoutItemMap
 

Detailed Description

Contains utilities for working with QgsExpressionContext objects, including methods for creating scopes for specific uses (e.g., project scopes, layer scopes).

Since
QGIS 2.12

Definition at line 48 of file qgsexpressioncontextutils.h.

Member Function Documentation

◆ atlasScope()

QgsExpressionContextScope * QgsExpressionContextUtils::atlasScope ( const QgsLayoutAtlas atlas)
static

Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.

For instance, current page name and number.

Parameters
atlassource atlas. If nullptr, a set of default atlas variables will be added to the scope.

Definition at line 692 of file qgsexpressioncontextutils.cpp.

◆ createFeatureBasedContext()

QgsExpressionContext QgsExpressionContextUtils::createFeatureBasedContext ( const QgsFeature feature,
const QgsFields fields 
)
static

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.

Definition at line 874 of file qgsexpressioncontextutils.cpp.

◆ formScope()

QgsExpressionContextScope * QgsExpressionContextUtils::formScope ( const QgsFeature formFeature = QgsFeature( ),
const QString &  formMode = QString() 
)
static

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. The formMode (SingleEditMode etc.) is passed as text

Since
QGIS 3.2

Definition at line 294 of file qgsexpressioncontextutils.cpp.

◆ globalProjectLayerScopes()

QList< QgsExpressionContextScope * > QgsExpressionContextUtils::globalProjectLayerScopes ( const QgsMapLayer layer)
static

Creates a list of three scopes: global, layer's project and layer.

Since
QGIS 3.0

Definition at line 402 of file qgsexpressioncontextutils.cpp.

◆ globalScope()

QgsExpressionContextScope * QgsExpressionContextUtils::globalScope ( )
static

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
setGlobalVariable()

Definition at line 45 of file qgsexpressioncontextutils.cpp.

◆ layerScope()

QgsExpressionContextScope * QgsExpressionContextUtils::layerScope ( const QgsMapLayer layer)
static

Creates a new scope which contains variables and functions relating to a QgsMapLayer.

For instance, layer name, id and fields.

Definition at line 358 of file qgsexpressioncontextutils.cpp.

◆ layoutItemScope()

QgsExpressionContextScope * QgsExpressionContextUtils::layoutItemScope ( const QgsLayoutItem item)
static

Creates a new scope which contains variables and functions relating to a QgsLayoutItem.

For instance, item size and position.

See also
setLayoutItemVariable()
setLayoutItemVariables()
Since
QGIS 3.0

Definition at line 731 of file qgsexpressioncontextutils.cpp.

◆ layoutScope()

QgsExpressionContextScope * QgsExpressionContextUtils::layoutScope ( const QgsLayout layout)
static

Creates a new scope which contains variables and functions relating to a QgsLayout layout.

For instance, number of pages and page sizes.

Since
QGIS 3.0

Definition at line 588 of file qgsexpressioncontextutils.cpp.

◆ mapLayerPositionScope()

QgsExpressionContextScope * QgsExpressionContextUtils::mapLayerPositionScope ( const QgsPointXY position)
static

Sets the expression context variables which are available for expressions triggered by moving the mouse over a feature of the currently selected layer.

Parameters
positionmap coordinates of the current pointer position in the CRS of the layer which triggered the action.
Since
QGIS 3.30

Definition at line 563 of file qgsexpressioncontextutils.cpp.

◆ mapSettingsScope()

QgsExpressionContextScope * QgsExpressionContextUtils::mapSettingsScope ( const QgsMapSettings mapSettings)
static

Creates a new scope which contains variables and functions relating to a QgsMapSettings object.

For instance, map scale and rotation.

Definition at line 452 of file qgsexpressioncontextutils.cpp.

◆ mapToolCaptureScope()

QgsExpressionContextScope * QgsExpressionContextUtils::mapToolCaptureScope ( const QList< QgsPointLocator::Match > &  matches)
static

Sets the expression context variables which are available for expressions triggered by a map tool capture like add feature.

Since
QGIS 3.0

Definition at line 539 of file qgsexpressioncontextutils.cpp.

◆ meshExpressionScope()

static QgsExpressionContextScope * QgsExpressionContextUtils::meshExpressionScope ( QgsMesh::ElementType  elementType)
static

Creates a new scope which contains functions relating to mesh layer element elementType.

Since
QGIS 3.22

◆ multiFrameScope()

QgsExpressionContextScope * QgsExpressionContextUtils::multiFrameScope ( const QgsLayoutMultiFrame frame)
static

Creates a new scope which contains variables and functions relating to a QgsLayoutMultiFrame.

See also
setLayoutMultiFrameVariable()
setLayoutMultiFrameVariables()
Since
QGIS 3.10

Definition at line 813 of file qgsexpressioncontextutils.cpp.

◆ notificationScope()

QgsExpressionContextScope * QgsExpressionContextUtils::notificationScope ( const QString &  message = QString())
static

Creates a new scope which contains variables and functions relating to provider notifications.

Parameters
messagethe notification message

Definition at line 930 of file qgsexpressioncontextutils.cpp.

◆ parentFormScope()

QgsExpressionContextScope * QgsExpressionContextUtils::parentFormScope ( const QgsFeature formFeature = QgsFeature( ),
const QString &  formMode = QString() 
)
static

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. The formMode (SingleEditMode etc.) is passed as text

Since
QGIS 3.14

Definition at line 305 of file qgsexpressioncontextutils.cpp.

◆ processingAlgorithmScope()

QgsExpressionContextScope * QgsExpressionContextUtils::processingAlgorithmScope ( const QgsProcessingAlgorithm algorithm,
const QVariantMap &  parameters,
QgsProcessingContext context 
)
static

Creates a new scope which contains variables and functions relating to a processing algorithm, when used with the specified parameters and context.

For instance, algorithm name and parameter functions.

See also
processingModelAlgorithmScope()

Definition at line 882 of file qgsexpressioncontextutils.cpp.

◆ processingModelAlgorithmScope()

QgsExpressionContextScope * QgsExpressionContextUtils::processingModelAlgorithmScope ( const QgsProcessingModelAlgorithm *  model,
const QVariantMap &  parameters,
QgsProcessingContext context 
)
static

Creates a new scope which contains variables and functions relating to a processing model algorithm, when used with the specified parameters and context.

For instance, model name and path variables.

Since
QGIS 3.6

Definition at line 899 of file qgsexpressioncontextutils.cpp.

◆ projectScope()

QgsExpressionContextScope * QgsExpressionContextUtils::projectScope ( const QgsProject project)
static

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
projectWhat project to use
See also
setProjectVariable()

Definition at line 315 of file qgsexpressioncontextutils.cpp.

◆ registerContextFunctions()

void QgsExpressionContextUtils::registerContextFunctions ( )
static

Registers all known core functions provided by QgsExpressionContextScope objects.

Definition at line 937 of file qgsexpressioncontextutils.cpp.

◆ removeGlobalVariable()

void QgsExpressionContextUtils::removeGlobalVariable ( const QString &  name)
static

Remove a global context variable.

Parameters
namevariable name
See also
setGlobalVariable()
setGlobalVariables()
globalScope()

Definition at line 80 of file qgsexpressioncontextutils.cpp.

◆ removeProjectVariable()

void QgsExpressionContextUtils::removeProjectVariable ( QgsProject project,
const QString &  name 
)
static

Remove project context variable.

Parameters
projectProject to apply changes to
namevariable name
See also
setProjectVariable()
setProjectVariables()
projectScope()

Definition at line 346 of file qgsexpressioncontextutils.cpp.

◆ setGlobalVariable()

void QgsExpressionContextUtils::setGlobalVariable ( const QString &  name,
const QVariant &  value 
)
static

Sets a global context variable.

This variable will be contained within scopes retrieved via globalScope().

Parameters
namevariable name
valuevariable value
See also
setGlobalVariable()
globalScope()
removeGlobalVariable()

Definition at line 70 of file qgsexpressioncontextutils.cpp.

◆ setGlobalVariables()

void QgsExpressionContextUtils::setGlobalVariables ( const QVariantMap &  variables)
static

Sets all global context variables.

Existing global variables will be removed and replaced with the variables specified.

Parameters
variablesnew set of global variables
See also
setGlobalVariable()
globalScope()
removeGlobalVariable()

Definition at line 75 of file qgsexpressioncontextutils.cpp.

◆ setLayerVariable()

void QgsExpressionContextUtils::setLayerVariable ( QgsMapLayer layer,
const QString &  name,
const QVariant &  value 
)
static

Sets a layer context variable.

This variable will be contained within scopes retrieved via layerScope().

Parameters
layermap layer
namevariable name
valuevariable value
See also
setLayerVariables()
layerScope()

Definition at line 417 of file qgsexpressioncontextutils.cpp.

◆ setLayerVariables()

void QgsExpressionContextUtils::setLayerVariables ( QgsMapLayer layer,
const QVariantMap &  variables 
)
static

Sets all layer context variables.

Existing layer variables will be removed and replaced with the variables specified.

Parameters
layermap layer
variablesnew set of layer variables
See also
setLayerVariable()
layerScope()

Definition at line 433 of file qgsexpressioncontextutils.cpp.

◆ setLayoutItemVariable()

void QgsExpressionContextUtils::setLayoutItemVariable ( QgsLayoutItem item,
const QString &  name,
const QVariant &  value 
)
static

Sets a layout item context variable, with the given name and value.

This variable will be contained within scopes retrieved via layoutItemScope().

See also
setLayoutItemVariables()
layoutItemScope()
Since
QGIS 3.0

Definition at line 778 of file qgsexpressioncontextutils.cpp.

◆ setLayoutItemVariables()

void QgsExpressionContextUtils::setLayoutItemVariables ( QgsLayoutItem item,
const QVariantMap &  variables 
)
static

Sets all layout item context variables for an item.

Existing variables will be removed and replaced with the variables specified.

See also
setLayoutItemVariable()
layoutItemScope()
Since
QGIS 3.0

Definition at line 794 of file qgsexpressioncontextutils.cpp.

◆ setLayoutMultiFrameVariable()

void QgsExpressionContextUtils::setLayoutMultiFrameVariable ( QgsLayoutMultiFrame frame,
const QString &  name,
const QVariant &  value 
)
static

Sets a layout multi frame context variable, with the given name and value.

This variable will be contained within scopes retrieved via multiFrameScope().

See also
setLayoutItemVariables()
multiFrameScope()
Since
QGIS 3.10

Definition at line 839 of file qgsexpressioncontextutils.cpp.

◆ setLayoutMultiFrameVariables()

void QgsExpressionContextUtils::setLayoutMultiFrameVariables ( QgsLayoutMultiFrame frame,
const QVariantMap &  variables 
)
static

Sets all layout multiframe context variables for an frame.

Existing variables will be removed and replaced with the variables specified.

See also
setLayoutMultiFrameVariable()
multiFrameScope()
Since
QGIS 3.10

Definition at line 855 of file qgsexpressioncontextutils.cpp.

◆ setLayoutVariable()

void QgsExpressionContextUtils::setLayoutVariable ( QgsLayout layout,
const QString &  name,
const QVariant &  value 
)
static

Sets a layout context variable.

This variable will be contained within scopes retrieved via layoutScope().

Parameters
layouttarget layout
namevariable name
valuevariable value
See also
setLayoutVariables()
layoutScope()
Since
QGIS 3.0

Definition at line 657 of file qgsexpressioncontextutils.cpp.

◆ setLayoutVariables()

void QgsExpressionContextUtils::setLayoutVariables ( QgsLayout layout,
const QVariantMap &  variables 
)
static

Sets all layout context variables.

Existing layout variables will be removed and replaced with the variables specified.

Parameters
layouttarget layout
variablesnew set of layer variables
See also
setLayoutVariable()
layoutScope()
Since
QGIS 3.0

Definition at line 673 of file qgsexpressioncontextutils.cpp.

◆ setProjectVariable()

void QgsExpressionContextUtils::setProjectVariable ( QgsProject project,
const QString &  name,
const QVariant &  value 
)
static

Sets a project context variable.

This variable will be contained within scopes retrieved via projectScope().

Parameters
projectProject to apply changes to
namevariable name
valuevariable value
See also
setProjectVariables()
removeProjectVariable()
projectScope()

Definition at line 326 of file qgsexpressioncontextutils.cpp.

◆ setProjectVariables()

void QgsExpressionContextUtils::setProjectVariables ( QgsProject project,
const QVariantMap &  variables 
)
static

Sets all project context variables.

Existing project variables will be removed and replaced with the variables specified.

Parameters
projectProject to apply changes to
variablesnew set of project variables
See also
setProjectVariable()
removeProjectVariable()
projectScope()

Definition at line 338 of file qgsexpressioncontextutils.cpp.

◆ updateSymbolScope()

QgsExpressionContextScope * QgsExpressionContextUtils::updateSymbolScope ( const QgsSymbol symbol,
QgsExpressionContextScope symbolScope = nullptr 
)
static

Updates a symbol scope related to a QgsSymbol to an expression context.

Parameters
symbolsymbol to extract properties from
symbolScopepointer to an existing scope to update
Since
QGIS 2.14

Definition at line 570 of file qgsexpressioncontextutils.cpp.

Friends And Related Symbol Documentation

◆ QgsLayoutItemMap

friend class QgsLayoutItemMap
friend

Definition at line 360 of file qgsexpressioncontextutils.h.


The documentation for this class was generated from the following files: