@@ -4212,9 +4212,29 @@ const QList<QgsExpression::Function *> &QgsExpression::Functions()
4212
4212
<< new StaticFunction ( QStringLiteral ( " layer_property" ), 2 , fcnGetLayerProperty, QStringLiteral ( " General" ) )
4213
4213
<< new StaticFunction ( QStringLiteral ( " raster_statistic" ), ParameterList () << Parameter ( QStringLiteral ( " layer" ) )
4214
4214
<< Parameter ( QStringLiteral ( " band" ) )
4215
- << Parameter ( QStringLiteral ( " statistic" ) ), fcnGetRasterBandStat, QStringLiteral ( " General" ) )
4216
- << new StaticFunction ( QStringLiteral ( " var" ), 1 , fcnGetVariable, QStringLiteral ( " General" ) )
4215
+ << Parameter ( QStringLiteral ( " statistic" ) ), fcnGetRasterBandStat, QStringLiteral ( " General" ) );
4217
4216
4217
+ // **var** function
4218
+ StaticFunction *varFunction = new StaticFunction ( QStringLiteral ( " var" ), 1 , fcnGetVariable, QStringLiteral ( " General" ) );
4219
+ varFunction->setIsStaticFunction (
4220
+ []( const NodeFunction * node, QgsExpression * parent, const QgsExpressionContext * context )
4221
+ {
4222
+ if ( node->args ()->count () > 0 )
4223
+ {
4224
+ Node *argNode = node->args ()->at ( 0 );
4225
+
4226
+ if ( !argNode->isStatic ( parent, context ) )
4227
+ return false ;
4228
+
4229
+ if ( fcnGetVariable ( QVariantList () << argNode->eval ( parent, context ), context, parent ).isValid () )
4230
+ return true ;
4231
+ }
4232
+ return false ;
4233
+ }
4234
+ );
4235
+
4236
+ sFunctions
4237
+ << varFunction
4218
4238
// return all attributes string for referencedColumns - this is caught by
4219
4239
// QgsFeatureRequest::setSubsetOfAttributes and causes all attributes to be fetched by the
4220
4240
// feature request
@@ -5590,10 +5610,7 @@ QgsExpression::Node *QgsExpression::NodeFunction::clone() const
5590
5610
5591
5611
bool QgsExpression::NodeFunction::isStatic ( QgsExpression *parent, const QgsExpressionContext *context ) const
5592
5612
{
5593
- Q_UNUSED ( parent )
5594
- Q_UNUSED ( context )
5595
- // TODO some functions are static!
5596
- return false ;
5613
+ return Functions ()[mFnIndex ]->isStatic ( this , parent, context );
5597
5614
}
5598
5615
5599
5616
bool QgsExpression::NodeFunction::validateParams ( int fnIndex, QgsExpression::NodeList *args, QString &error )
@@ -6299,6 +6316,14 @@ bool QgsExpression::Function::usesGeometry( const QgsExpression::NodeFunction *n
6299
6316
return true ;
6300
6317
}
6301
6318
6319
+ bool QgsExpression::Function::isStatic ( const QgsExpression::NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const
6320
+ {
6321
+ Q_UNUSED ( parent )
6322
+ Q_UNUSED ( context )
6323
+ Q_UNUSED ( node )
6324
+ return false ;
6325
+ }
6326
+
6302
6327
QSet<QString> QgsExpression::Function::referencedColumns ( const NodeFunction *node ) const
6303
6328
{
6304
6329
Q_UNUSED ( node )
@@ -6310,7 +6335,15 @@ bool QgsExpression::Function::operator==( const QgsExpression::Function &other )
6310
6335
return ( QString::compare ( mName , other.mName , Qt::CaseInsensitive ) == 0 );
6311
6336
}
6312
6337
6313
- QgsExpression::StaticFunction::StaticFunction ( const QString &fnname, const QgsExpression::ParameterList ¶ms, QgsExpression::FcnEval fcn, const QString &group, const QString &helpText, std::function < bool ( const QgsExpression::NodeFunction *node ) > usesGeometry, std::function < QSet<QString>( const QgsExpression::NodeFunction *node ) > referencedColumns, bool lazyEval, const QStringList &aliases, bool handlesNull )
6338
+ QgsExpression::StaticFunction::StaticFunction ( const QString &fnname, const QgsExpression::ParameterList ¶ms,
6339
+ QgsExpression::FcnEval fcn,
6340
+ const QString &group,
6341
+ const QString &helpText,
6342
+ std::function < bool ( const QgsExpression::NodeFunction *node ) > usesGeometry,
6343
+ std::function < QSet<QString>( const QgsExpression::NodeFunction *node ) > referencedColumns,
6344
+ bool lazyEval,
6345
+ const QStringList &aliases,
6346
+ bool handlesNull )
6314
6347
: Function( fnname, params, group, helpText, lazyEval, handlesNull )
6315
6348
, mFnc( fcn )
6316
6349
, mAliases( aliases )
@@ -6336,6 +6369,19 @@ QSet<QString> QgsExpression::StaticFunction::referencedColumns( const NodeFuncti
6336
6369
return mReferencedColumns ;
6337
6370
}
6338
6371
6372
+ bool QgsExpression::StaticFunction::isStatic ( const NodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context ) const
6373
+ {
6374
+ if ( mIsStaticFunc )
6375
+ return mIsStaticFunc ( node, parent, context );
6376
+ else
6377
+ return false ;
6378
+ }
6379
+
6380
+ void QgsExpression::StaticFunction::setIsStaticFunction ( std::function<bool ( const NodeFunction *, QgsExpression *, const QgsExpressionContext * )> isStatic )
6381
+ {
6382
+ mIsStaticFunc = isStatic;
6383
+ }
6384
+
6339
6385
QVariant QgsExpression::Node::eval ( QgsExpression *parent, const QgsExpressionContext *context )
6340
6386
{
6341
6387
if ( mHasCachedValue )
0 commit comments