QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
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(),
380 const QString &
group,
381 const QString &
helpText = QString(),
385 const QStringList &
aliases = QStringList(),
408 const QString &
group,
413 const QStringList &
aliases = QStringList(),
423 const QStringList &
groups,
424 const QString &
helpText = QString(),
428 const QStringList &
aliases = QStringList(),
447 return mFnc ? mFnc( values, context, parent, node ) : QVariant();
450 QStringList
aliases()
const override;
488 static const QList<QgsExpressionFunction *> &
functions();
492 QStringList mAliases;
498 QSet<QString> mReferencedColumns;
499 bool mIsStatic =
false;
575 void appendTemporaryVariable(
const QgsExpressionContext *context,
const QString &
name,
const QVariant &value )
const;
585 #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.
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_foreach(array, expression) expression function.
bool optional() const
Returns true if the parameter is optional.
An expression node for expression functions.
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.
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.
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.