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