Add equality operator for QgsNumericFormat

This commit is contained in:
Nyall Dawson 2020-01-13 13:03:09 +10:00
parent 9835ab06ea
commit 31cdf131b3
4 changed files with 27 additions and 0 deletions

View File

@ -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;
};
/************************************************************************

View File

@ -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 );
}

View File

@ -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

View File

@ -70,6 +70,16 @@ class TestQgsNumericFormat(unittest.TestCase):
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()