QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Static Public Member Functions | List of all members
QgsExpressionContextUtils Class Reference

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

#include <qgsexpressioncontext.h>

Static Public Member Functions

static QgsExpressionContextScopeatlasScope (const QgsAtlasComposition *atlas)
 Creates a new scope which contains variables and functions relating to a QgsAtlasComposition. More...
 
static QgsExpressionContextScopecomposerItemScope (const QgsComposerItem *composerItem)
 Creates a new scope which contains variables and functions relating to a QgsComposerItem. More...
 
static QgsExpressionContextScopecompositionScope (const QgsComposition *composition)
 Creates a new scope which contains variables and functions relating to a QgsComposition. More...
 
static QgsExpressionContext createFeatureBasedContext (const QgsFeature &feature, const QgsFields &fields)
 Helper function for creating an expression context which contains just a feature and fields collection. More...
 
static QgsExpressionContextScopeglobalScope ()
 Creates a new scope which contains variables and functions relating to the global QGIS context. More...
 
static QgsExpressionContextScopelayerScope (const QgsMapLayer *layer)
 Creates a new scope which contains variables and functions relating to a QgsMapLayer. More...
 
static QgsExpressionContextScopemapSettingsScope (const QgsMapSettings &mapSettings)
 Creates a new scope which contains variables and functions relating to a QgsMapSettings object. More...
 
static QgsExpressionContextScopeprojectScope ()
 Creates a new scope which contains variables and functions relating to the current QGIS project. More...
 
static void registerContextFunctions ()
 Registers all known core functions provided by QgsExpressionContextScope objects. More...
 
static void setComposerItemVariable (QgsComposerItem *composerItem, const QString &name, const QVariant &value)
 Sets a composer item context variable. More...
 
static void setComposerItemVariables (QgsComposerItem *composerItem, const QgsStringMap &variables)
 Sets all composition context variables. More...
 
static void setCompositionVariable (QgsComposition *composition, const QString &name, const QVariant &value)
 Sets a composition context variable. More...
 
static void setCompositionVariables (QgsComposition *composition, const QgsStringMap &variables)
 Sets all composition context variables. More...
 
static void setGlobalVariable (const QString &name, const QVariant &value)
 Sets a global context variable. More...
 
static void setGlobalVariables (const QgsStringMap &variables)
 Sets all global context variables. More...
 
static void setLayerVariable (QgsMapLayer *layer, const QString &name, const QVariant &value)
 Sets a layer context variable. More...
 
static void setLayerVariables (QgsMapLayer *layer, const QgsStringMap &variables)
 Sets all layer context variables. More...
 
static void setProjectVariable (const QString &name, const QVariant &value)
 Sets a project context variable. More...
 
static void setProjectVariables (const QgsStringMap &variables)
 Sets all project context variables. More...
 
static QgsExpressionContextScopeupdateSymbolScope (const QgsSymbolV2 *symbol, QgsExpressionContextScope *symbolScope=nullptr)
 Updates a symbol scope related to a QgsSymbolV2 to an expression context. More...
 

Detailed Description

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

Note
added in QGIS 2.12

Definition at line 520 of file qgsexpressioncontext.h.

Member Function Documentation

◆ atlasScope()

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

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

For instance, current page name and number.

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

Definition at line 856 of file qgsexpressioncontext.cpp.

◆ composerItemScope()

QgsExpressionContextScope * QgsExpressionContextUtils::composerItemScope ( const QgsComposerItem composerItem)
static

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

For instance, item size and position.

Parameters
composerItemsource composer item

Definition at line 893 of file qgsexpressioncontext.cpp.

◆ compositionScope()

QgsExpressionContextScope * QgsExpressionContextUtils::compositionScope ( const QgsComposition composition)
static

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

For instance, number of pages and page sizes.

Parameters
compositionsource composition

Definition at line 789 of file qgsexpressioncontext.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 959 of file qgsexpressioncontext.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 482 of file qgsexpressioncontext.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 676 of file qgsexpressioncontext.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 751 of file qgsexpressioncontext.cpp.

◆ projectScope()

QgsExpressionContextScope * QgsExpressionContextUtils::projectScope ( )
static

Creates a new scope which contains variables and functions relating to the current QGIS project.

For instance, project path and title, and variables specified through the project properties.

See also
setProjectVariable()

Definition at line 609 of file qgsexpressioncontext.cpp.

◆ registerContextFunctions()

void QgsExpressionContextUtils::registerContextFunctions ( )
static

Registers all known core functions provided by QgsExpressionContextScope objects.

Definition at line 967 of file qgsexpressioncontext.cpp.

◆ setComposerItemVariable()

void QgsExpressionContextUtils::setComposerItemVariable ( QgsComposerItem composerItem,
const QString name,
const QVariant value 
)
static

Sets a composer item context variable.

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

Parameters
composerItemtarget composer item
namevariable name
valuevariable value
See also
setComposerItemVariables()
composerItemScope()

Definition at line 924 of file qgsexpressioncontext.cpp.

◆ setComposerItemVariables()

void QgsExpressionContextUtils::setComposerItemVariables ( QgsComposerItem composerItem,
const QgsStringMap variables 
)
static

Sets all composition context variables.

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

Parameters
composerItemtarget composer item
variablesnew set of layer variables
See also
setComposerItemVariable()
composerItemScope()

Definition at line 940 of file qgsexpressioncontext.cpp.

◆ setCompositionVariable()

void QgsExpressionContextUtils::setCompositionVariable ( QgsComposition composition,
const QString name,
const QVariant value 
)
static

Sets a composition context variable.

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

Parameters
compositiontarget composition
namevariable name
valuevariable value
See also
setCompositionVariables()
compositionScope()

Definition at line 821 of file qgsexpressioncontext.cpp.

◆ setCompositionVariables()

void QgsExpressionContextUtils::setCompositionVariables ( QgsComposition composition,
const QgsStringMap variables 
)
static

Sets all composition context variables.

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

Parameters
compositiontarget composition
variablesnew set of layer variables
See also
setCompositionVariable()
compositionScope()

Definition at line 837 of file qgsexpressioncontext.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()

Definition at line 523 of file qgsexpressioncontext.cpp.

◆ setGlobalVariables()

void QgsExpressionContextUtils::setGlobalVariables ( const QgsStringMap 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()

Definition at line 538 of file qgsexpressioncontext.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 716 of file qgsexpressioncontext.cpp.

◆ setLayerVariables()

void QgsExpressionContextUtils::setLayerVariables ( QgsMapLayer layer,
const QgsStringMap 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 732 of file qgsexpressioncontext.cpp.

◆ setProjectVariable()

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

Sets a project context variable.

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

Parameters
namevariable name
valuevariable value
See also
setProjectVariables()
projectScope()

Definition at line 642 of file qgsexpressioncontext.cpp.

◆ setProjectVariables()

void QgsExpressionContextUtils::setProjectVariables ( const QgsStringMap variables)
static

Sets all project context variables.

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

Parameters
variablesnew set of project variables
See also
setProjectVariable()
projectScope()

Definition at line 657 of file qgsexpressioncontext.cpp.

◆ updateSymbolScope()

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

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

Parameters
symbolsymbol to extract properties from
symbolScopepointer to an existing scope to update
Note
added in QGIS 2.14

Definition at line 771 of file qgsexpressioncontext.cpp.


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