15#ifndef QGSEXPRESSIONCONTEXT_H
16#define QGSEXPRESSIONCONTEXT_H
32class LoadLayerFunction;
53 const QString &helpText = QString(),
54 bool usesGeometry =
false,
55 const QSet<QString> &referencedColumns = QSet<QString>(),
56 bool lazyEval =
false,
57 bool handlesNull =
false,
58 bool isContextual =
true )
60 , mUsesGeometry( usesGeometry )
61 , mReferencedColumns( referencedColumns )
71 const QString &helpText = QString(),
72 bool usesGeometry =
false,
73 const QSet<QString> &referencedColumns = QSet<QString>(),
74 bool lazyEval =
false,
75 bool handlesNull =
false,
76 bool isContextual =
true )
78 , mUsesGeometry( usesGeometry )
79 , mReferencedColumns( referencedColumns )
97 QSet<QString> mReferencedColumns;
132 StaticVariable(
const QString &name = QString(),
const QVariant &value = QVariant(),
bool readOnly =
false,
bool isStatic =
false,
const QString &description = QString() )
135 , readOnly( readOnly )
136 , isStatic( isStatic )
137 , 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;
245 bool isStatic(
const QString &name )
const;
252 QString description(
const QString &name )
const;
266 bool hasFunction(
const QString &name )
const;
283 QStringList functionNames()
const;
360 void setFields(
const QgsFields &fields );
374 bool writeXml( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext &context )
const;
385 QStringList hiddenVariables()
const;
397 void setHiddenVariables(
const QStringList &hiddenVariables );
410 void addHiddenVariable(
const QString &hiddenVariable );
421 void removeHiddenVariable(
const QString &hiddenVariable );
441 QList< QgsMapLayerStore * > layerStores()
const;
445 QHash<QString, StaticVariable> mVariables;
446 QHash<QString, QgsScopedExpressionFunction * > mFunctions;
447 bool mHasFeature =
false;
449 bool mHasGeometry =
false;
451 QStringList mHiddenVariables;
453 QList< QPointer< QgsMapLayerStore > > mLayerStores;
497 bool hasVariable(
const QString &name )
const;
508 QVariant variable(
const QString &name )
const;
514 QVariantMap variablesToMap()
const;
523 bool isHighlightedVariable(
const QString &name )
const;
531 QStringList highlightedVariables()
const;
540 void setHighlightedVariables(
const QStringList &variableNames );
550 bool isHighlightedFunction(
const QString &name )
const;
563 void setHighlightedFunctions(
const QStringList &names );
602 QList< QgsExpressionContextScope * >
scopes() {
return mStack; }
616 int indexOfScope(
const QString &scopeName )
const;
626 QStringList variableNames()
const;
634 QStringList filteredVariableNames()
const;
642 bool isReadOnly(
const QString &name )
const;
651 QString description(
const QString &name )
const;
659 bool hasFunction(
const QString &name )
const;
666 QStringList functionNames()
const;
681 int scopeCount()
const;
697 void appendScopes(
const QList<QgsExpressionContextScope *> &scopes
SIP_TRANSFER );
711 QList<QgsExpressionContextScope *> takeScopes()
SIP_SKIP;
733 bool hasFeature() const;
756 bool hasGeometry() const;
772 void setFields( const
QgsFields &fields );
785 void setOriginalValueVariable( const QVariant &value );
797 void setCachedValue( const QString &key, const QVariant &value ) const;
806 bool hasCachedValue( const QString &key ) const;
817 QVariant cachedValue( const QString &key ) const;
825 void clearCachedValues() const;
889 QString uniqueHash(
bool &ok
SIP_OUT, const QSet<QString> &variables = QSet<QString>() ) const;
892 static const QString EXPR_FIELDS;
894 static const QString EXPR_ORIGINAL_VALUE;
896 static const QString EXPR_SYMBOL_COLOR;
898 static const QString EXPR_SYMBOL_ANGLE;
900 static const QString EXPR_GEOMETRY_PART_COUNT;
902 static const QString EXPR_GEOMETRY_PART_NUM;
908 static const QString EXPR_GEOMETRY_RING_NUM;
910 static const QString EXPR_GEOMETRY_POINT_COUNT;
912 static const QString EXPR_GEOMETRY_POINT_NUM;
914 static const QString EXPR_CLUSTER_SIZE;
916 static const QString EXPR_CLUSTER_COLOR;
921 QStringList mHighlightedVariables;
922 QStringList mHighlightedFunctions;
926 std::unique_ptr< LoadLayerFunction > mLoadLayerFunction;
930 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.