Skip to content

Commit 4790035

Browse files
committedFeb 22, 2017
Add method to remove feature from a QgsExpressionContextScope
1 parent abc6129 commit 4790035

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed
 

‎python/core/qgsexpressioncontext.sip

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,8 @@ class QgsExpressionContextScope
197197

198198
void setFeature( const QgsFeature& feature );
199199

200-
/** Convenience function for setting a fields for the scope. Any existing
201-
* fields set by the scope will be overwritten.
202-
* @param fields fields for scope
203-
*/
200+
void removeFeature();
201+
204202
void setFields( const QgsFields& fields );
205203
};
206204

‎src/core/qgsexpressioncontext.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,19 @@ class CORE_EXPORT QgsExpressionContextScope
269269
/** Convenience function for setting a feature for the scope. Any existing
270270
* feature set by the scope will be overwritten.
271271
* @param feature feature for scope
272+
* @see removeFeature()
273+
* @see feature()
272274
*/
273275
void setFeature( const QgsFeature& feature ) { mHasFeature = true; mFeature = feature; }
274276

277+
/**
278+
* Removes any feature associated with the scope.
279+
* @note added in QGIS 3.0
280+
* @see setFeature()
281+
* @see hasFeature()
282+
*/
283+
void removeFeature() { mHasFeature = false; mFeature = QgsFeature(); }
284+
275285
/** Convenience function for setting a fields for the scope. Any existing
276286
* fields set by the scope will be overwritten.
277287
* @param fields fields for scope

‎tests/src/core/testqgsexpressioncontext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ void TestQgsExpressionContext::setFeature()
437437
scope.setFeature( feature );
438438
QVERIFY( scope.hasFeature() );
439439
QCOMPARE( scope.feature().id(), 50LL );
440+
scope.removeFeature();
441+
QVERIFY( !scope.hasFeature() );
442+
QVERIFY( !scope.feature().isValid() );
440443

441444
//test setting a feature in a context with no scopes
442445
QgsExpressionContext emptyContext;

0 commit comments

Comments
 (0)
Please sign in to comment.