QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
16 #ifndef QGSEXPRESSIONFUNCTION_H
17 #define QGSEXPRESSIONFUNCTION_H
24 #include <QJsonDocument>
25 #include <QJsonObject>
28 #include "qgis_core.h"
66 bool optional =
false,
67 const QVariant &defaultValue = QVariant(),
68 bool isSubExpression =
false )
70 , mOptional( optional )
71 , mDefaultValue( defaultValue )
72 , mIsSubExpression( isSubExpression )
76 QString
name()
const {
return mName; }
93 return ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 );
98 bool mOptional =
false;
99 QVariant mDefaultValue;
100 bool mIsSubExpression =
false;
109 const QString &group,
110 const QString &helpText = QString(),
111 bool lazyEval =
false,
112 bool handlesNull =
false,
113 bool isContextual =
false )
116 , mGroups( group.isEmpty() ? QStringList() : QStringList() << group )
117 , mHelpText( helpText )
118 , mLazyEval( lazyEval )
119 , mHandlesNull( handlesNull )
120 , mIsContextual( isContextual )
130 const QStringList &groups,
131 const QString &helpText = QString(),
132 bool lazyEval =
false,
133 bool handlesNull =
false,
134 bool isContextual =
false )
138 , mHelpText( helpText )
139 , mLazyEval( lazyEval )
140 , mHandlesNull( handlesNull )
141 , mIsContextual( isContextual )
151 const QString &group,
152 const QString &helpText = QString(),
153 bool lazyEval =
false,
154 bool handlesNull =
false,
155 bool isContextual =
false )
158 , mParameterList( params )
159 , mGroups( group.isEmpty() ? QStringList() : QStringList() << group )
160 , mHelpText( helpText )
161 , mLazyEval( lazyEval )
162 , mHandlesNull( handlesNull )
163 , mIsContextual( isContextual )
172 const QStringList &groups,
173 const QString &helpText = QString(),
174 bool lazyEval =
false,
175 bool handlesNull =
false,
176 bool isContextual =
false )
179 , mParameterList( params )
181 , mHelpText( helpText )
182 , mLazyEval( lazyEval )
183 , mHandlesNull( handlesNull )
184 , mIsContextual( isContextual )
190 QString
name()
const {
return mName; }
193 int params()
const {
return mParameterList.isEmpty() ? mParams : mParameterList.count(); }
198 if ( mParameterList.isEmpty() )
202 for (
const Parameter ¶m : mParameterList )
204 if ( !param.optional() )
225 virtual QStringList aliases()
const;
277 virtual bool isDeprecated()
const;
283 QString
group()
const {
return mGroups.isEmpty() ? QString() : mGroups.at( 0 ); }
290 QStringList
groups()
const {
return mGroups; }
293 const QString helpText()
const;
317 virtual bool handlesNull()
const;
359 const QString &
group,
360 const QString &
helpText = QString(),
364 const QStringList &
aliases = QStringList(),
381 const QStringList &
groups,
382 const QString &
helpText = QString(),
386 const QStringList &
aliases = QStringList(),
402 const QString &
group,
403 const QString &
helpText = QString(),
407 const QStringList &
aliases = QStringList(),
430 const QString &
group,
435 const QStringList &
aliases = QStringList(),
445 const QStringList &
groups,
446 const QString &
helpText = QString(),
450 const QStringList &
aliases = QStringList(),
469 return mFnc ? mFnc( values, context, parent, node ) : QVariant();
472 QStringList
aliases()
const override;
510 static const QList<QgsExpressionFunction *> &
functions();
514 QStringList mAliases;
520 QSet<QString> mReferencedColumns;
521 bool mIsStatic =
false;
597 void appendTemporaryVariable(
const QgsExpressionContext *context,
const QString &
name,
const QVariant &value )
const;
607 #endif // QGSEXPRESSIONFUNCTION_H
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
const QString helpText() const
The help text for the function.
QStringList aliases() const override
Returns a list of possible aliases for the function.
bool isSubExpression() const
Returns true if parameter argument is a separate sub-expression, and should not be checked while dete...
Handles the with_variable(name, value, node) expression function.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
void setPrepareFunction(const std::function< bool(const QgsExpressionNodeFunction *, QgsExpression *, const QgsExpressionContext *)> &prepareFunc)
Set a function that will be called in the prepare step to determine if the function is static or not.
QString name() const
Returns the name of the parameter.
Handles the array_filter(array, expression) expression function.
bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
This will be called during the prepare step() of an expression if it is not static.
QStringList groups() const
Returns a list of the groups the function belongs to.
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Returns result of evaluating the function.
bool isContextual() const
Returns whether the function is only available if provided by a QgsExpressionContext object.
static const QList< QgsExpressionFunction * > & functions()
Returns a list of all registered expression functions.
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Returns result of evaluating the function.
bool operator==(const QgsExpressionFunction::Parameter &other) const
QgsExpressionFunction(const QString &fnname, int params, const QString &group, const QString &helpText=QString(), bool lazyEval=false, bool handlesNull=false, bool isContextual=false)
Constructor for function which uses unnamed parameters.
bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
This will be called during the prepare step() of an expression if it is not static.
virtual bool handlesNull() const
Returns true if the function handles NULL values in arguments by itself, and the default NULL value h...
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
QVariant run(QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Evaluates the function, first evaluating all required arguments before passing them to the function's...
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Returns result of evaluating the function.
int params() const
The number of parameters this function takes.
Represents a single parameter passed to a function.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
QgsExpressionFunction(const QString &fnname, const QgsExpressionFunction::ParameterList ¶ms, const QString &group, const QString &helpText=QString(), bool lazyEval=false, bool handlesNull=false, bool isContextual=false)
Constructor for function which uses named parameter list.
void setIsStaticFunction(const std::function< bool(const QgsExpressionNodeFunction *, QgsExpression *, const QgsExpressionContext *) > &isStatic)
Set a function that will be called in the prepare step to determine if the function is static or not.
QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const override
Returns a set of field names which are required for this function.
QgsStaticExpressionFunction(const QString &fnname, const QgsExpressionFunction::ParameterList ¶ms, FcnEval fcn, const QStringList &groups, const QString &helpText=QString(), bool usesGeometry=false, const QSet< QString > &referencedColumns=QSet< QString >(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
Static function for evaluation against a QgsExpressionContext, using a named list of parameter values...
QgsWithVariableExpressionFunction()
Handles the array loopingarray_Foreach(array, expression) expression function.
c++ helper class for defining QgsExpression functions.
bool optional() const
Returns true if the parameter is optional.
An expression node for expression functions.
QgsStaticExpressionFunction(const QString &fnname, int params, FcnEval fcn, const QStringList &groups, const QString &helpText=QString(), bool usesGeometry=false, const QSet< QString > &referencedColumns=QSet< QString >(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
Static function for evaluation against a QgsExpressionContext, using an unnamed list of parameter val...
Single scope for storing variables and functions for use within a QgsExpressionContext....
bool usesGeometry(const QgsExpressionNodeFunction *node) const override
Does this function use a geometry object.
QVariant(* FcnEval)(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node)
Function definition for evaluation against an expression context, using a list of values as parameter...
QVariant defaultValue() const
Returns the default value for the parameter.
bool lazyEval() const
true if this function should use lazy evaluation.
QString group() const
Returns the first group which the function belongs to.
A abstract base class for defining QgsExpression functions.
bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
This will be called during the prepare step() of an expression if it is not static.
QVariant run(QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Evaluates the function, first evaluating all required arguments before passing them to the function's...
QgsStaticExpressionFunction(const QString &fnname, const QgsExpressionFunction::ParameterList ¶ms, FcnEval fcn, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QSet< QString > &referencedColumns=QSet< QString >(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
Static function for evaluation against a QgsExpressionContext, using a named list of parameter values...
QString name() const
The name of the function.
const QgsExpressionFunction::ParameterList & parameters() const
Returns the list of named parameters for the function, if set.
int minParams() const
The minimum number of parameters this function takes.
static bool allParamsStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context)
This will return true if all the params for the provided function node are static within the constrai...
QVariant run(QgsExpressionNode::NodeList *args, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Evaluates the function, first evaluating all required arguments before passing them to the function's...
QgsArrayForeachExpressionFunction()
Parameter(const QString &name, bool optional=false, const QVariant &defaultValue=QVariant(), bool isSubExpression=false)
Constructor for Parameter.
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Returns result of evaluating the function.
QgsExpressionFunction(const QString &fnname, const QgsExpressionFunction::ParameterList ¶ms, const QStringList &groups, const QString &helpText=QString(), bool lazyEval=false, bool handlesNull=false, bool isContextual=false)
Constructor for function which uses named parameter list and group list.
Class for parsing and evaluation of expressions (formerly called "search strings")....
QgsArrayFilterExpressionFunction()
bool prepare(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
This will be called during the prepare step() of an expression if it is not static.
void setIsStatic(bool isStatic)
Tag this function as either static or not static.
QgsStaticExpressionFunction(const QString &fnname, int params, FcnEval fcn, const QString &group, const QString &helpText=QString(), bool usesGeometry=false, const QSet< QString > &referencedColumns=QSet< QString >(), bool lazyEval=false, const QStringList &aliases=QStringList(), bool handlesNull=false)
Static function for evaluation against a QgsExpressionContext, using an unnamed list of parameter val...
A list of expression nodes.
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
QgsExpressionFunction(const QString &fnname, int params, const QStringList &groups, const QString &helpText=QString(), bool lazyEval=false, bool handlesNull=false, bool isContextual=false)
Constructor for function which uses unnamed parameters and group list.