Skip to content
Permalink
Browse files

Ensure that @symbol_color is always correct for symbol layer types

with subsymbols
  • Loading branch information
nyalldawson committed May 7, 2016
1 parent d823be1 commit cda387cb6f96e01d0c677c974f1a18e5d0bcbce9
@@ -14,7 +14,7 @@ class QgsArrowSymbolLayer : public QgsLineSymbolLayerV2
*
* @return A new QgsArrowSymbolLayer
*/
static QgsSymbolLayerV2* create( const QgsStringMap& properties ) /Factory/;
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;

/** Virtual constructor */
virtual QgsArrowSymbolLayer* clone() const /Factory/;
@@ -108,6 +108,7 @@ class QgsArrowSymbolLayer : public QgsLineSymbolLayerV2
void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );

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

private:
QgsArrowSymbolLayer( const QgsArrowSymbolLayer& );
@@ -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/);
@@ -613,3 +613,8 @@ void QgsArrowSymbolLayer::setColor( const QColor& c )
mColor = c;
}

QColor QgsArrowSymbolLayer::color() const
{
return mSymbol.data() ? mSymbol->color() : mColor;
}

@@ -34,7 +34,7 @@ class CORE_EXPORT QgsArrowSymbolLayer : public QgsLineSymbolLayerV2
*
* @return A new QgsArrowSymbolLayer
*/
static QgsSymbolLayerV2* create( const QgsStringMap& properties );
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );

/** Virtual constructor */
virtual QgsArrowSymbolLayer* clone() const override;
@@ -128,6 +128,7 @@ class CORE_EXPORT QgsArrowSymbolLayer : public QgsLineSymbolLayerV2
void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) override;

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

private:
/** Filling sub symbol */
@@ -2331,6 +2331,11 @@ void QgsLinePatternFillSymbolLayer::setColor( const QColor& c )
mColor = c;
}

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

QgsLinePatternFillSymbolLayer::~QgsLinePatternFillSymbolLayer()
{
delete mFillLineSymbol;
@@ -3392,6 +3397,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;
}

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


@@ -3433,6 +3450,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() );
@@ -899,7 +899,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; }

@@ -1029,6 +1029,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;
@@ -1080,6 +1082,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;
@@ -813,6 +813,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;
@@ -110,5 +110,18 @@ def test_2(self):
renderchecker.setControlName('expected_arrowsymbollayer_2')
self.assertTrue(renderchecker.runTest('arrowsymbollayer_2'))

def testColors(self):
"""
Test colors, need to make sure colors are passed/retrieved from subsymbol
"""
sym_layer = QgsArrowSymbolLayer.create()
sym_layer.setColor(QColor(150, 50, 100))
self.assertEqual(sym_layer.color(), QColor(150, 50, 100))
self.assertEqual(sym_layer.subSymbol().color(), QColor(150, 50, 100))
sym_layer.subSymbol().setColor(QColor(250, 150, 200))
self.assertEqual(sym_layer.subSymbol().color(), QColor(250, 150, 200))
self.assertEqual(sym_layer.color(), QColor(250, 150, 200))


if __name__ == '__main__':
unittest.main()
@@ -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 cda387c

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