Skip to content
Permalink
Browse files

Add equality operator for QgsTextFormat

  • Loading branch information
nyalldawson committed Jul 14, 2020
1 parent dfb6223 commit ac5a7226eed2caea86285abe2551356ae79a5a18
@@ -50,6 +50,9 @@ Copy constructor.

~QgsTextFormat();

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

bool isValid() const;
%Docstring
Returns ``True`` if the format is valid.
@@ -59,6 +59,36 @@ QgsTextFormat::~QgsTextFormat() //NOLINT

}

bool QgsTextFormat::operator==( const QgsTextFormat &other ) const
{
if ( d->isValid != other.isValid()
|| d->textFont != other.font()
|| d->textNamedStyle != other.namedStyle()
|| d->fontSizeUnits != other.sizeUnit()
|| d->fontSizeMapUnitScale != other.sizeMapUnitScale()
|| d->fontSize != other.size()
|| d->textColor != other.color()
|| d->opacity != other.opacity()
|| d->blendMode != other.blendMode()
|| d->multilineHeight != other.lineHeight()
|| d->orientation != other.orientation()
|| d->previewBackgroundColor != other.previewBackgroundColor()
|| d->allowHtmlFormatting != other.allowHtmlFormatting()
|| mBufferSettings != other.mBufferSettings
|| mBackgroundSettings != other.mBackgroundSettings
|| mShadowSettings != other.mShadowSettings
|| mMaskSettings != other.mMaskSettings
|| d->mDataDefinedProperties != other.dataDefinedProperties() )
return false;

return true;
}

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

bool QgsTextFormat::isValid() const
{
return d->isValid;
@@ -63,6 +63,9 @@ class CORE_EXPORT QgsTextFormat

~QgsTextFormat();

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

/**
* Returns TRUE if the format is valid.
*
@@ -695,6 +695,96 @@ def createFormatSettings(self):
s.dataDefinedProperties().setProperty(QgsPalLayerSettings.Bold, QgsProperty.fromExpression('1>2'))
return s

def testFormatEquality(self):
s = self.createFormatSettings()
s2 = self.createFormatSettings()
self.assertEqual(s, s2)

s.buffer().setEnabled(False)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.buffer().setSize(12)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.mask().setEnabled(False)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.mask().setSize(12)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.background().setEnabled(False)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.background().setSvgFile('test2.svg')
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.shadow().setEnabled(False)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.shadow().setOffsetAngle(123)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

font = getTestFont()
font.setKerning(True)
s.setFont(font)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setNamedStyle('Bold')
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setSize(15)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setSizeUnit(QgsUnitTypes.RenderPixels)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setSizeMapUnitScale(QgsMapUnitScale(11, 12))
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setColor(QColor(255, 255, 0))
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setOpacity(0.6)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setBlendMode(QPainter.CompositionMode_Darken)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setLineHeight(15)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setPreviewBackgroundColor(QColor(100, 250, 200))
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setOrientation(QgsTextFormat.HorizontalOrientation)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.setAllowHtmlFormatting(False)
self.assertNotEqual(s, s2)
s = self.createFormatSettings()

s.dataDefinedProperties().setProperty(QgsPalLayerSettings.Bold, QgsProperty.fromExpression('1>3'))
self.assertNotEqual(s, s2)

def checkTextFormat(self, s):
""" test QgsTextFormat """
self.assertTrue(s.buffer().enabled())

0 comments on commit ac5a722

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