Skip to content
Permalink
Browse files

Add equality operator for QgsNumericFormat

  • Loading branch information
nyalldawson committed Jan 13, 2020
1 parent 9835ab0 commit 31cdf131b39cd01f2099f23966ae8fc3c57d22e5
@@ -236,6 +236,9 @@ Writes the format to an XML ``element``.
.. seealso:: :py:func:`QgsNumericFormatRegistry.createFromXml`
%End

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

};

/************************************************************************
@@ -16,6 +16,7 @@

#include "qgsnumericformat.h"
#include "qgsxmlutils.h"
#include "qgsreadwritecontext.h"

#include <QLocale>

@@ -49,3 +50,13 @@ void QgsNumericFormat::writeXml( QDomElement &element, QDomDocument &document, c
element.setAttribute( QStringLiteral( "id" ), id() );
}

bool QgsNumericFormat::operator==( const QgsNumericFormat &other ) const
{
return id() == other.id() && configuration( QgsReadWriteContext() ) == other.configuration( QgsReadWriteContext() );
}

bool QgsNumericFormat::operator!=( const QgsNumericFormat &other ) const
{
return !operator==( other );
}

@@ -300,6 +300,9 @@ class CORE_EXPORT QgsNumericFormat
*/
void writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;

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

};

#endif // QGSNUMERICFORMAT_H
@@ -70,6 +70,16 @@ def testFallbackFormat(self):
f3 = QgsNumericFormatRegistry().createFromXml(elem, QgsReadWriteContext())
self.assertIsInstance(f3, QgsFallbackNumericFormat)

def testEquality(self):
f = QgsBasicNumericFormat()
f2 = QgsBasicNumericFormat()
self.assertEqual(f, f2)
f2.setShowPlusSign(True)
self.assertNotEqual(f, f2)
f.setShowPlusSign(True)
self.assertEqual(f, f2)
self.assertNotEqual(f, QgsCurrencyNumericFormat())

def testBasicFormat(self):
""" test basic formatter """
f = QgsBasicNumericFormat()

0 comments on commit 31cdf13

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