QGIS API Documentation  2.12.0-Lyon
Public Member Functions | Static Public Attributes | List of all members
QgsExpressionContext Class Reference

Expression contexts are used to encapsulate the parameters around which a QgsExpression should be evaluated. More...

#include <qgsexpressioncontext.h>

Public Member Functions

 QgsExpressionContext ()
 
 QgsExpressionContext (const QgsExpressionContext &other)
 Copy constructor. More...
 
 ~QgsExpressionContext ()
 
QgsExpressionContextScopeactiveScopeForVariable (const QString &name)
 Returns the currently active scope from the context for a specified variable name. More...
 
const QgsExpressionContextScopeactiveScopeForVariable (const QString &name) const
 Returns the currently active scope from the context for a specified variable name. More...
 
void appendScope (QgsExpressionContextScope *scope)
 Appends a scope to the end of the context. More...
 
QgsFeature feature () const
 Convenience function for retrieving the feature for the context, if set. More...
 
QgsFields fields () const
 Convenience function for retrieving the fields for the context, if set. More...
 
QStringList filteredVariableNames () const
 Returns a filtered list of variables names set by all scopes in the context. More...
 
QgsExpression::Functionfunction (const QString &name) const
 Fetches a matching function from the context. More...
 
QStringList functionNames () const
 Retrieves a list of function names contained in the context. More...
 
bool hasFunction (const QString &name) const
 Checks whether a specified function is contained in the context. More...
 
bool hasVariable (const QString &name) const
 Check whether a variable is specified by any scope within the context. More...
 
int indexOfScope (QgsExpressionContextScope *scope) const
 Returns the index of the specified scope if it exists within the context. More...
 
bool isHighlightedVariable (const QString &name) const
 Returns true if the specified variable name is intended to be highlighted to the user. More...
 
bool isReadOnly (const QString &name) const
 Returns whether a variable is read only, and should not be modifiable by users. More...
 
QgsExpressionContextScopelastScope ()
 Returns the last scope added to the context. More...
 
QgsExpressionContextoperator<< (QgsExpressionContextScope *scope)
 Appends a scope to the end of the context. More...
 
QgsExpressionContextoperator= (const QgsExpressionContext &other)
 
QgsExpressionContextScopescope (int index)
 Returns the scope at the specified index within the context. More...
 
int scopeCount () const
 Returns the number of scopes contained in the context. More...
 
QList< QgsExpressionContextScope * > scopes ()
 Returns a list of scopes contained within the stack. More...
 
void setFeature (const QgsFeature &feature)
 Convenience function for setting a feature for the context. More...
 
void setFields (const QgsFields &fields)
 Convenience function for setting a fields for the context. More...
 
void setHighlightedVariables (const QStringList &variableNames)
 Sets the list of variable names within the context intended to be highlighted to the user. More...
 
void setOriginalValueVariable (const QVariant &value)
 Sets the original value variable value for the context. More...
 
QVariant variable (const QString &name) const
 Fetches a matching variable from the context. More...
 
QStringList variableNames () const
 Returns a list of variables names set by all scopes in the context. More...
 

Static Public Attributes

static const QString EXPR_FEATURE
 
static const QString EXPR_FIELDS
 
static const QString EXPR_ORIGINAL_VALUE
 

Detailed Description

Expression contexts are used to encapsulate the parameters around which a QgsExpression should be evaluated.

QgsExpressions can then utilise the information stored within a context to contextualise their evaluated result. A QgsExpressionContext consists of a stack of QgsExpressionContextScope objects, where scopes added later to the stack will override conflicting variables and functions from scopes lower in the stack.

Note
added in QGIS 2.12

Definition at line 239 of file qgsexpressioncontext.h.

Constructor & Destructor Documentation

QgsExpressionContext::QgsExpressionContext ( )
inline

Definition at line 243 of file qgsexpressioncontext.h.

QgsExpressionContext::QgsExpressionContext ( const QgsExpressionContext other)

Copy constructor.

Definition at line 201 of file qgsexpressioncontext.cpp.

QgsExpressionContext::~QgsExpressionContext ( )

Definition at line 222 of file qgsexpressioncontext.cpp.

Member Function Documentation

QgsExpressionContextScope * QgsExpressionContext::activeScopeForVariable ( const QString name)

Returns the currently active scope from the context for a specified variable name.

As scopes later in the stack override earlier contexts, this will be the last matching scope which contains a matching variable.

Parameters
namevariable name
Returns
matching scope containing variable, or null if none found

Definition at line 267 of file qgsexpressioncontext.cpp.

const QgsExpressionContextScope * QgsExpressionContext::activeScopeForVariable ( const QString name) const

Returns the currently active scope from the context for a specified variable name.

As scopes later in the stack override earlier contexts, this will be the last matching scope which contains a matching variable.

Parameters
namevariable name
Returns
matching scope containing variable, or null if none found

Definition at line 254 of file qgsexpressioncontext.cpp.

void QgsExpressionContext::appendScope ( QgsExpressionContextScope scope)

Appends a scope to the end of the context.

This scope will override any matching variables or functions provided by existing scopes within the context. Ownership of the scope is transferred to the stack.

Parameters
scopeexpression context to append to context

Definition at line 380 of file qgsexpressioncontext.cpp.

QgsFeature QgsExpressionContext::feature ( ) const

Convenience function for retrieving the feature for the context, if set.

See also
setFeature

Definition at line 399 of file qgsexpressioncontext.cpp.

QgsFields QgsExpressionContext::fields ( ) const

Convenience function for retrieving the fields for the context, if set.

See also
setFields

Definition at line 412 of file qgsexpressioncontext.cpp.

QStringList QgsExpressionContext::filteredVariableNames ( ) const

Returns a filtered list of variables names set by all scopes in the context.

