15 #ifndef QGSEXPRESSIONCONTEXT_H
16 #define QGSEXPRESSIONCONTEXT_H
18 #include "qgis_core.h"
23 #include <QStringList>
49 const QString &helpText = QString(),
50 bool usesGeometry =
false,
51 const QSet<QString> &referencedColumns = QSet<QString>(),
52 bool lazyEval =
false,
53 bool handlesNull =
false,
54 bool isContextual =
true )
56 , mUsesGeometry( usesGeometry )
57 , mReferencedColumns( referencedColumns )
68 const QString &helpText = QString(),
69 bool usesGeometry =
false,
70 const QSet<QString> &referencedColumns = QSet<QString>(),
71 bool lazyEval =
false,
72 bool handlesNull =
false,
73 bool isContextual =
true )
75 , mUsesGeometry( usesGeometry )
76 , mReferencedColumns( referencedColumns )
94 QSet<QString> mReferencedColumns;
129 StaticVariable(
const QString &name = QString(),
const QVariant &value = QVariant(),
bool readOnly =
false,
bool isStatic =
false,
const QString &description = QString() )
132 , readOnly( readOnly )
133 , isStatic( isStatic )
134 , description( description )
171 QString
name()
const {
return mName; }
180 void setVariable(
const QString &name,
const QVariant &value,
bool isStatic =
false );
197 bool removeVariable(
const QString &name );
206 bool hasVariable(
const QString &name )
const;
215 QVariant variable(
const QString &name )
const;
222 QStringList variableNames()
const;
230 QStringList filteredVariableNames()
const;
238 bool isReadOnly(
const QString &name )
const;
246 bool isStatic(
const QString &name )
const;
254 QString description(
const QString &name )
const;
268 bool hasFunction(
const QString &name )
const;
285 QStringList functionNames()
const;
332 void setFields(
const QgsFields &fields );
346 bool writeXml( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext &context )
const;
350 QHash<QString, StaticVariable> mVariables;
351 QHash<QString, QgsScopedExpressionFunction * > mFunctions;
352 bool mHasFeature =
false;
401 bool hasVariable(
const QString &name )
const;
412 QVariant variable(
const QString &name )
const;
419 QVariantMap variablesToMap()
const;
428 bool isHighlightedVariable(
const QString &name )
const;
436 QStringList highlightedVariables()
const;
445 void setHighlightedVariables(
const QStringList &variableNames );
455 bool isHighlightedFunction(
const QString &name )
const;
468 void setHighlightedFunctions(
const QStringList &names );
507 QList< QgsExpressionContextScope * >
scopes() {
return mStack; }
522 int indexOfScope(
const QString &scopeName )
const;
532 QStringList variableNames()
const;
540 QStringList filteredVariableNames()
const;
548 bool isReadOnly(
const QString &name )
const;
558 QString description(
const QString &name )
const;
566 bool hasFunction(
const QString &name )
const;
573 QStringList functionNames()
const;
588 int scopeCount()
const;
605 void appendScopes(
const QList<QgsExpressionContextScope *> &scopes
SIP_TRANSFER );
620 QList<QgsExpressionContextScope *> takeScopes()
SIP_SKIP;
643 bool hasFeature() const;
658 void setFields( const
QgsFields &fields );
672 void setOriginalValueVariable( const QVariant &value );
685 void setCachedValue( const QString &key, const QVariant &value ) const;
695 bool hasCachedValue( const QString &key ) const;
707 QVariant cachedValue( const QString &key ) const;
716 void clearCachedValues() const;
719 static const QString EXPR_FIELDS;
721 static const QString EXPR_ORIGINAL_VALUE;
723 static const QString EXPR_SYMBOL_COLOR;
725 static const QString EXPR_SYMBOL_ANGLE;
727 static const QString EXPR_GEOMETRY_PART_COUNT;
729 static const QString EXPR_GEOMETRY_PART_NUM;
735 static const QString EXPR_GEOMETRY_RING_NUM;
737 static const QString EXPR_GEOMETRY_POINT_COUNT;
739 static const QString EXPR_GEOMETRY_POINT_NUM;
741 static const QString EXPR_CLUSTER_SIZE;
743 static const QString EXPR_CLUSTER_COLOR;
748 QStringList mHighlightedVariables;
749 QStringList mHighlightedFunctions;
752 mutable QMap< QString, QVariant > mCachedValues;
Single scope for storing variables and functions for use within a QgsExpressionContext.
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.
QString name() const
Returns the friendly display name of the context scope.
int variableCount() const
Returns the count of variables contained within the scope.
QgsFeature feature() const
Sets the feature associated with the scope.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContext()=default
Constructor for QgsExpressionContext.
QList< QgsExpressionContextScope * > scopes()
Returns a list of scopes contained within the stack.
A abstract base class for defining QgsExpression functions.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
virtual bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const
Will be called during prepare to determine if the function is static.
QString name() const
The name of the function.
virtual QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const
Returns a set of field names which are required for this function.
virtual bool usesGeometry(const QgsExpressionNodeFunction *node) const
Does this function use a geometry object.
An expression node for expression functions.
Class for 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...
Container of fields for a vector layer.
The class is used as a container of context for various read/write operations on other objects.
Expression function for use within a QgsExpressionContextScope.
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.
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override=0
Returns result of evaluating the function.
virtual QgsScopedExpressionFunction * clone() const =0
Returns a clone of 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.