15#ifndef QGSEXPRESSIONCONTEXT_H
16#define QGSEXPRESSIONCONTEXT_H
32class LoadLayerFunction;
98 QSet<QString> mReferencedColumns;
174 QString
name()
const {
return mName; }
183 void setVariable(
const QString &name,
const QVariant &value,
bool isStatic =
false );
200 bool removeVariable(
const QString &name );
209 bool hasVariable(
const QString &name )
const;
218 QVariant variable(
const QString &name )
const;
225 QStringList variableNames()
const;
233 QStringList filteredVariableNames()
const;
241 bool isReadOnly(
const QString &name )
const;
248 bool isStatic(
const QString &name )
const;
255 QString description(
const QString &name )
const;
269 bool hasFunction(
const QString &name )
const;
286 QStringList functionNames()
const;
363 void setFields(
const QgsFields &fields );
377 bool writeXml( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext &context )
const;
388 QStringList hiddenVariables()
const;
400 void setHiddenVariables(
const QStringList &hiddenVariables );
413 void addHiddenVariable(
const QString &hiddenVariable );
424 void removeHiddenVariable(
const QString &hiddenVariable );
444 QList< QgsMapLayerStore * > layerStores()
const;
448 QHash<QString, StaticVariable> mVariables;
449 QHash<QString, QgsScopedExpressionFunction * > mFunctions;
450 bool mHasFeature =
false;
452 bool mHasGeometry =
false;
454 QStringList mHiddenVariables;
456 QList< QPointer< QgsMapLayerStore > > mLayerStores;
512 QVariant
variable(
const QString &name )
const;
606 QList< QgsExpressionContextScope * >
scopes() {
return mStack; }
620 int indexOfScope(
const QString &scopeName )
const;
630 QStringList variableNames()
const;
638 QStringList filteredVariableNames()
const;
646 bool isReadOnly(
const QString &name )
const;
655 QString description(
const QString &name )
const;
663 bool hasFunction(
const QString &name )
const;
670 QStringList functionNames()
const;
685 int scopeCount()
const;
701 void appendScopes(
const QList<QgsExpressionContextScope *> &scopes
SIP_TRANSFER );
715 QList<QgsExpressionContextScope *> takeScopes()
SIP_SKIP;
737 bool hasFeature() const;
760 bool hasGeometry() const;
776 void setFields( const
QgsFields &fields );
789 void setOriginalValueVariable( const QVariant &value );
801 void setCachedValue( const QString &key, const QVariant &value ) const;
810 bool hasCachedValue( const QString &key ) const;
821 QVariant cachedValue( const QString &key ) const;
829 void clearCachedValues() const;
893 QString uniqueHash(
bool &ok
SIP_OUT, const QSet<QString> &variables = QSet<QString>() ) const;
925 QStringList mHighlightedVariables;
926 QStringList mHighlightedFunctions;
930 std::unique_ptr< LoadLayerFunction > mLoadLayerFunction;
934 mutable QMap< QString, QVariant > mCachedValues;
Single scope for storing variables and functions for use within a QgsExpressionContext.
void removeGeometry()
Removes any geometry associated with the scope.
void removeFeature()
Removes any feature associated with the scope.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
bool hasFeature() const
Returns true if the scope has a feature associated with it.
QgsGeometry geometry() const
Sets the geometry associated with the scope.
QString name() const
Returns the friendly display name of the context scope.
int variableCount() const
Returns the count of variables contained within the scope.
bool hasGeometry() const
Returns true if the scope has a geometry associated with it.
void setGeometry(const QgsGeometry &geometry)
Convenience function for setting a geometry for the scope.
QgsFeature feature() const
Sets the feature associated with the scope.
QgsExpressionContextScope & operator=(const QgsExpressionContextScope &other)
QgsExpressionContextScope(const QString &name=QString())
Constructor for QgsExpressionContextScope.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
QStringList highlightedVariables() const
Returns the current list of variables highlighted within the context.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
void setHighlightedFunctions(const QStringList &names)
Sets the list of function names intended to be highlighted to the user.
bool isHighlightedFunction(const QString &name) const
Returns true if the specified function name is intended to be highlighted to the user.
QgsExpressionContext & operator=(const QgsExpressionContext &other)
static const QString EXPR_FIELDS
Inbuilt variable name for fields storage.
static const QString EXPR_GEOMETRY_RING_NUM
Inbuilt variable name for geometry ring number variable.
bool isHighlightedVariable(const QString &name) const
Returns true if the specified variable name is intended to be highlighted to the user.
QgsExpressionContextScope * activeScopeForVariable(const QString &name)
Returns the currently active scope from the context for a specified variable name.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
QList< QgsExpressionContextScope * > scopes()
Returns a list of scopes contained within the stack.
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within the context.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
QVariantMap variablesToMap() const
Returns a map of variable name to value representing all the expression variables contained by the co...
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
QStringList variableNames() const
Returns a list of variables names set by all scopes in the context.
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
QgsExpressionContextScope * scope(int index)
Returns the scope at the specified index within the context.
An abstract base class for defining QgsExpression functions.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
bool isContextual() const
Returns whether the function is only available if provided by a QgsExpressionContext object.
int params() const
The number of parameters this function takes.
QgsExpressionFunction(const QString &fnname, int params, const QString &group, const QString &helpText=QString(), bool lazyEval=false, bool handlesNull=false, bool isContextual=false)
Constructor for function which uses unnamed parameters.
virtual bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const
Will be called during prepare to determine if the function is static.
bool lazyEval() const
true if this function should use lazy evaluation.
QString group() const
Returns the first group which the function belongs to.
virtual QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const
Returns a set of field names which are required for this function.
virtual bool handlesNull() const
Returns true if the function handles NULL values in arguments by itself, and the default NULL value h...
const QString helpText() const
The help text for the function.
virtual bool usesGeometry(const QgsExpressionNodeFunction *node) const
Does this function use a geometry object.
An expression node for expression functions.
Handles parsing and evaluation of expressions (formerly called "search strings").
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
A container for the context for various read/write operations on objects.
Expression function for use within a QgsExpressionContextScope.
QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const override
Returns a set of field names which are required for this function.
virtual QgsScopedExpressionFunction * clone() const =0
Returns a clone of the function.
QgsScopedExpressionFunction(const QString &fnname, int params, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QSet< QString > &referencedColumns=QSet< QString >(), bool lazyEval=false, bool handlesNull=false, bool isContextual=true)
Create a new QgsScopedExpressionFunction.
QgsScopedExpressionFunction(const QString &fnname, const QgsExpressionFunction::ParameterList ¶ms, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QSet< QString > &referencedColumns=QSet< QString >(), bool lazyEval=false, bool handlesNull=false, bool isContextual=true)
Create a new QgsScopedExpressionFunction using named parameters.
bool usesGeometry(const QgsExpressionNodeFunction *node) const override
Does this function use a geometry object.
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override=0
Returns result of evaluating the function.
Single variable definition for use within a QgsExpressionContextScope.
bool readOnly
True if variable should not be editable by users.
StaticVariable(const QString &name=QString(), const QVariant &value=QVariant(), bool readOnly=false, bool isStatic=false, const QString &description=QString())
Constructor for StaticVariable.
bool isStatic
A static variable can be cached for the lifetime of a context.
QString name
Variable name.
QVariant value
Variable value.
QString description
Translated description of variable, for use within expression builder widgets.