The included variables are those which should be seen by users.

Returns
filtered list of unique variable names
See also
variableNames

Definition at line 314 of file qgsexpressioncontext.cpp.

QgsExpression::Function * QgsExpressionContext::function ( const QString name) const

Fetches a matching function from the context.

The function will be fetched from the last scope contained within the context which has a matching function set.

Parameters
namefunction name
Returns
function if contained by the context, otherwise null.
See also
hasFunction

Definition at line 362 of file qgsexpressioncontext.cpp.

QStringList QgsExpressionContext::functionNames ( ) const

Retrieves a list of function names contained in the context.

See also
function()
variableNames()

Definition at line 350 of file qgsexpressioncontext.cpp.

bool QgsExpressionContext::hasFunction ( const QString name) const

Checks whether a specified function is contained in the context.

Parameters
namefunction name
Returns
true if context provides a matching function
See also
function

Definition at line 340 of file qgsexpressioncontext.cpp.

bool QgsExpressionContext::hasVariable ( const QString name) const

Check whether a variable is specified by any scope within the context.

Parameters
namevariable name
Returns
true if variable is set
See also
variable()
variableNames()

Definition at line 228 of file qgsexpressioncontext.cpp.

int QgsExpressionContext::indexOfScope ( QgsExpressionContextScope scope) const

Returns the index of the specified scope if it exists within the context.

Parameters
scopescope to find
Returns
index of scope, or -1 if scope was not found within the context.

Definition at line 296 of file qgsexpressioncontext.cpp.

bool QgsExpressionContext::isHighlightedVariable ( const QString name) const

Returns true if the specified variable name is intended to be highlighted to the user.

This is used by the expression builder to more prominently display the variable.

Parameters
namevariable name
See also
setHighlightedVariables()

Definition at line 244 of file qgsexpressioncontext.cpp.

bool QgsExpressionContext::isReadOnly ( const QString name) const

Returns whether a variable is read only, and should not be modifiable by users.

Parameters
namevariable name
Returns
true if variable is read only. Read only status will be taken from last matching scope which contains a matching variable.

Definition at line 330 of file qgsexpressioncontext.cpp.

QgsExpressionContextScope * QgsExpressionContext::lastScope ( )

Returns the last scope added to the context.

See also
scope()

Definition at line 288 of file qgsexpressioncontext.cpp.

QgsExpressionContext & QgsExpressionContext::operator<< ( QgsExpressionContextScope scope)

Appends a scope to the end of the context.

This scope will override any matching variables or functions provided by existing scopes within the context. Ownership of the scope is transferred to the stack.

Definition at line 385 of file qgsexpressioncontext.cpp.

QgsExpressionContext & QgsExpressionContext::operator= ( const QgsExpressionContext other)

Definition at line 210 of file qgsexpressioncontext.cpp.

QgsExpressionContextScope * QgsExpressionContext::scope ( int  index)

Returns the scope at the specified index within the context.

Parameters
indexindex of scope
Returns
matching scope, or null if none found
See also
lastScope()

Definition at line 280 of file qgsexpressioncontext.cpp.

int QgsExpressionContext::scopeCount ( ) const

Returns the number of scopes contained in the context.

Definition at line 375 of file qgsexpressioncontext.cpp.

QList< QgsExpressionContextScope* > QgsExpressionContext::scopes ( )
inline

Returns a list of scopes contained within the stack.

Returns
list of pointers to scopes

Definition at line 317 of file qgsexpressioncontext.h.

void QgsExpressionContext::setFeature ( const QgsFeature feature)

Convenience function for setting a feature for the context.

The feature will be set within the last scope of the context, so will override any existing features within the context.

Parameters
featurefeature for context
See also
feature()

Definition at line 391 of file qgsexpressioncontext.cpp.

void QgsExpressionContext::setFields ( const QgsFields fields)

Convenience function for setting a fields for the context.

The fields will be set within the last scope of the context, so will override any existing fields within the context.

Parameters
fieldsfields for context
See also
fields()

Definition at line 404 of file qgsexpressioncontext.cpp.

void QgsExpressionContext::setHighlightedVariables ( const QStringList variableNames)

Sets the list of variable names within the context intended to be highlighted to the user.

This is used by the expression builder to more prominently display these variables.

Parameters
variableNamesvariable names to highlight
See also
isHighlightedVariable()

Definition at line 249 of file qgsexpressioncontext.cpp.

void QgsExpressionContext::setOriginalValueVariable ( const QVariant value)

Sets the original value variable value for the context.

Parameters
valuevalue for original value variable. This usually represents the an original widget value before any data defined overrides have been applied.
Note
added in QGIS 2.12

Definition at line 417 of file qgsexpressioncontext.cpp.

QVariant QgsExpressionContext::variable ( const QString name) const

Fetches a matching variable from the context.

The variable will be fetched from the last scope contained within the context which has a matching variable set.

Parameters
namevariable name
Returns
variable value if matching variable exists in the context, otherwise an invalid QVariant
See also
hasVariable()
variableNames()

Definition at line 238 of file qgsexpressioncontext.cpp.

QStringList QgsExpressionContext::variableNames ( ) const

Returns a list of variables names set by all scopes in the context.

Returns
list of unique variable names
See also
filteredVariableNames
functionNames
hasVariable
variable

Definition at line 304 of file qgsexpressioncontext.cpp.

Member Data Documentation

const QString QgsExpressionContext::EXPR_FEATURE
static

Definition at line 421 of file qgsexpressioncontext.h.

const QString QgsExpressionContext::EXPR_FIELDS
static

Definition at line 420 of file qgsexpressioncontext.h.

const QString QgsExpressionContext::EXPR_ORIGINAL_VALUE
static

Definition at line 422 of file qgsexpressioncontext.h.


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