@@ -432,27 +432,28 @@ void TestQgsExpressionContext::evaluate()
432
432
void TestQgsExpressionContext::setFeature ()
433
433
{
434
434
QgsFeature feature ( 50LL );
435
+ feature.setValid ( true );
435
436
QgsExpressionContextScope scope;
436
437
scope.setFeature ( feature );
437
- QVERIFY ( scope.hasVariable ( QgsExpressionContext::EXPR_FEATURE ) );
438
- QCOMPARE (( qvariant_cast<QgsFeature>( scope.variable ( QgsExpressionContext::EXPR_FEATURE ) ) ).id (), 50LL );
438
+ QVERIFY ( scope.hasFeature ( ) );
439
+ QCOMPARE ( scope.feature ( ).id (), 50LL );
439
440
440
441
// test setting a feature in a context with no scopes
441
442
QgsExpressionContext emptyContext;
442
443
QVERIFY ( !emptyContext.feature ().isValid () );
443
444
emptyContext.setFeature ( feature );
444
445
// setFeature should have created a scope
445
446
QCOMPARE ( emptyContext.scopeCount (), 1 );
446
- QVERIFY ( emptyContext.hasVariable ( QgsExpressionContext::EXPR_FEATURE ) );
447
- QCOMPARE (( qvariant_cast<QgsFeature>( emptyContext.variable ( QgsExpressionContext::EXPR_FEATURE ) ) ).id (), 50LL );
447
+ QVERIFY ( emptyContext.feature (). isValid ( ) );
448
+ QCOMPARE ( emptyContext.feature ( ).id (), 50LL );
448
449
QCOMPARE ( emptyContext.feature ().id (), 50LL );
449
450
450
451
QgsExpressionContext contextWithScope;
451
452
contextWithScope << new QgsExpressionContextScope ();
452
453
contextWithScope.setFeature ( feature );
453
454
QCOMPARE ( contextWithScope.scopeCount (), 1 );
454
- QVERIFY ( contextWithScope.hasVariable ( QgsExpressionContext::EXPR_FEATURE ) );
455
- QCOMPARE (( qvariant_cast<QgsFeature>( contextWithScope.variable ( QgsExpressionContext::EXPR_FEATURE ) ) ).id (), 50LL );
455
+ QVERIFY ( contextWithScope.feature (). isValid ( ) );
456
+ QCOMPARE ( contextWithScope.feature ( ).id (), 50LL );
456
457
QCOMPARE ( contextWithScope.feature ().id (), 50LL );
457
458
}
458
459
@@ -652,7 +653,7 @@ void TestQgsExpressionContext::featureBasedContext()
652
653
653
654
QgsExpressionContext context = QgsExpressionContextUtils::createFeatureBasedContext ( f, fields );
654
655
655
- QgsFeature evalFeature = qvariant_cast<QgsFeature>( context.variable ( QStringLiteral ( " _feature_ " ) ) );
656
+ QgsFeature evalFeature = context.feature ( );
656
657
QgsFields evalFields = qvariant_cast<QgsFields>( context.variable ( QStringLiteral ( " _fields_" ) ) );
657
658
QCOMPARE ( evalFeature.attributes (), f.attributes () );
658
659
QCOMPARE ( evalFields, fields );
0 commit comments