Skip to content

Commit

Permalink
Add equality operator for QgsTextBufferSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 14, 2020
1 parent 7547dbd commit 305fa33
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions src/core/textrenderer/qgstextbuffersettings.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/textrenderer/qgstextbuffersettings.h
Expand Up @@ -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()
Expand Down
41 changes: 40 additions & 1 deletion tests/src/python/test_qgstextrenderer.py
Expand Up @@ -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())
Expand Down Expand Up @@ -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 """
Expand Down

0 comments on commit 305fa33

Please sign in to comment.