16 #ifndef QGSEXPRESSIONFUNCTION_H 17 #define QGSEXPRESSIONFUNCTION_H 26 #include "qgis_core.h" 64 bool optional =
false,
65 const QVariant &defaultValue = QVariant(),
66 bool isSubExpression =
false )
68 , mOptional( optional )
69 , mDefaultValue( defaultValue )
70 , mIsSubExpression( isSubExpression )
74 QString
name()
const {
return mName; }
91 return ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 );
96 bool mOptional =
false;
97 QVariant mDefaultValue;
98 bool mIsSubExpression =
false;
107 const QString &group,
108 const QString &helpText = QString(),
109 bool lazyEval =
false,
110 bool handlesNull =
false,
111 bool isContextual =
false )
114 , mGroups( group.isEmpty() ? QStringList() : QStringList() << group )
115 , mHelpText( helpText )
116 , mLazyEval( lazyEval )
117 , mHandlesNull( handlesNull )
118 , mIsContextual( isContextual )
128 const QStringList &groups,
129 const QString &helpText = QString(),
130 bool lazyEval =
false,
131 bool handlesNull =
false,
132 bool isContextual =
false )
136 , mHelpText( helpText )
137 , mLazyEval( lazyEval )
138 , mHandlesNull( handlesNull )
139 , mIsContextual( isContextual )
149 const QString &group,
150 const QString &helpText = QString(),
151 bool lazyEval =
false,
152 bool handlesNull =
false,
153 bool isContextual =
false )
156 , mParameterList( params )
157 , mGroups( group.isEmpty() ? QStringList() : QStringList() << group )
158 , mHelpText( helpText )
159 , mLazyEval( lazyEval )
160 , mHandlesNull( handlesNull )
161 , mIsContextual( isContextual )
170 const QStringList &groups,
171 const QString &helpText = QString(),
172 bool lazyEval =
false,
173 bool handlesNull =
false,
174 bool isContextual =
false )
177 , mParameterList( params )
179 , mHelpText( helpText )
180 , mLazyEval( lazyEval )
181 , mHandlesNull( handlesNull )
182 , mIsContextual( isContextual )
188 QString
name()
const {
return mName; }
191 int params()
const {
return mParameterList.isEmpty() ? mParams : mParameterList.count(); }
196 if ( mParameterList.isEmpty() )
200 for (
const Parameter ¶m : mParameterList )
202 if ( !param.optional() )
223 virtual QStringList aliases()
const;
275 virtual bool isDeprecated()
const;
281 QString
group()
const {
return mGroups.isEmpty() ? QString() : mGroups.at( 0 ); }
288 QStringList
groups()
const {
return mGroups; }
291 const QString helpText()
const;
315 virtual bool handlesNull()
const;
357 const QString &group,
358 const QString &helpText = QString(),
359 bool usesGeometry =
false,
360 const QSet<QString> &referencedColumns = QSet<QString>(),
361 bool lazyEval =
false,
362 const QStringList &aliases = QStringList(),
363 bool handlesNull =
false )
366 , mAliases( aliases )
367 , mUsesGeometry( usesGeometry )
368 , mReferencedColumns( referencedColumns )
378 const QString &group,
379 const QString &helpText = QString(),
380 bool usesGeometry =
false,
381 const QSet<QString> &referencedColumns = QSet<QString>(),
382 bool lazyEval =
false,
383 const QStringList &aliases = QStringList(),
384 bool handlesNull =
false )
387 , mAliases( aliases )
388 , mUsesGeometry( usesGeometry )
389 , mReferencedColumns( referencedColumns )
406 const QString &group,
407 const QString &helpText,
410 bool lazyEval =
false,
411 const QStringList &aliases = QStringList(),
412 bool handlesNull =
false );
422 const QStringList &groups,
423 const QString &helpText = QString(),
424 bool usesGeometry =
false,
425 const QSet<QString> &referencedColumns = QSet<QString>(),
426 bool lazyEval =
false,
427 const QStringList &aliases = QStringList(),
428 bool handlesNull =
false )
431 , mAliases( aliases )
432 , mUsesGeometry( usesGeometry )
433 , mReferencedColumns( referencedColumns )
446 return mFnc ? mFnc( values, context, parent, node ) : QVariant();
449 QStringList aliases()
const override;
474 void setIsStatic(
bool isStatic );
487 static const QList<QgsExpressionFunction *> &functions();
491 QStringList mAliases;
493 std::function < bool( const QgsExpressionNodeFunction *node ) > mUsesGeometryFunc;
495 std::function < bool( const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) > mIsStaticFunc = allParamsStatic;
496 std::function < bool( const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) > mPrepareFunc;
497 QSet<QString> mReferencedColumns;
498 bool mIsStatic =
false;
528 void appendTemporaryVariable(
const QgsExpressionContext *context,
const QString &name,
const QVariant &value )
const;
538 #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.
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.
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.