mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
Add equality operator for QgsNumericFormat
This commit is contained in:
parent
9835ab06ea
commit
31cdf131b3
@ -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 @@ 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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user