15#ifndef QGSEXPRESSIONCONTEXT_H
16#define QGSEXPRESSIONCONTEXT_H
32class LoadLayerFunction;
55 const QString &helpText = QString(),
56 bool usesGeometry =
false,
57 const QSet<QString> &referencedColumns = QSet<QString>(),
58 bool lazyEval =
false,
59 bool handlesNull =
false,
60 bool isContextual =
true )
62 , mUsesGeometry( usesGeometry )
63 , mReferencedColumns( referencedColumns )
74 const QString &helpText = QString(),
75 bool usesGeometry =
false,
76 const QSet<QString> &referencedColumns = QSet<QString>(),
77 bool lazyEval =
false,
78 bool handlesNull =
false,
79 bool isContextual =
true )
81 , mUsesGeometry( usesGeometry )
82 , mReferencedColumns( referencedColumns )
100 QSet<QString> mReferencedColumns;
135 StaticVariable(
const QString &name = QString(),
const QVariant &value = QVariant(),
bool readOnly =
false,
bool isStatic =
false,
const QString &description = QString() )
138 , readOnly( readOnly )
139 , isStatic( isStatic )
140 , description( description )
177 QString
name()
const {
return mName; }
186 void setVariable(
const QString &name,
const QVariant &value,
bool isStatic =
false );
203 bool removeVariable(
const QString &name );
212 bool hasVariable(
const QString &name )
const;
221 QVariant variable(
const QString &name )
const;
228 QStringList variableNames()
const;
236 QStringList filteredVariableNames()
const;
244 bool isReadOnly(
const QString &name )
const;
252 bool isStatic(
const QString &name )
const;
260 QString description(
const QString &name )
const;
274 bool hasFunction(
const QString &name )
const;
291 QStringList functionNames()
const;
371 void setFields(
const QgsFields &fields );
385 bool writeXml( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext &context )
const;
396 QStringList hiddenVariables()
const;
408 void setHiddenVariables(
const QStringList &hiddenVariables );
421 void addHiddenVariable(
const QString &hiddenVariable );
432 void removeHiddenVariable(
const QString &hiddenVariable );
452 QList< QgsMapLayerStore * > layerStores()
const;
456 QHash<QString, StaticVariable> mVariables;
457 QHash<QString, QgsScopedExpressionFunction * > mFunctions;
458 bool mHasFeature =
false;
460 bool mHasGeometry =
false;
462 QStringList mHiddenVariables;
464 QList< QPointer< QgsMapLayerStore > > mLayerStores;
512 bool hasVariable(
const QString &name )
const;
523 QVariant variable(
const QString &name )
const;
530 QVariantMap variablesToMap()
const;
539 bool isHighlightedVariable(
const QString &name )
const;
547 QStringList highlightedVariables()
const;
556 void setHighlightedVariables(
const QStringList &variableNames );
566 bool isHighlightedFunction(
const QString &name )
const;
579 void setHighlightedFunctions(
const QStringList &names );
618 QList< QgsExpressionContextScope * >
scopes() {
return mStack; }
633 int indexOfScope(
const QString &scopeName )
const;
643 QStringList variableNames()
const;
651 QStringList filteredVariableNames()
const;
659 bool isReadOnly(
const QString &name )
const;
669 QString description(
const QString &name )
const;
677 bool hasFunction(
const QString &name )
const;
684 QStringList functionNames()
const;
699 int scopeCount()
const;
716 void appendScopes(
const QList<QgsExpressionContextScope *> &scopes
SIP_TRANSFER );
731 QList<QgsExpressionContextScope *> takeScopes()
SIP_SKIP;
754 bool hasFeature() const;
777 bool hasGeometry() const;
793 void setFields( const
QgsFields &fields );
807 void setOriginalValueVariable( const QVariant &value );
820 void setCachedValue( const QString &key, const QVariant &value ) const;
830 bool hasCachedValue( const QString &key ) const;
842 QVariant cachedValue( const QString &key ) const;
851 void clearCachedValues() const;
906 static const QString EXPR_FIELDS;
908 static const QString EXPR_ORIGINAL_VALUE;
910 static const QString EXPR_SYMBOL_COLOR;
912 static const QString EXPR_SYMBOL_ANGLE;
914 static const QString EXPR_GEOMETRY_PART_COUNT;
916 static const QString EXPR_GEOMETRY_PART_NUM;
922 static const QString EXPR_GEOMETRY_RING_NUM;
924 static const QString EXPR_GEOMETRY_POINT_COUNT;
926 static const QString EXPR_GEOMETRY_POINT_NUM;
928 static const QString EXPR_CLUSTER_SIZE;
930 static const QString EXPR_CLUSTER_COLOR;
935 QStringList mHighlightedVariables;
936 QStringList mHighlightedFunctions;
940 std::unique_ptr< LoadLayerFunction > mLoadLayerFunction;
944 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.
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.
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...
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...
The class is used as a container of context for various read/write operations on other 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.