QGIS API Documentation 3.41.0-Master (af5edcb665c)
|
Single scope for storing variables and functions for use within a QgsExpressionContext. More...
#include <qgsexpressioncontext.h>
Classes | |
struct | StaticVariable |
Single variable definition for use within a QgsExpressionContextScope. More... | |
Public Member Functions | |
QgsExpressionContextScope (const QgsExpressionContextScope &other) | |
QgsExpressionContextScope (const QString &name=QString()) | |
Constructor for QgsExpressionContextScope. | |
~QgsExpressionContextScope () | |
void | addFunction (const QString &name, QgsScopedExpressionFunction *function) |
Adds a function to the scope. | |
void | addHiddenVariable (const QString &hiddenVariable) |
Adds the passed variable to a list of hidden variables that won't be visible in the expression builder dialog and widget. | |
void | addLayerStore (QgsMapLayerStore *store) |
Adds a layer store to the scope. | |
void | addVariable (const QgsExpressionContextScope::StaticVariable &variable) |
Adds a variable into the context scope. | |
QString | description (const QString &name) const |
Returns the translated description for the variable with the specified name (if set). | |
QgsFeature | feature () const |
Sets the feature associated with the scope. | |
QStringList | filteredVariableNames () const |
Returns a filtered and sorted list of variable names contained within the scope. | |
QgsExpressionFunction * | function (const QString &name) const |
Retrieves a function from the scope. | |
QStringList | functionNames () const |
Retrieves a list of names of functions contained in the scope. | |
QgsGeometry | geometry () const |
Sets the geometry associated with the scope. | |
bool | hasFeature () const |
Returns true if the scope has a feature associated with it. | |
bool | hasFunction (const QString &name) const |
Tests whether a function with the specified name exists in the scope. | |
bool | hasGeometry () const |
Returns true if the scope has a geometry associated with it. | |
bool | hasVariable (const QString &name) const |
Tests whether a variable with the specified name exists in the scope. | |
QStringList | hiddenVariables () const |
Returns the list of variables hidden within the scope. | |
bool | isReadOnly (const QString &name) const |
Tests whether the specified variable is read only and should not be editable by users. | |
bool | isStatic (const QString &name) const |
Tests whether the variable with the specified name is static and can be cached. | |
QList< QgsMapLayerStore * > | layerStores () const |
Returns the list of layer stores associated with the scope. | |
QString | name () const |
Returns the friendly display name of the context scope. | |
QgsExpressionContextScope & | operator= (const QgsExpressionContextScope &other) |
void | readXml (const QDomElement &element, const QgsReadWriteContext &context) |
Reads scope variables from an XML element. | |
void | removeFeature () |
Removes any feature associated with the scope. | |
void | removeGeometry () |
Removes any geometry associated with the scope. | |
void | removeHiddenVariable (const QString &hiddenVariable) |
Removes the passed variable from a list of hidden variables. | |
bool | removeVariable (const QString &name) |
Removes a variable from the context scope, if found. | |
void | setFeature (const QgsFeature &feature) |
Convenience function for setting a feature for the scope. | |
void | setFields (const QgsFields &fields) |
Convenience function for setting a fields for the scope. | |
void | setGeometry (const QgsGeometry &geometry) |
Convenience function for setting a geometry for the scope. | |
void | setHiddenVariables (const QStringList &hiddenVariables) |
Sets the list of variables intended to be hidden in the expression builder dialog and widget. | |
void | setVariable (const QString &name, const QVariant &value, bool isStatic=false) |
Convenience method for setting a variable in the context scope by name name and value. | |
QVariant | variable (const QString &name) const |
Retrieves a variable's value from the scope. | |
int | variableCount () const |
Returns the count of variables contained within the scope. | |
QStringList | variableNames () const |
Returns a list of variable names contained within the scope. | |
bool | writeXml (QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const |
Writes scope variables to an XML element. | |
Single scope for storing variables and functions for use within a QgsExpressionContext.
Examples include a project's scope, which could contain information about the current project such as the project file's location. QgsExpressionContextScope can encapsulate both variables (static values) and functions(which are calculated only when an expression is evaluated).
See QgsExpressionContextUtils for helper methods for working with QgsExpressionContextScope objects.
Definition at line 114 of file qgsexpressioncontext.h.
QgsExpressionContextScope::QgsExpressionContextScope | ( | const QString & | name = QString() | ) |
Constructor for QgsExpressionContextScope.
name | friendly display name for the context scope |
Definition at line 38 of file qgsexpressioncontext.cpp.
QgsExpressionContextScope::QgsExpressionContextScope | ( | const QgsExpressionContextScope & | other | ) |
Definition at line 44 of file qgsexpressioncontext.cpp.
QgsExpressionContextScope::~QgsExpressionContextScope | ( | ) |
Definition at line 83 of file qgsexpressioncontext.cpp.
void QgsExpressionContextScope::addFunction | ( | const QString & | name, |
QgsScopedExpressionFunction * | function | ||
) |
Adds a function to the scope.
name | function name |
function | function to insert. Ownership is transferred to the scope. |
Definition at line 249 of file qgsexpressioncontext.cpp.
void QgsExpressionContextScope::addHiddenVariable | ( | const QString & | hiddenVariable | ) |
Adds the passed variable to a list of hidden variables that won't be visible in the expression builder dialog and widget.
Definition at line 150 of file qgsexpressioncontext.cpp.
void QgsExpressionContextScope::addLayerStore | ( | QgsMapLayerStore * | store | ) |
Adds a layer store to the scope.
Ownership of the store is not transferred to the scope, it is the caller's responsibility to ensure that the store remains alive for the duration of the expression context.
Definition at line 162 of file qgsexpressioncontext.cpp.
void QgsExpressionContextScope::addVariable | ( | const QgsExpressionContextScope::StaticVariable & | variable | ) |
Adds a variable into the context scope.
If a variable with the same name is already set then its value is overwritten, otherwise a new variable is added to the scope.
variable | definition of variable to insert |
Definition at line 102 of file qgsexpressioncontext.cpp.
QString QgsExpressionContextScope::description | ( | const QString & | name | ) | const |
Returns the translated description for the variable with the specified name (if set).
Definition at line 229 of file qgsexpressioncontext.cpp.
|
inline |
Sets the feature associated with the scope.
Definition at line 304 of file qgsexpressioncontext.h.
QStringList QgsExpressionContextScope::filteredVariableNames | ( | ) | const |
Returns a filtered and sorted list of variable names contained within the scope.
Hidden variable names will be excluded, and the list will be sorted so that read only variables are listed first.
Definition at line 201 of file qgsexpressioncontext.cpp.
QgsExpressionFunction * QgsExpressionContextScope::function | ( | const QString & | name | ) | const |
Retrieves a function from the scope.
name | function name |
nullptr
if matching function could not be found Definition at line 239 of file qgsexpressioncontext.cpp.
QStringList QgsExpressionContextScope::functionNames | ( | ) | const |
Retrieves a list of names of functions contained in the scope.
Definition at line 244 of file qgsexpressioncontext.cpp.
|
inline |
Sets the geometry associated with the scope.
Definition at line 335 of file qgsexpressioncontext.h.
|
inline |
Returns true
if the scope has a feature associated with it.
Definition at line 297 of file qgsexpressioncontext.h.
bool QgsExpressionContextScope::hasFunction | ( | const QString & | name | ) | const |
Tests whether a function with the specified name exists in the scope.
name | function name |
true
if matching function was found in the scope Definition at line 234 of file qgsexpressioncontext.cpp.
|
inline |
Returns true
if the scope has a geometry associated with it.
Definition at line 327 of file qgsexpressioncontext.h.
bool QgsExpressionContextScope::hasVariable | ( | const QString & | name | ) | const |
Tests whether a variable with the specified name exists in the scope.
name | variable name |
true
if matching variable was found in the scope Definition at line 116 of file qgsexpressioncontext.cpp.
QStringList QgsExpressionContextScope::hiddenVariables | ( | ) | const |
Returns the list of variables hidden within the scope.
Definition at line 140 of file qgsexpressioncontext.cpp.
bool QgsExpressionContextScope::isReadOnly | ( | const QString & | name | ) | const |
Tests whether the specified variable is read only and should not be editable by users.
name | variable name |
true
if variable is read only Definition at line 219 of file qgsexpressioncontext.cpp.
bool QgsExpressionContextScope::isStatic | ( | const QString & | name | ) | const |
Tests whether the variable with the specified name is static and can be cached.
Definition at line 224 of file qgsexpressioncontext.cpp.
QList< QgsMapLayerStore * > QgsExpressionContextScope::layerStores | ( | ) | const |
Returns the list of layer stores associated with the scope.
Definition at line 167 of file qgsexpressioncontext.cpp.
|
inline |
Returns the friendly display name of the context scope.
Definition at line 171 of file qgsexpressioncontext.h.
QgsExpressionContextScope & QgsExpressionContextScope::operator= | ( | const QgsExpressionContextScope & | other | ) |
Definition at line 61 of file qgsexpressioncontext.cpp.
void QgsExpressionContextScope::readXml | ( | const QDomElement & | element, |
const QgsReadWriteContext & | context | ||
) |
Reads scope variables from an XML element.
Definition at line 260 of file qgsexpressioncontext.cpp.
|
inline |
Removes any feature associated with the scope.
Definition at line 320 of file qgsexpressioncontext.h.
|
inline |
Removes any geometry associated with the scope.
Definition at line 353 of file qgsexpressioncontext.h.
void QgsExpressionContextScope::removeHiddenVariable | ( | const QString & | hiddenVariable | ) |
Removes the passed variable from a list of hidden variables.
Definition at line 156 of file qgsexpressioncontext.cpp.
bool QgsExpressionContextScope::removeVariable | ( | const QString & | name | ) |
Removes a variable from the context scope, if found.
name | name of variable to remove |
true
if variable was removed from the scope, false
if matching variable was not found within the scope Definition at line 107 of file qgsexpressioncontext.cpp.
|
inline |
Convenience function for setting a feature for the scope.
Any existing feature set by the scope will be overwritten.
feature | feature for scope |
Definition at line 313 of file qgsexpressioncontext.h.
void QgsExpressionContextScope::setFields | ( | const QgsFields & | fields | ) |
Convenience function for setting a fields for the scope.
Any existing fields set by the scope will be overwritten.
fields | fields for scope |
Definition at line 255 of file qgsexpressioncontext.cpp.
|
inline |
Convenience function for setting a geometry for the scope.
Any existing geometry set by the scope will be overwritten.
Definition at line 345 of file qgsexpressioncontext.h.
void QgsExpressionContextScope::setHiddenVariables | ( | const QStringList & | hiddenVariables | ) |
Sets the list of variables intended to be hidden in the expression builder dialog and widget.
Definition at line 145 of file qgsexpressioncontext.cpp.
void QgsExpressionContextScope::setVariable | ( | const QString & | name, |
const QVariant & | value, | ||
bool | isStatic = false |
||
) |
Convenience method for setting a variable in the context scope by name name and value.
If a variable with the same name is already set then its value is overwritten, otherwise a new variable is added to the scope. If the isStatic parameter is set to true
, this variable can be cached during the execution of QgsExpression::prepare().
Definition at line 88 of file qgsexpressioncontext.cpp.
QVariant QgsExpressionContextScope::variable | ( | const QString & | name | ) | const |
Retrieves a variable's value from the scope.
name | variable name |
Definition at line 121 of file qgsexpressioncontext.cpp.
|
inline |
Returns the count of variables contained within the scope.
Definition at line 257 of file qgsexpressioncontext.h.
QStringList QgsExpressionContextScope::variableNames | ( | ) | const |
Returns a list of variable names contained within the scope.
Definition at line 126 of file qgsexpressioncontext.cpp.
bool QgsExpressionContextScope::writeXml | ( | QDomElement & | element, |
QDomDocument & | document, | ||
const QgsReadWriteContext & | context | ||
) | const |
Writes scope variables to an XML element.
Definition at line 278 of file qgsexpressioncontext.cpp.