Skip to content
Permalink
Browse files

Ensure that @symbol_color is always correct for symbol layer types

with subsymbols

(cherry-picked from cda387c)
  • Loading branch information
nyalldawson committed May 16, 2016
1 parent 7a4ef0d commit 82a4b4d54ade27fcb2c4b66cabfbe20e86a11a50
@@ -843,6 +843,9 @@ class QgsPointPatternFillSymbolLayer : QgsImageFillSymbolLayer

virtual QSet<QString> usedAttributes() const;

void setColor( const QColor& c );
virtual QColor color() const;

protected:
void applyDataDefinedSettings( QgsSymbolV2RenderContext& context );
};
@@ -879,6 +882,7 @@ class QgsCentroidFillSymbolLayerV2 : QgsFillSymbolLayerV2
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

void setColor( const QColor& color );
QColor color() const;

QgsSymbolV2* subSymbol();
bool setSubSymbol( QgsSymbolV2* symbol /Transfer/ );
@@ -145,6 +145,7 @@ class QgsMarkerLineSymbolLayerV2 : QgsLineSymbolLayerV2
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

void setColor( const QColor& color );
virtual QColor color() const;

QgsSymbolV2* subSymbol();
bool setSubSymbol( QgsSymbolV2* symbol /Transfer/);
@@ -2317,6 +2317,11 @@ void QgsLinePatternFillSymbolLayer::setColor( const QColor& c )
mColor = c;
}

QColor QgsLinePatternFillSymbolLayer::color() const
{
return mFillLineSymbol ? mFillLineSymbol->color() : mColor;
}

QgsLinePatternFillSymbolLayer::~QgsLinePatternFillSymbolLayer()
{
delete mFillLineSymbol;
@@ -3370,6 +3375,18 @@ QSet<QString> QgsPointPatternFillSymbolLayer::usedAttributes() const
return attributes;
}

void QgsPointPatternFillSymbolLayer::setColor( const QColor& c )
{
mColor = c;
if ( mMarkerSymbol )
mMarkerSymbol->setColor( c );
}

QColor QgsPointPatternFillSymbolLayer::color() const
{
return mMarkerSymbol ? mMarkerSymbol->color() : mColor;
}

//////////////


@@ -3404,6 +3421,11 @@ void QgsCentroidFillSymbolLayerV2::setColor( const QColor& color )
mColor = color;
}

QColor QgsCentroidFillSymbolLayerV2::color() const
{
return mMarker ? mMarker->color() : mColor;
}

void QgsCentroidFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
{
mMarker->setAlpha( context.alpha() );
@@ -896,7 +896,7 @@ class CORE_EXPORT QgsLinePatternFillSymbolLayer: public QgsImageFillSymbolLayer
void setLineWidth( double w );
double lineWidth() const { return mLineWidth; }
void setColor( const QColor& c ) override;
QColor color() const override { return mColor; }
QColor color() const override;
void setOffset( double offset ) { mOffset = offset; }
double offset() const { return mOffset; }

@@ -1026,6 +1026,8 @@ class CORE_EXPORT QgsPointPatternFillSymbolLayer: public QgsImageFillSymbolLayer
QgsMapUnitScale mapUnitScale() const override;

virtual QSet<QString> usedAttributes() const override;
void setColor( const QColor& c ) override;
virtual QColor color() const override;

protected:
QgsMarkerSymbolV2* mMarkerSymbol;
@@ -1077,6 +1079,7 @@ class CORE_EXPORT QgsCentroidFillSymbolLayerV2 : public QgsFillSymbolLayerV2
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;

void setColor( const QColor& color ) override;
QColor color() const override;

QgsSymbolV2* subSymbol() override;
bool setSubSymbol( QgsSymbolV2* symbol ) override;
@@ -809,6 +809,11 @@ void QgsMarkerLineSymbolLayerV2::setColor( const QColor& color )
mColor = color;
}

QColor QgsMarkerLineSymbolLayerV2::color() const
{
return mMarker ? mMarker->color() : mColor;
}

void QgsMarkerLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
{
mMarker->setAlpha( context.alpha() );
@@ -194,6 +194,7 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const override;

void setColor( const QColor& color ) override;
virtual QColor color() const override;

QgsSymbolV2* subSymbol() override;
bool setSubSymbol( QgsSymbolV2* symbol ) override;
@@ -364,6 +364,14 @@ def testQgsCentroidFillSymbolLayerV2(self):
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage

# test colors, need to make sure colors are passed/retrieved from subsymbol
mSymbolLayer.setColor(QColor(150, 50, 100))
self.assertEqual(mSymbolLayer.color(), QColor(150, 50, 100))
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(150, 50, 100))
mSymbolLayer.subSymbol().setColor(QColor(250, 150, 200))
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(250, 150, 200))
self.assertEqual(mSymbolLayer.color(), QColor(250, 150, 200))

def testQgsLinePatternFillSymbolLayer(self):
"""
Create a new style from a .sld file and match test
@@ -404,8 +412,16 @@ def testQgsLinePatternFillSymbolLayer(self):
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage

# test colors, need to make sure colors are passed/retrieved from subsymbol
mSymbolLayer.setColor(QColor(150, 50, 100))
self.assertEqual(mSymbolLayer.color(), QColor(150, 50, 100))
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(150, 50, 100))
mSymbolLayer.subSymbol().setColor(QColor(250, 150, 200))
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(250, 150, 200))
self.assertEqual(mSymbolLayer.color(), QColor(250, 150, 200))

@unittest.expectedFailure
def testQgsPointPatternFillSymbolLayer(self):
def testQgsPointPatternFillSymbolLayerSld(self):
"""
Create a new style from a .sld file and match test
"""
@@ -452,6 +468,20 @@ def testQgsPointPatternFillSymbolLayer(self):
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage

def testQgsPointPatternFillSymbolLayer(self):
"""
Test point pattern fill
"""
# test colors, need to make sure colors are passed/retrieved from subsymbol
mSymbolLayer = QgsPointPatternFillSymbolLayer.create()

mSymbolLayer.setColor(QColor(150, 50, 100))
self.assertEqual(mSymbolLayer.color(), QColor(150, 50, 100))
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(150, 50, 100))
mSymbolLayer.subSymbol().setColor(QColor(250, 150, 200))
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(250, 150, 200))
self.assertEqual(mSymbolLayer.color(), QColor(250, 150, 200))

def testQgsSVGFillSymbolLayer(self):
"""
Create a new style from a .sld file and match test
@@ -522,6 +552,14 @@ def testQgsMarkerLineSymbolLayerV2(self):
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage

# test colors, need to make sure colors are passed/retrieved from subsymbol
mSymbolLayer.setColor(QColor(150, 50, 100))
self.assertEqual(mSymbolLayer.color(), QColor(150, 50, 100))
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(150, 50, 100))
mSymbolLayer.subSymbol().setColor(QColor(250, 150, 200))
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(250, 150, 200))
self.assertEqual(mSymbolLayer.color(), QColor(250, 150, 200))

def testQgsSimpleLineSymbolLayerV2(self):
"""
Create a new style from a .sld file and match test
@@ -692,6 +730,5 @@ def testQgsSvgMarkerSymbolLayerV2(self):
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage


if __name__ == '__main__':
unittest.main()

0 comments on commit 82a4b4d

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