Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore QgsFeature equality operators in Python
Browse files Browse the repository at this point in the history
These were (accidentally?) ommited in 9050cc1, and then
incorrectly marked as sip_skip when sipify was first introduced
as a result
nyalldawson committed Aug 6, 2022
1 parent 2f0df49 commit a185f5c
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgsfeature.sip.in
Original file line number Diff line number Diff line change
@@ -156,7 +156,9 @@ Copy constructor
%End


bool operator==( const QgsFeature &other ) const;

bool operator!=( const QgsFeature &other ) const;

virtual ~QgsFeature();

6 changes: 3 additions & 3 deletions src/core/qgsfeature.h
Original file line number Diff line number Diff line change
@@ -200,17 +200,17 @@ class CORE_EXPORT QgsFeature
/**
* Assignment operator
*/
QgsFeature &operator=( const QgsFeature &rhs ) SIP_SKIP;
QgsFeature &operator=( const QgsFeature &rhs );

/**
* Compares two features
*/
bool operator==( const QgsFeature &other ) const SIP_SKIP;
bool operator==( const QgsFeature &other ) const;

/**
* Compares two features
*/
bool operator!=( const QgsFeature &other ) const SIP_SKIP;
bool operator!=( const QgsFeature &other ) const;

virtual ~QgsFeature();

41 changes: 41 additions & 0 deletions tests/src/python/test_qgsfeature.py
Original file line number Diff line number Diff line change
@@ -57,6 +57,47 @@ def test_FeatureDefaultConstructor(self):
feat = QgsFeature(QgsFields(), 1234)
self.assertEqual(feat.id(), 1234)

def test_equality(self):
fields = QgsFields()
field1 = QgsField('my_field')
fields.append(field1)
field2 = QgsField('my_field2')
fields.append(field2)

feat = QgsFeature(fields, 0)
feat.initAttributes(1)
feat.setAttribute(0, "text")
feat.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(123, 456)))

self.assertNotEqual(feat, QgsFeature())

feat2 = QgsFeature(fields, 0)
feat2.initAttributes(1)
feat2.setAttribute(0, "text")
feat2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(123, 456)))

self.assertEqual(feat, feat2)

feat2.setId(5)
self.assertNotEqual(feat, feat2)
feat2.setId(0)
self.assertEqual(feat, feat2)

feat2.setAttribute(0, "text2")
self.assertNotEqual(feat, feat2)
feat2.setAttribute(0, "text")
self.assertEqual(feat, feat2)

feat2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(1231, 4561)))
self.assertNotEqual(feat, feat2)
feat2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(123, 456)))
self.assertEqual(feat, feat2)

field2 = QgsField('my_field3')
fields.append(field2)
feat2.setFields(fields)
self.assertNotEqual(feat, feat2)

def test_ValidFeature(self):
myPath = os.path.join(unitTestDataPath(), 'points.shp')
myLayer = QgsVectorLayer(myPath, 'Points', 'ogr')

0 comments on commit a185f5c

Please sign in to comment.