@@ -3315,6 +3315,31 @@ static QVariant fcnTransformGeometry( const QVariantList &values, const QgsExpre
3315
3315
}
3316
3316
3317
3317
3318
+ static QVariant fcnGetFeatureById ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
3319
+ {
3320
+ QVariant result;
3321
+ QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer ( values.at ( 0 ), parent );
3322
+ if ( !vl )
3323
+ return result;
3324
+
3325
+ QgsFeatureId fid = QgsExpressionUtils::getIntValue ( values.at ( 1 ), parent );
3326
+
3327
+ QgsFeatureRequest req;
3328
+ req.setFilterFid ( fid );
3329
+ req.setLimit ( 1 );
3330
+ if ( !parent->needsGeometry () )
3331
+ {
3332
+ req.setFlags ( QgsFeatureRequest::NoGeometry );
3333
+ }
3334
+ QgsFeatureIterator fIt = vl->getFeatures ( req );
3335
+
3336
+ QgsFeature fet;
3337
+ if ( fIt .nextFeature ( fet ) )
3338
+ result = QVariant::fromValue ( fet );
3339
+
3340
+ return result;
3341
+ }
3342
+
3318
3343
static QVariant fcnGetFeature ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
3319
3344
{
3320
3345
// arguments: 1. layer id / name, 2. key attribute, 3. eq value
@@ -4144,7 +4169,8 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
4144
4169
sFunctions << uuidFunc;
4145
4170
4146
4171
sFunctions
4147
- << new QgsStaticExpressionFunction ( QStringLiteral ( " get_feature" ), 3 , fcnGetFeature, QStringLiteral ( " Record" ), QString (), false , QSet<QString>(), false , QStringList () << QStringLiteral ( " QgsExpressionUtils::getFeature" ) );
4172
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " get_feature" ), 3 , fcnGetFeature, QStringLiteral ( " Record" ), QString (), false , QSet<QString>(), false , QStringList () << QStringLiteral ( " QgsExpressionUtils::getFeature" ) )
4173
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " get_feature_by_id" ), 2 , fcnGetFeatureById, QStringLiteral ( " Record" ), QString (), false , QSet<QString>(), false );
4148
4174
4149
4175
QgsStaticExpressionFunction *isSelectedFunc = new QgsStaticExpressionFunction (
4150
4176
QStringLiteral ( " is_selected" ),
0 commit comments