Skip to content
Permalink
Browse files

Add equality operators to QgsPropertyCollection

  • Loading branch information
nyalldawson committed Jul 14, 2020
1 parent 9bad557 commit dfb6223390a9dd97f98ebfc8dacd275a0cbcc4b3
@@ -389,6 +389,9 @@ Copy constructor.
%End


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

int count() const;
%Docstring
Returns the number of properties contained within the collection.
@@ -144,6 +144,16 @@ QgsPropertyCollection &QgsPropertyCollection::operator=( const QgsPropertyCollec
return *this;
}

bool QgsPropertyCollection::operator==( const QgsPropertyCollection &other ) const
{
return mProperties == other.mProperties;
}

bool QgsPropertyCollection::operator!=( const QgsPropertyCollection &other ) const
{
return !( *this == other );
}

int QgsPropertyCollection::count() const
{
if ( !mDirty )
@@ -332,6 +332,9 @@ class CORE_EXPORT QgsPropertyCollection : public QgsAbstractPropertyCollection

QgsPropertyCollection &operator=( const QgsPropertyCollection &other );

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

/**
* Returns the number of properties contained within the collection.
*/
@@ -1375,6 +1375,10 @@ void TestQgsProperty::propertyCollection()
QVERIFY( !collection.hasDynamicProperties() );
QVERIFY( !collection.hasActiveProperties() );

QgsPropertyCollection collection2;
QVERIFY( collection == collection2 );
QVERIFY( !( collection != collection2 ) );

QgsProperty property = QgsProperty::fromValue( "value", true );
collection.setProperty( Property1, property );
QVERIFY( collection.hasProperty( Property1 ) );
@@ -1386,6 +1390,12 @@ void TestQgsProperty::propertyCollection()
QVERIFY( collection.hasActiveProperties() );
QVERIFY( !collection.hasDynamicProperties() );

QVERIFY( collection != collection2 );
QVERIFY( !( collection == collection2 ) );
collection2.setProperty( Property1, property );
QVERIFY( collection == collection2 );
QVERIFY( !( collection != collection2 ) );

//preparation
QVERIFY( collection.prepare( context ) );

@@ -1403,6 +1413,8 @@ void TestQgsProperty::propertyCollection()
QCOMPARE( collection.property( Property1 ).value( context ), property2.value( context ) );
QVERIFY( collection.hasActiveProperties() );
QVERIFY( !collection.hasDynamicProperties() );
QVERIFY( collection != collection2 );
QVERIFY( !( collection == collection2 ) );

//implicit conversion
collection.setProperty( Property3, 5 );
@@ -1432,6 +1444,13 @@ void TestQgsProperty::propertyCollection()
collection.setProperty( Property4, QgsProperty::fromExpression( QStringLiteral( "\"field1\" + \"field2\"" ), true ) );
QCOMPARE( collection.count(), 4 );

collection2 = collection;
QVERIFY( collection == collection2 );
QVERIFY( !( collection != collection2 ) );
collection2.setProperty( Property3, QgsProperty() );
QVERIFY( collection != collection2 );
QVERIFY( !( collection == collection2 ) );

// test referenced fields
QCOMPARE( collection.referencedFields( context ).count(), 2 );
QVERIFY( collection.referencedFields( context ).contains( "field1" ) );
@@ -1466,7 +1485,7 @@ void TestQgsProperty::propertyCollection()
QVERIFY( restoredCollection.hasDynamicProperties() );

// copy constructor
QgsPropertyCollection collection2( collection );
collection2 = QgsPropertyCollection( collection );
QCOMPARE( collection2.name(), QStringLiteral( "collection" ) );
QCOMPARE( collection2.count(), 4 );
QCOMPARE( collection2.property( Property1 ).propertyType(), QgsProperty::StaticProperty );

0 comments on commit dfb6223

Please sign in to comment.
You can’t perform that action at this time.