15#ifndef QGSEXPRESSIONCONTEXT_H
16#define QGSEXPRESSIONCONTEXT_H
32class LoadLayerFunction;
54 const QString &helpText = QString(),
55 bool usesGeometry =
false,
56 const QSet<QString> &referencedColumns = QSet<QString>(),
57 bool lazyEval =
false,
58 bool handlesNull =
false,
59 bool isContextual =
true )
61 , mUsesGeometry( usesGeometry )
62 , mReferencedColumns( referencedColumns )
72 const QString &helpText = QString(),
73 bool usesGeometry =
false,
74 const QSet<QString> &referencedColumns = QSet<QString>(),
75 bool lazyEval =
false,
76 bool handlesNull =
false,
77 bool isContextual =
true )
79 , mUsesGeometry( usesGeometry )
80 , mReferencedColumns( referencedColumns )
98 QSet<QString> mReferencedColumns;
133 StaticVariable(
const QString &name = QString(),
const QVariant &value = QVariant(),
bool readOnly =
false,
bool isStatic =
false,
const QString &description = QString() )
136 , readOnly( readOnly )
137 , isStatic( isStatic )
138 , description( description )
133 StaticVariable(
const QString &name = QString(),
const QVariant &value = QVariant(),
bool readOnly =
false,
bool isStatic =
false,
const QString &description = QString() ) {
…}
172 QString
name()
const {
return mName; }
181 void setVariable(
const QString &name,
const QVariant &value,
bool isStatic =
false );
198 bool removeVariable(
const QString &name );
207 bool hasVariable(
const QString &name )
const;
216 QVariant variable(
const QString &name )
const;
223 QStringList variableNames()
const;
231 QStringList filteredVariableNames()
const;
239 bool isReadOnly(
const QString &name )
const;
246 bool isStatic(
const QString &name )
const;
253 QString description(
const QString &name )
const;
267 bool hasFunction(
const QString &name )
const;
284 QStringList functionNames()
const;
361 void setFields(
const QgsFields &fields );
375 bool writeXml( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext &context )
const;
386 QStringList hiddenVariables()
const;
398 void setHiddenVariables(
const QStringList &hiddenVariables );
411 void addHiddenVariable(
const QString &hiddenVariable );
422 void removeHiddenVariable(
const QString &hiddenVariable );
442 QList< QgsMapLayerStore * > layerStores()
const;
446 QHash<QString, StaticVariable> mVariables;
447 QHash<QString, QgsScopedExpressionFunction * > mFunctions;
448 bool mHasFeature =
false;
450 bool mHasGeometry =
false;
452 QStringList mHiddenVariables;
454 QList< QPointer< QgsMapLayerStore > > mLayerStores;
498 bool hasVariable(
const QString &name )
const;
509 QVariant variable(
const QString &name )
const;
515 QVariantMap variablesToMap()
const;
524 bool isHighlightedVariable(
const QString &name )
const;
532 QStringList highlightedVariables()
const;
541 void setHighlightedVariables(
const QStringList &variableNames );
551 bool isHighlightedFunction(
const QString &name )
const;
564 void setHighlightedFunctions(
const QStringList &names );
603 QList< QgsExpressionContextScope * >
scopes() {
return mStack; }
617 int indexOfScope(
const QString &scopeName )
const;
627 QStringList variableNames()
const;
635 QStringList filteredVariableNames()
const;
643 bool isReadOnly(
const QString &name )
const;
652 QString description(
const QString &name )
const;
660 bool hasFunction(
const QString &name )
const;
667 QStringList functionNames()
const;
682 int scopeCount()
const;
698 void appendScopes(
const QList<QgsExpressionContextScope *> &scopes
SIP_TRANSFER );
712 QList<QgsExpressionContextScope *> takeScopes()
SIP_SKIP;
734 bool hasFeature() const;
757 bool hasGeometry() const;
773 void setFields( const
QgsFields &fields );
786 void setOriginalValueVariable( const QVariant &value );
798 void setCachedValue( const QString &key, const QVariant &value ) const;
807 bool hasCachedValue( const QString &key ) const;
818 QVariant cachedValue( const QString &key ) const;
826 void clearCachedValues() const;
890 QString uniqueHash(
bool &ok
SIP_OUT, const QSet<QString> &variables = QSet<QString>() ) const;
893 static const QString EXPR_FIELDS;
895 static const QString EXPR_ORIGINAL_VALUE;
897 static const QString EXPR_SYMBOL_COLOR;
899 static const QString EXPR_SYMBOL_ANGLE;
901 static const QString EXPR_GEOMETRY_PART_COUNT;
903 static const QString EXPR_GEOMETRY_PART_NUM;
909 static const QString EXPR_GEOMETRY_RING_NUM;
911 static const QString EXPR_GEOMETRY_POINT_COUNT;
913 static const QString EXPR_GEOMETRY_POINT_NUM;
915 static const QString EXPR_CLUSTER_SIZE;
917 static const QString EXPR_CLUSTER_COLOR;
922 QStringList mHighlightedVariables;
923 QStringList mHighlightedFunctions;
927 std::unique_ptr< LoadLayerFunction > mLoadLayerFunction;
931 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.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QList< QgsExpressionContextScope * > scopes()
Returns a list of scopes contained within the stack.
An 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.
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.
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.
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.
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.