Skip to content

Commit

Permalink
Add an equality operator for QgsTextMaskSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 14, 2020
1 parent 305fa33 commit 52d7d18
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
Expand Up @@ -46,6 +46,9 @@ Copy constructor.

~QgsTextMaskSettings();

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

bool enabled() const;
%Docstring
Returns whether the mask is enabled.
Expand Down
24 changes: 24 additions & 0 deletions src/core/textrenderer/qgstextmasksettings.cpp
Expand Up @@ -37,6 +37,30 @@ QgsTextMaskSettings &QgsTextMaskSettings::operator=( const QgsTextMaskSettings &
return *this;
}

bool QgsTextMaskSettings::operator==( const QgsTextMaskSettings &other ) const
{
if ( d->enabled != other.enabled()
|| d->type != other.type()
|| d->size != other.size()
|| d->sizeUnit != other.sizeUnit()
|| d->sizeMapUnitScale != other.sizeMapUnitScale()
|| d->joinStyle != other.joinStyle()
|| d->opacity != other.opacity()
|| d->maskedSymbolLayers != other.maskedSymbolLayers() )
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 QgsTextMaskSettings::operator!=( const QgsTextMaskSettings &other ) const
{
return !( *this == other );
}

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

~QgsTextMaskSettings();

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

/**
* Returns whether the mask is enabled.
*/
Expand Down
33 changes: 33 additions & 0 deletions tests/src/python/test_qgstextrenderer.py
Expand Up @@ -277,6 +277,39 @@ def createMaskSettings(self):
QgsSymbolLayerReference("layerid2", QgsSymbolLayerId("symbol2", 2))])
return s

def testMaskEquality(self):
s = self.createMaskSettings()
s2 = self.createMaskSettings()
self.assertEqual(s, s2)

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

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

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

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

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

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

s.setMaskedSymbolLayers([QgsSymbolLayerReference("layerid11", QgsSymbolLayerId("symbol", 1)),
QgsSymbolLayerReference("layerid21", QgsSymbolLayerId("symbol2", 2))])
self.assertNotEqual(s, s2)

def checkMaskSettings(self, s):
""" test QgsTextMaskSettings """
self.assertTrue(s.enabled())
Expand Down

0 comments on commit 52d7d18

Please sign in to comment.