@@ -310,6 +310,7 @@ static QgsExpression::Interval getInterval( const QVariant& value, QgsExpression
310
310
311
311
return QgsExpression::Interval::invalidInterVal ();
312
312
}
313
+
313
314
static QgsGeometry getGeometry ( const QVariant& value, QgsExpression* parent )
314
315
{
315
316
if ( value.canConvert <QgsGeometry>() )
@@ -319,6 +320,14 @@ static QgsGeometry getGeometry( const QVariant& value, QgsExpression* parent )
319
320
return QgsGeometry ();
320
321
}
321
322
323
+ static QgsFeature getFeature ( const QVariant& value, QgsExpression* parent )
324
+ {
325
+ if ( value.canConvert <QgsFeature>() )
326
+ return value.value <QgsFeature>();
327
+
328
+ parent->setEvalErrorString ( " Cannot convert to QgsFeature" );
329
+ return 0 ;
330
+ }
322
331
323
332
// this handles also NULL values
324
333
static TVL getTVLValue ( const QVariant& value, QgsExpression* parent )
@@ -786,6 +795,17 @@ static QVariant fcnFeatureId( const QVariantList& , const QgsFeature* f, QgsExpr
786
795
return f ? QVariant (( int )f->id () ) : QVariant ();
787
796
}
788
797
798
+ static QVariant fcnFeature ( const QVariantList& , const QgsFeature* f, QgsExpression* )
799
+ {
800
+ return f ? QVariant::fromValue ( *f ) : QVariant ();
801
+ }
802
+ static QVariant fcnAttribute ( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
803
+ {
804
+ QgsFeature feat = getFeature ( values.at ( 0 ), parent );
805
+ QString attr = getStringValue ( values.at ( 1 ), parent );
806
+
807
+ return feat.attribute ( attr );
808
+ }
789
809
static QVariant fcnConcat ( const QVariantList& values, const QgsFeature* , QgsExpression *parent )
790
810
{
791
811
QString concat;
@@ -1660,8 +1680,15 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
1660
1680
<< new StaticFunction ( " geomToWKT" , 1 , fcnGeomToWKT, " Geometry" )
1661
1681
<< new StaticFunction ( " $rownum" , 0 , fcnRowNumber, " Record" )
1662
1682
<< new StaticFunction ( " $id" , 0 , fcnFeatureId, " Record" )
1683
+ << new StaticFunction ( " $currentfeature" , 0 , fcnFeature, " Features" )
1663
1684
<< new StaticFunction ( " $scale" , 0 , fcnScale, " Record" )
1664
1685
<< new StaticFunction ( " $uuid" , 0 , fcnUuid, " Record" )
1686
+
1687
+ // return all attributes string for referencedColumns - this is caught by
1688
+ // QgsFeatureRequest::setSubsetOfAttributes and causes all attributes to be fetched by the
1689
+ // feature request
1690
+ << new StaticFunction ( " attribute" , 2 , fcnAttribute, " Features" , QString (), false , QStringList ( QgsFeatureRequest::AllAttributes ) )
1691
+
1665
1692
<< new StaticFunction ( " _specialcol_" , 1 , fcnSpecialColumn, " Special" )
1666
1693
;
1667
1694
}
@@ -1804,6 +1831,7 @@ QStringList QgsExpression::referencedColumns()
1804
1831
{
1805
1832
if ( !mRootNode )
1806
1833
return QStringList ();
1834
+
1807
1835
QStringList columns = mRootNode ->referencedColumns ();
1808
1836
1809
1837
// filter out duplicates
@@ -2428,6 +2456,26 @@ QString QgsExpression::NodeFunction::dump() const
2428
2456
return QString ( " %1(%2)" ).arg ( fd->name () ).arg ( mArgs ? mArgs ->dump () : QString () ); // function
2429
2457
}
2430
2458
2459
+ QStringList QgsExpression::NodeFunction::referencedColumns () const
2460
+ {
2461
+ Function* fd = Functions ()[mFnIndex ];
2462
+ QStringList functionColumns = fd->referencedColumns ();
2463
+
2464
+ if ( !mArgs )
2465
+ {
2466
+ // no referenced columns in arguments, just return function's referenced columns
2467
+ return functionColumns;
2468
+ }
2469
+
2470
+ foreach ( Node* n, mArgs ->list () )
2471
+ {
2472
+ functionColumns.append ( n->referencedColumns () );
2473
+ }
2474
+
2475
+ // remove duplicates and return
2476
+ return functionColumns.toSet ().toList ();
2477
+ }
2478
+
2431
2479
//
2432
2480
2433
2481
QVariant QgsExpression::NodeLiteral::eval ( QgsExpression* , const QgsFeature* )
0 commit comments