Skip to content

Commit

Permalink
Fix failing equality operator test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 14, 2017
1 parent 3ca0b90 commit 3215173
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsproperty.sip
Expand Up @@ -90,6 +90,9 @@ class QgsProperty

operator bool() const;

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

Type propertyType() const;

bool isActive() const;
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsproperty.cpp
Expand Up @@ -237,6 +237,21 @@ QgsProperty &QgsProperty::operator=( const QgsProperty & other )
return *this;
}

bool QgsProperty::operator==( const QgsProperty& other ) const
{
return d->active == other.d->active
&& d->type == other.d->type
&& ( d->type != StaticProperty || d->staticValue == other.d->staticValue )
&& ( d->type != FieldBasedProperty || d->fieldName == other.d->fieldName )
&& ( d->type != ExpressionBasedProperty || d->expressionString == other.d->expressionString )
&& (( !d->transformer && !other.d->transformer ) || ( d->transformer && other.d->transformer && d->transformer->toExpression( QString() ) == other.d->transformer->toExpression( QString() ) ) );
}

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

QgsProperty::Type QgsProperty::propertyType() const
{
return static_cast< Type >( d->type );
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsproperty.h
Expand Up @@ -228,6 +228,9 @@ class CORE_EXPORT QgsProperty
*/
operator bool() const;

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

/**
* Returns the property type.
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/src/core/testqgsproperty.cpp
Expand Up @@ -593,6 +593,14 @@ void TestQgsProperty::equality()
dd1.setField( QStringLiteral( "field" ) );
QVERIFY( dd1 == dd2 );
QVERIFY( !( dd1 != dd2 ) );

// with transformer
dd1.setTransformer( new QgsGenericNumericTransformer( 1, 2, 3, 4 ) );
QVERIFY( !( dd1 == dd2 ) );
QVERIFY( dd1 != dd2 );
dd2.setTransformer( new QgsGenericNumericTransformer( 1, 2, 3, 4 ) );
QVERIFY( dd1 == dd2 );
QVERIFY( !( dd1 != dd2 ) );
}

void TestQgsProperty::propertyTransformer()
Expand Down

0 comments on commit 3215173

Please sign in to comment.