Skip to content
Permalink
Browse files
Add equality operator for QgsProviderSublayerDetails
  • Loading branch information
nyalldawson committed Jul 2, 2021
1 parent 998c6c1 commit 65bccd2c61844b5f1e986b26671df6580061ef36
@@ -211,6 +211,9 @@ Sets the associated layer ``number``, for providers which order sublayers.
.. seealso:: :py:func:`layerNumber`
%End

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

};


@@ -23,3 +23,22 @@ QgsMapLayer *QgsProviderSublayerDetails::toLayer( const LayerOptions &options )
{
return QgsMapLayerFactory::createLayer( mUri, mName, mType, mProviderKey, options.transformContext );
}

bool QgsProviderSublayerDetails::operator==( const QgsProviderSublayerDetails &other ) const
{
return mProviderKey == other.mProviderKey
&& mType == other.mType
&& mUri == other.mUri
&& mLayerNumber == other.mLayerNumber
&& mName == other.mName
&& mDescription == other.mDescription
&& mFeatureCount == other.mFeatureCount
&& mGeometryColumnName == other.mGeometryColumnName
&& mPath == other.mPath
&& mWkbType == other.mWkbType;
}

bool QgsProviderSublayerDetails::operator!=( const QgsProviderSublayerDetails &other ) const
{
return !( *this == other );
}
@@ -230,6 +230,9 @@ class CORE_EXPORT QgsProviderSublayerDetails
*/
void setLayerNumber( int number ) { mLayerNumber = number; }

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

private:

QString mProviderKey;
@@ -69,6 +69,58 @@ def testGettersSetters(self):
d.setLayerNumber(13)
self.assertEqual(d.layerNumber(), 13)

def test_equality(self):
"""
Test equality operator
"""
d = QgsProviderSublayerDetails()
d2 = QgsProviderSublayerDetails()
d.setProviderKey('key')
self.assertNotEqual(d, d2)
d2.setProviderKey('key')
self.assertEqual(d, d2)

d.setType(QgsMapLayerType.MeshLayer)
self.assertNotEqual(d, d2)
d2.setType(QgsMapLayerType.MeshLayer)
self.assertEqual(d, d2)

d.setUri('some uri')
self.assertNotEqual(d, d2)
d2.setUri('some uri')
self.assertEqual(d, d2)

d.setName('name')
self.assertNotEqual(d, d2)
d2.setName('name')
self.assertEqual(d, d2)

d.setDescription('desc')
self.assertNotEqual(d, d2)
d2.setDescription('desc')
self.assertEqual(d, d2)

d.setPath(['a', 'b', 'c'])
self.assertNotEqual(d, d2)
d2.setPath(['a', 'b', 'c'])
self.assertEqual(d, d2)

d.setFeatureCount(1000)
self.assertNotEqual(d, d2)
d2.setFeatureCount(1000)
self.assertEqual(d, d2)

d.setWkbType(QgsWkbTypes.Point)
self.assertNotEqual(d, d2)
d2.setWkbType(QgsWkbTypes.Point)
self.assertEqual(d, d2)

d.setGeometryColumnName('geom_col')
self.assertEqual(d.geometryColumnName(), 'geom_col')

d.setLayerNumber(13)
self.assertEqual(d.layerNumber(), 13)

def test_to_layer(self):
"""
Test converting sub layer details to a layer

0 comments on commit 65bccd2

Please sign in to comment.