Navigation Menu

Skip to content

Commit

Permalink
Equality operator for QgsTextBackgroundSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 14, 2020
1 parent c575b82 commit 7547dbd
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
Expand Up @@ -63,6 +63,9 @@ Copy constructor.

~QgsTextBackgroundSettings();

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

bool enabled() const;
%Docstring
Returns whether the background is enabled.
Expand Down
43 changes: 43 additions & 0 deletions src/core/textrenderer/qgstextbackgroundsettings.cpp
Expand Up @@ -44,6 +44,49 @@ QgsTextBackgroundSettings::~QgsTextBackgroundSettings() //NOLINT

}

bool QgsTextBackgroundSettings::operator==( const QgsTextBackgroundSettings &other ) const
{
if ( !d->enabled == other.enabled()
|| d->type != other.type()
|| d->svgFile != other.svgFile()
|| d->sizeType != other.sizeType()
|| d->size != other.size()
|| d->sizeUnits != other.sizeUnit()
|| d->sizeMapUnitScale != other.sizeMapUnitScale()
|| d->rotationType != other.rotationType()
|| d->rotation != other.rotation()
|| d->offset != other.offset()
|| d->offsetUnits != other.offsetUnit()
|| d->offsetMapUnitScale != other.offsetMapUnitScale()
|| d->radii != other.radii()
|| d->radiiUnits != other.radiiUnit()
|| d->radiiMapUnitScale != other.radiiMapUnitScale()
|| d->blendMode != other.blendMode()
|| d->fillColor != other.fillColor()
|| d->strokeColor != other.strokeColor()
|| d->opacity != other.opacity()
|| d->strokeWidth != other.strokeWidth()
|| d->strokeWidthUnits != other.strokeWidthUnit()
|| d->strokeWidthMapUnitScale != other.strokeWidthMapUnitScale()
|| d->joinStyle != other.joinStyle() )
return false;

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

if ( static_cast< bool >( d->markerSymbol ) != static_cast< bool >( other.markerSymbol() )
|| ( d->markerSymbol && QgsSymbolLayerUtils::symbolProperties( d->markerSymbol.get() ) != QgsSymbolLayerUtils::symbolProperties( other.markerSymbol() ) ) )
return false;

return true;
}

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

bool QgsTextBackgroundSettings::enabled() const
{
return d->enabled;
Expand Down
3 changes: 3 additions & 0 deletions src/core/textrenderer/qgstextbackgroundsettings.h
Expand Up @@ -91,6 +91,9 @@ class CORE_EXPORT QgsTextBackgroundSettings

~QgsTextBackgroundSettings();

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

/**
* Returns whether the background is enabled.
* \see setEnabled()
Expand Down
97 changes: 97 additions & 0 deletions tests/src/python/test_qgstextrenderer.py
Expand Up @@ -307,6 +307,103 @@ def createBackgroundSettings(self):

return s

def testBackgroundEquality(self):
s = self.createBackgroundSettings()
s2 = self.createBackgroundSettings()
self.assertEqual(s, s2)

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

s.setType(QgsTextBackgroundSettings.ShapeRectangle)
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setSvgFile('svg2.svg')
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setSizeType(QgsTextBackgroundSettings.SizeFixed)
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setSize(QSizeF(1, 22))
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

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

s.setSizeMapUnitScale(QgsMapUnitScale(11, 22))
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setRotationType(QgsTextBackgroundSettings.RotationSync)
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setRotation(145)
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setOffset(QPointF(31, 41))
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setOffsetUnit(QgsUnitTypes.RenderPixels)
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setOffsetMapUnitScale(QgsMapUnitScale(15, 16))
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setRadii(QSizeF(111, 112))
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setRadiiUnit(QgsUnitTypes.RenderPoints)
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setRadiiMapUnitScale(QgsMapUnitScale(151, 161))
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setFillColor(QColor(255, 255, 0))
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setStrokeColor(QColor(0, 255, 255))
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

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

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

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

s.setStrokeWidth(17)
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

s.setStrokeWidthUnit(QgsUnitTypes.RenderPixels)
self.assertNotEqual(s, s2)
s = self.createBackgroundSettings()

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

def checkBackgroundSettings(self, s):
""" test QgsTextBackgroundSettings """
self.assertTrue(s.enabled())
Expand Down

0 comments on commit 7547dbd

Please sign in to comment.