Navigation Menu

Skip to content

Commit

Permalink
Add method to remove feature from a QgsExpressionContextScope
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 22, 2017
1 parent abc6129 commit 4790035
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions python/core/qgsexpressioncontext.sip
Expand Up @@ -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 );
};

Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsexpressioncontext.h
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgsexpressioncontext.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 4790035

Please sign in to comment.