15 #ifndef QGSEXPRESSIONCONTEXT_H 16 #define QGSEXPRESSIONCONTEXT_H 18 #include "qgis_core.h" 24 #include <QStringList> 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 )
74 , mUsesGeometry( usesGeometry )
75 , mReferencedColumns( referencedColumns )
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 )
93 , mUsesGeometry( usesGeometry )
94 , mReferencedColumns( referencedColumns )
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;
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;
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;
758 static void setGlobalVariable(
const QString &name,
const QVariant &value );
768 static void setGlobalVariables(
const QVariantMap &variables );
777 static void removeGlobalVariable(
const QString &name );
797 static void setProjectVariable(
QgsProject *project,
const QString &name,
const QVariant &value );
808 static void setProjectVariables(
QgsProject *project,
const QVariantMap &variables );
818 static void removeProjectVariable(
QgsProject *project,
const QString &name );
830 static QList<QgsExpressionContextScope *> globalProjectLayerScopes(
const QgsMapLayer *layer )
SIP_FACTORY;
841 static void setLayerVariable(
QgsMapLayer *layer,
const QString &name,
const QVariant &value );
851 static void setLayerVariables(
QgsMapLayer *layer,
const QVariantMap &variables );
892 static void setLayoutVariable(
QgsLayout *layout,
const QString &name,
const QVariant &value );
903 static void setLayoutVariables(
QgsLayout *layout,
const QVariantMap &variables );
929 static void setLayoutItemVariable(
QgsLayoutItem *item,
const QString &name,
const QVariant &value );
938 static void setLayoutItemVariables(
QgsLayoutItem *item,
const QVariantMap &variables );
963 static void registerContextFunctions();
967 #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").
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.
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.
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...
Abstract base class for processing algorithms.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
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 QgsLayout as an atlas, by iterating over the features from an associated vector ...
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.
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.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
virtual bool usesGeometry(const QgsExpressionNodeFunction *node) const
Does this function use a geometry object.
Contains utilities for working with QgsExpressionContext objects, including methods for creating scop...
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.
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.