Skip to content
Permalink
Browse files

Add equality operator for QgsTextBufferSettings

  • Loading branch information
nyalldawson committed Jul 14, 2020
1 parent 7547dbd commit 305fa330bd90c8ab0b791f95b22e80bf572ba8ad
@@ -39,6 +39,9 @@ Copy constructor.

~QgsTextBufferSettings();

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

bool enabled() const;
%Docstring
Returns whether the buffer is enabled.
@@ -44,6 +44,31 @@ QgsTextBufferSettings::~QgsTextBufferSettings() //NOLINT

}

bool QgsTextBufferSettings::operator==( const QgsTextBufferSettings &other ) const
{
if ( d->enabled != other.enabled()
|| d->size != other.size()
|| d->sizeUnit != other.sizeUnit()
|| d->sizeMapUnitScale != other.sizeMapUnitScale()
|| d->color != other.color()
|| d->opacity != other.opacity()
|| d->fillBufferInterior != other.fillBufferInterior()
|| d->joinStyle != other.joinStyle()
|| d->blendMode != other.blendMode() )
return false;

if ( static_cast< bool >( d->paintEffect ) != static_cast< bool >( other.paintEffect() )
|| ( d->paintEffect && d->paintEffect->properties() != other.paintEffect()->properties() ) )
return false;

return true;
}

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

bool QgsTextBufferSettings::enabled() const
{
return d->enabled;
@@ -59,6 +59,9 @@ class CORE_EXPORT QgsTextBufferSettings

~QgsTextBufferSettings();

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

/**
* Returns whether the buffer is enabled.
* \see setEnabled()
@@ -180,6 +180,46 @@ def createBufferSettings(self):
s.setBlendMode(QPainter.CompositionMode_DestinationAtop)
return s

def testBufferEquality(self):
s = self.createBufferSettings()
s2 = self.createBufferSettings()
self.assertEqual(s, s2)

s.setEnabled(False)
self.assertNotEqual(s, s2)
s = self.createBufferSettings()

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

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

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

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

s.setFillBufferInterior(False)
self.assertNotEqual(s, s2)
s = self.createBufferSettings()

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

s.setJoinStyle(Qt.MiterJoin)
self.assertNotEqual(s, s2)
s = self.createBufferSettings()

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

def checkBufferSettings(self, s):
""" test QgsTextBufferSettings """
self.assertTrue(s.enabled())
@@ -402,7 +442,6 @@ def testBackgroundEquality(self):

s.setStrokeWidthMapUnitScale(QgsMapUnitScale(QgsMapUnitScale(251, 261)))
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

def checkBackgroundSettings(self, s):
""" test QgsTextBackgroundSettings """

0 comments on commit 305fa33

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