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;
443 void setHighlightedVariables(
const QStringList &variableNames );
453 bool isHighlightedFunction(
const QString &name )
const;
466 void setHighlightedFunctions(
const QStringList &names );
505 QList< QgsExpressionContextScope * >
scopes() {
return mStack; }
520 int indexOfScope(
const QString &scopeName )
const;
530 QStringList variableNames()
const;
538 QStringList filteredVariableNames()
const;
546 bool isReadOnly(
const QString &name )
const;
556 QString description(
const QString &name )
const;
564 bool hasFunction(
const QString &name )
const;
571 QStringList functionNames()
const;
586 int scopeCount()
const;
603 void appendScopes(
const QList<QgsExpressionContextScope *> &scopes SIP_TRANSFER );
618 QList<QgsExpressionContextScope *> takeScopes()
SIP_SKIP;
641 bool hasFeature()
const;
656 void setFields(
const QgsFields &fields );
670 void setOriginalValueVariable(
const QVariant &value );
683 void setCachedValue(
const QString &key,
const QVariant &value )
const;
693 bool hasCachedValue(
const QString &key )
const;
705 QVariant cachedValue(
const QString &key )
const;
714 void clearCachedValues()
const;
739 QList< QgsExpressionContextScope * > mStack;
740 QStringList mHighlightedVariables;
741 QStringList mHighlightedFunctions;
744 mutable QMap< QString, QVariant > mCachedValues;
784 static void setGlobalVariable(
const QString &name,
const QVariant &value );
794 static void setGlobalVariables(
const QVariantMap &variables );
803 static void removeGlobalVariable(
const QString &name );
823 static void setProjectVariable(
QgsProject *project,
const QString &name,
const QVariant &value );
834 static void setProjectVariables(
QgsProject *project,
const QVariantMap &variables );
844 static void removeProjectVariable(
QgsProject *project,
const QString &name );
856 static QList<QgsExpressionContextScope *> globalProjectLayerScopes(
const QgsMapLayer *layer )
SIP_FACTORY;
867 static void setLayerVariable(
QgsMapLayer *layer,
const QString &name,
const QVariant &value );
877 static void setLayerVariables(
QgsMapLayer *layer,
const QVariantMap &variables );
918 static void setLayoutVariable(
QgsLayout *layout,
const QString &name,
const QVariant &value );
929 static void setLayoutVariables(
QgsLayout *layout,
const QVariantMap &variables );
955 static void setLayoutItemVariable(
QgsLayoutItem *item,
const QString &name,
const QVariant &value );
964 static void setLayoutItemVariables(
QgsLayoutItem *item,
const QVariantMap &variables );
989 static void registerContextFunctions();
996 GetLayerVisibility(
const QList<QgsMapLayer *> &layers );
1002 const QList< QPointer< QgsMapLayer > > mLayers;
1010 #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.
Abstract base class for all rendered symbols.
QgsFeature feature() const
Sets the feature associated with the scope.
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.
QString name() const
Returns the friendly display name of the context scope.
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
Layout graphical items for displaying a map.
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.
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.
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.
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
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.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
int variableCount() const
Returns the count of variables contained within the scope.
void removeFeature()
Removes any feature associated with the scope.
virtual QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const
Returns a set of field names which are required for this function.
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.
virtual bool usesGeometry(const QgsExpressionNodeFunction *node) const
Does this function use a geometry object.
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.
bool hasFeature() const
Returns true if the scope has a feature associated with it.
virtual bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const
Will be called during prepare to determine if the function is static.
Expression function for use within a QgsExpressionContextScope.
QString name
Variable name.
QVariant value
Variable value.