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;
355 bool variableNameSort(
const QString &a,
const QString &b );
403 bool hasVariable(
const QString &name )
const;
414 QVariant variable(
const QString &name )
const;
421 QVariantMap variablesToMap()
const;
430 bool isHighlightedVariable(
const QString &name )
const;
439 void setHighlightedVariables(
const QStringList &variableNames );
449 bool isHighlightedFunction(
const QString &name )
const;
462 void setHighlightedFunctions(
const QStringList &names );
501 QList< QgsExpressionContextScope * >
scopes() {
return mStack; }
516 int indexOfScope(
const QString &scopeName )
const;
526 QStringList variableNames()
const;
534 QStringList filteredVariableNames()
const;
542 bool isReadOnly(
const QString &name )
const;
552 QString description(
const QString &name )
const;
560 bool hasFunction(
const QString &name )
const;
567 QStringList functionNames()
const;
582 int scopeCount()
const;
599 void appendScopes(
const QList<QgsExpressionContextScope *> &scopes SIP_TRANSFER );
614 QList<QgsExpressionContextScope *> takeScopes()
SIP_SKIP;
637 bool hasFeature()
const;
652 void setFields(
const QgsFields &fields );
666 void setOriginalValueVariable(
const QVariant &value );
679 void setCachedValue(
const QString &key,
const QVariant &value )
const;
689 bool hasCachedValue(
const QString &key )
const;
701 QVariant cachedValue(
const QString &key )
const;
710 void clearCachedValues()
const;
735 QList< QgsExpressionContextScope * > mStack;
736 QStringList mHighlightedVariables;
737 QStringList mHighlightedFunctions;
740 mutable QMap< QString, QVariant > mCachedValues;
744 #endif // QGSEXPRESSIONCONTEXT_H static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
Class for parsing and evaluation of expressions (formerly called "search strings").
The class is used as a container of context for various read/write operations on other objects...
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
virtual QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node)=0
Returns result of evaluating the function.
Single variable definition for use within a QgsExpressionContextScope.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
virtual QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const
Returns a set of field names which are required for this function.
Container of fields for a vector layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
int variableCount() const
Returns the count of variables contained within the scope.
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
QString description
Translated description of variable, for use within expression builder widgets.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool readOnly
True if variable should not be editable by users.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
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.
virtual bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const
Will be called during prepare to determine if the function is static.
std::ostream & operator<<(std::ostream &os, const QgsCoordinateReferenceSystem &r)
Output stream operator.
static const QString EXPR_FIELDS
Inbuilt variable name for fields storage.
Single scope for storing variables and functions for use within a QgsExpressionContext.
An expression node for expression functions.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
virtual bool usesGeometry(const QgsExpressionNodeFunction *node) const
Does this function use a geometry object.
A abstract base class for defining QgsExpression functions.
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.
StaticVariable(const QString &name=QString(), const QVariant &value=QVariant(), bool readOnly=false, bool isStatic=false, const QString &description=QString())
Constructor for StaticVariable.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
bool hasFeature() const
Returns true if the scope has a feature associated with it.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
QString name() const
Returns the friendly display name of the context scope.
void removeFeature()
Removes any feature associated with the scope.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
bool isStatic
A static variable can be cached for the lifetime of a context.
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
QList< QgsExpressionContextScope *> scopes()
Returns a list of scopes contained within the stack.
Expression function for use within a QgsExpressionContextScope.
QString name
Variable name.
QgsFeature feature() const
Sets the feature associated with the scope.
QVariant value
Variable value.