Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add equality operators to QgsPropertyCollection
  • Loading branch information
nyalldawson committed Jul 14, 2020
1 parent 9bad557 commit dfb6223
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgspropertycollection.sip.in
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgspropertycollection.cpp
Expand Up @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgspropertycollection.h
Expand Up @@ -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.
*/
Expand Down
21 changes: 20 additions & 1 deletion tests/src/core/testqgsproperty.cpp
Expand Up @@ -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 ) );
Expand All @@ -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 ) );

Expand All @@ -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 );
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit dfb6223

Please sign in to comment.