15 #ifndef QGSEXPRESSIONCONTEXT_H 16 #define QGSEXPRESSIONCONTEXT_H 18 #include "qgis_core.h" 24 #include <QStringList> 27 #include "qgsexpression.h" 28 #include "qgsexpressionfunction.h" 32 class QgsExpressionNodeFunction;
36 class QgsComposerItem;
37 class QgsAtlasComposition;
67 const QString &helpText = QString(),
68 bool usesGeometry =
false,
69 const QSet<QString> &referencedColumns = QSet<QString>(),
70 bool lazyEval =
false,
71 bool handlesNull =
false,
72 bool isContextual =
true )
73 : QgsExpressionFunction( fnname, params, group, helpText, lazyEval, handlesNull, isContextual )
74 , mUsesGeometry( usesGeometry )
75 , mReferencedColumns( referencedColumns )
84 const QgsExpressionFunction::ParameterList ¶ms,
86 const QString &helpText = QString(),
87 bool usesGeometry =
false,
88 const QSet<QString> &referencedColumns = QSet<QString>(),
89 bool lazyEval =
false,
90 bool handlesNull =
false,
91 bool isContextual =
true )
92 : QgsExpressionFunction( fnname, params, group, helpText, lazyEval, handlesNull, isContextual )
93 , mUsesGeometry( usesGeometry )
94 , mReferencedColumns( referencedColumns )
97 QVariant func(
const QVariantList &values,
const QgsExpressionContext *context, QgsExpression *parent,
const QgsExpressionNodeFunction *node )
override = 0;
104 bool usesGeometry(
const QgsExpressionNodeFunction *node )
const override;
106 QSet<QString> referencedColumns(
const QgsExpressionNodeFunction *node )
const override;
108 bool isStatic(
const QgsExpressionNodeFunction *node, QgsExpression *parent,
const QgsExpressionContext *context )
const override;
112 QSet<QString> mReferencedColumns;
147 StaticVariable(
const QString &name = QString(),
const QVariant &value = QVariant(),
bool readOnly =
false,
bool isStatic =
false,
const QString &description = QString() )
150 , readOnly( readOnly )
151 , isStatic( isStatic )
152 , description( description )
189 QString
name()
const {
return mName; }
198 void setVariable(
const QString &name,
const QVariant &value,
bool isStatic =
false );
215 bool removeVariable(
const QString &name );
224 bool hasVariable(
const QString &name )
const;
233 QVariant variable(
const QString &name )
const;
240 QStringList variableNames()
const;
248 QStringList filteredVariableNames()
const;
256 bool isReadOnly(
const QString &name )
const;
264 bool isStatic(
const QString &name )
const;
272 QString description(
const QString &name )
const;
286 bool hasFunction(
const QString &name )
const;
296 QgsExpressionFunction *
function(
const QString &name )
const;
303 QStringList functionNames()
const;
350 void setFields(
const QgsFields &fields );
354 QHash<QString, StaticVariable> mVariables;
355 QHash<QString, QgsScopedExpressionFunction * > mFunctions;
356 bool mHasFeature =
false;
359 bool variableNameSort(
const QString &a,
const QString &b );
407 bool hasVariable(
const QString &name )
const;
418 QVariant variable(
const QString &name )
const;
425 QVariantMap variablesToMap()
const;
434 bool isHighlightedVariable(
const QString &name )
const;
442 void setHighlightedVariables(
const QStringList &variableNames );
481 QList< QgsExpressionContextScope * >
scopes() {
return mStack; }
496 int indexOfScope(
const QString &scopeName )
const;
506 QStringList variableNames()
const;
514 QStringList filteredVariableNames()
const;
522 bool isReadOnly(
const QString &name )
const;
532 QString description(
const QString &name )
const;
540 bool hasFunction(
const QString &name )
const;
547 QStringList functionNames()
const;
557 QgsExpressionFunction *
function(
const QString &name )
const;
562 int scopeCount()
const;
579 void appendScopes(
const QList<QgsExpressionContextScope *> &scopes SIP_TRANSFER );
594 QList<QgsExpressionContextScope *> takeScopes()
SIP_SKIP;
617 bool hasFeature()
const;
632 void setFields(
const QgsFields &fields );
646 void setOriginalValueVariable(
const QVariant &value );
659 void setCachedValue(
const QString &key,
const QVariant &value )
const;
669 bool hasCachedValue(
const QString &key )
const;
681 QVariant cachedValue(
const QString &key )
const;
690 void clearCachedValues()
const;
715 QList< QgsExpressionContextScope * > mStack;
716 QStringList mHighlightedVariables;
719 mutable QMap< QString, QVariant > mCachedValues;
751 static void setGlobalVariable(
const QString &name,
const QVariant &value );
761 static void setGlobalVariables(
const QVariantMap &variables );
770 static void removeGlobalVariable(
const QString &name );
790 static void setProjectVariable(
QgsProject *project,
const QString &name,
const QVariant &value );
801 static void setProjectVariables(
QgsProject *project,
const QVariantMap &variables );
811 static void removeProjectVariable(
QgsProject *project,
const QString &name );
823 static QList<QgsExpressionContextScope *> globalProjectLayerScopes(
const QgsMapLayer *layer )
SIP_FACTORY;
834 static void setLayerVariable(
QgsMapLayer *layer,
const QString &name,
const QVariant &value );
844 static void setLayerVariables(
QgsMapLayer *layer,
const QVariantMap &variables );
885 static void setLayoutVariable(
QgsLayout *layout,
const QString &name,
const QVariant &value );
896 static void setLayoutVariables(
QgsLayout *layout,
const QVariantMap &variables );
922 static void setLayoutItemVariable(
QgsLayoutItem *item,
const QString &name,
const QVariant &value );
931 static void setLayoutItemVariables(
QgsLayoutItem *item,
const QVariantMap &variables );
956 static void registerContextFunctions();
960 #endif // QGSEXPRESSIONCONTEXT_H static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
Single variable definition for use within a QgsExpressionContextScope.
Base class for all map layer types.
Base class for graphical items within a QgsLayout.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
Container of fields for a vector layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Abstract base class for processing algorithms.
The QgsMapSettings class contains configuration for rendering of the map.
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...
Class used to render an Atlas, iterating over geometry features.
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.
Reads and writes project states.
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.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Contains utilities for working with QgsExpressionContext objects, including methods for creating scop...
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.
Contains information about the context in which a processing algorithm is executed.
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.