Add method to remove feature from a QgsExpressionContextScope

This commit is contained in:
Nyall Dawson 2017-02-22 13:58:11 +10:00
parent abc6129b60
commit 4790035efa
3 changed files with 15 additions and 4 deletions

View File

@ -197,10 +197,8 @@ class QgsExpressionContextScope
void setFeature( const QgsFeature& feature );
/** Convenience function for setting a fields for the scope. Any existing
* fields set by the scope will be overwritten.
* @param fields fields for scope
*/
void removeFeature();
void setFields( const QgsFields& fields );
};

View File

@ -269,9 +269,19 @@ class CORE_EXPORT QgsExpressionContextScope
/** Convenience function for setting a feature for the scope. Any existing
* feature set by the scope will be overwritten.
* @param feature feature for scope
* @see removeFeature()
* @see feature()
*/
void setFeature( const QgsFeature& feature ) { mHasFeature = true; mFeature = feature; }
/**
* Removes any feature associated with the scope.
* @note added in QGIS 3.0
* @see setFeature()
* @see hasFeature()
*/
void removeFeature() { mHasFeature = false; mFeature = QgsFeature(); }
/** Convenience function for setting a fields for the scope. Any existing
* fields set by the scope will be overwritten.
* @param fields fields for scope

View File

@ -437,6 +437,9 @@ void TestQgsExpressionContext::setFeature()
scope.setFeature( feature );
QVERIFY( scope.hasFeature() );
QCOMPARE( scope.feature().id(), 50LL );
scope.removeFeature();
QVERIFY( !scope.hasFeature() );
QVERIFY( !scope.feature().isValid() );
//test setting a feature in a context with no scopes
QgsExpressionContext emptyContext;