Skip to content

Commit 3215173

Browse files
committed
Fix failing equality operator test
1 parent 3ca0b90 commit 3215173

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

python/core/qgsproperty.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class QgsProperty
9090

9191
operator bool() const;
9292

93+
bool operator==( const QgsProperty& other ) const;
94+
bool operator!=( const QgsProperty& other ) const;
95+
9396
Type propertyType() const;
9497

9598
bool isActive() const;

src/core/qgsproperty.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,21 @@ QgsProperty &QgsProperty::operator=( const QgsProperty & other )
237237
return *this;
238238
}
239239

240+
bool QgsProperty::operator==( const QgsProperty& other ) const
241+
{
242+
return d->active == other.d->active
243+
&& d->type == other.d->type
244+
&& ( d->type != StaticProperty || d->staticValue == other.d->staticValue )
245+
&& ( d->type != FieldBasedProperty || d->fieldName == other.d->fieldName )
246+
&& ( d->type != ExpressionBasedProperty || d->expressionString == other.d->expressionString )
247+
&& (( !d->transformer && !other.d->transformer ) || ( d->transformer && other.d->transformer && d->transformer->toExpression( QString() ) == other.d->transformer->toExpression( QString() ) ) );
248+
}
249+
250+
bool QgsProperty::operator!=( const QgsProperty& other ) const
251+
{
252+
return ( !(( *this ) == other ) );
253+
}
254+
240255
QgsProperty::Type QgsProperty::propertyType() const
241256
{
242257
return static_cast< Type >( d->type );

src/core/qgsproperty.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ class CORE_EXPORT QgsProperty
228228
*/
229229
operator bool() const;
230230

231+
bool operator==( const QgsProperty& other ) const;
232+
bool operator!=( const QgsProperty& other ) const;
233+
231234
/**
232235
* Returns the property type.
233236
*/

tests/src/core/testqgsproperty.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,14 @@ void TestQgsProperty::equality()
593593
dd1.setField( QStringLiteral( "field" ) );
594594
QVERIFY( dd1 == dd2 );
595595
QVERIFY( !( dd1 != dd2 ) );
596+
597+
// with transformer
598+
dd1.setTransformer( new QgsGenericNumericTransformer( 1, 2, 3, 4 ) );
599+
QVERIFY( !( dd1 == dd2 ) );
600+
QVERIFY( dd1 != dd2 );
601+
dd2.setTransformer( new QgsGenericNumericTransformer( 1, 2, 3, 4 ) );
602+
QVERIFY( dd1 == dd2 );
603+
QVERIFY( !( dd1 != dd2 ) );
596604
}
597605

598606
void TestQgsProperty::propertyTransformer()

0 commit comments

Comments
 (0)