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(),
361 bool usesGeometry =
false,
362 const QSet<QString> &referencedColumns = QSet<QString>(),
363 bool lazyEval =
false,
364 const QStringList &aliases = QStringList(),
365 bool handlesNull =
false )
368 , mAliases( aliases )
369 , mUsesGeometry( usesGeometry )
370 , mReferencedColumns( referencedColumns )
380 const QString &group,
381 const QString &helpText = QString(),
382 bool usesGeometry =
false,
383 const QSet<QString> &referencedColumns = QSet<QString>(),
384 bool lazyEval =
false,
385 const QStringList &aliases = QStringList(),
386 bool handlesNull =
false )
389 , mAliases( aliases )
390 , mUsesGeometry( usesGeometry )
391 , mReferencedColumns( referencedColumns )
408 const QString &group,
409 const QString &helpText,
412 bool lazyEval =
false,
413 const QStringList &aliases = QStringList(),
414 bool handlesNull =
false );
424 const QStringList &groups,
425 const QString &helpText = QString(),
426 bool usesGeometry =
false,
427 const QSet<QString> &referencedColumns = QSet<QString>(),
428 bool lazyEval =
false,
429 const QStringList &aliases = QStringList(),
430 bool handlesNull =
false )
433 , mAliases( aliases )
434 , mUsesGeometry( usesGeometry )
435 , mReferencedColumns( referencedColumns )
448 return mFnc ? mFnc( values, context, parent, node ) : QVariant();
451 QStringList aliases()
const override;
476 void setIsStatic(
bool isStatic );
489 static const QList<QgsExpressionFunction *> &functions();
493 QStringList mAliases;
495 std::function < bool( const QgsExpressionNodeFunction *node ) > mUsesGeometryFunc;
497 std::function < bool( const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) > mIsStaticFunc = allParamsStatic;
498 std::function < bool( const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) > mPrepareFunc;
499 QSet<QString> mReferencedColumns;
500 bool mIsStatic =
false;
576 void appendTemporaryVariable(
const QgsExpressionContext *context,
const QString &name,
const QVariant &value )
const;
586 #endif // QGSEXPRESSIONFUNCTION_H Class for parsing and evaluation of expressions (formerly called "search strings").
bool optional() const
Returns true if the parameter is optional.
int params() const
The number of parameters this function takes.
QStringList groups() const
Returns a list of the groups the function belongs to.
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.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Handles the with_variable(name, value, node) expression function.
QVariant defaultValue() const
Returns the default value for the parameter.
Handles the array_foreach(array, expression) expression function.
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...
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.
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...
Parameter(const QString &name, bool optional=false, const QVariant &defaultValue=QVariant(), bool isSubExpression=false)
Constructor for Parameter.
const QgsExpressionFunction::ParameterList & parameters() const
Returns the list of named parameters for the function, if set.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
int minParams() const
The minimum number of parameters this function takes.
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...
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override
Returns result of evaluating the function.
Single scope for storing variables and functions for use within a QgsExpressionContext.
An expression node for expression functions.
QString name() const
Returns the name of 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 isSubExpression() const
Returns true if parameter argument is a separate sub-expression, and should not be checked while dete...
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.
QString name() const
The name of the function.
Handles the array_filter(array, expression) expression function.
A abstract base class for defining QgsExpression functions.
A list of expression nodes.
c++ helper class for defining QgsExpression functions.
bool operator==(const QgsExpressionFunction::Parameter &other) const
Represents a single parameter passed to a function.
bool isContextual() const
Returns whether the function is only available if provided by a QgsExpressionContext object...
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.