Skip to content

Commit e6034e9

Browse files
committed
Fix vector field symbol does not use subsymbol color (fix #15130)
1 parent 302f8d4 commit e6034e9

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

python/core/symbology-ng/qgsvectorfieldsymbollayer.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class QgsVectorFieldSymbolLayer : QgsMarkerSymbolLayerV2
3434
bool setSubSymbol( QgsSymbolV2* symbol /Transfer/ );
3535
QgsSymbolV2* subSymbol();
3636

37+
void setColor( const QColor& color );
38+
virtual QColor color() const;
39+
3740
void renderPoint( QPointF point, QgsSymbolV2RenderContext& context );
3841
void startRender( QgsSymbolV2RenderContext& context );
3942
void stopRender( QgsSymbolV2RenderContext& context );

src/core/symbology-ng/qgsvectorfieldsymbollayer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,17 @@ void QgsVectorFieldSymbolLayer::convertPolarToCartesian( double length, double a
319319
y = length * cos( angle );
320320
}
321321

322+
void QgsVectorFieldSymbolLayer::setColor( const QColor& color )
323+
{
324+
if ( mLineSymbol )
325+
mLineSymbol->setColor( color );
326+
327+
mColor = color;
328+
}
329+
330+
QColor QgsVectorFieldSymbolLayer::color() const
331+
{
332+
return mLineSymbol ? mLineSymbol->color() : mColor;
333+
}
334+
322335

src/core/symbology-ng/qgsvectorfieldsymbollayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class CORE_EXPORT QgsVectorFieldSymbolLayer: public QgsMarkerSymbolLayerV2
5454
bool setSubSymbol( QgsSymbolV2* symbol ) override;
5555
QgsSymbolV2* subSymbol() override { return mLineSymbol; }
5656

57+
void setColor( const QColor& color ) override;
58+
virtual QColor color() const override;
59+
5760
void renderPoint( QPointF point, QgsSymbolV2RenderContext& context ) override;
5861
void startRender( QgsSymbolV2RenderContext& context ) override;
5962
void stopRender( QgsSymbolV2RenderContext& context ) override;

tests/src/python/test_qgssymbollayerv2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,5 +804,19 @@ def testQgsFilledMarkerSymbolLayer(self):
804804
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(250, 150, 200))
805805
self.assertEqual(mSymbolLayer.color(), QColor(250, 150, 200))
806806

807+
def testQgsVectorFieldSymbolLayer(self):
808+
"""
809+
Test QgsVectorFieldSymbolLayer
810+
"""
811+
# test colors, need to make sure colors are passed/retrieved from subsymbol
812+
mSymbolLayer = QgsVectorFieldSymbolLayer.create()
813+
814+
mSymbolLayer.setColor(QColor(150, 50, 100))
815+
self.assertEqual(mSymbolLayer.color(), QColor(150, 50, 100))
816+
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(150, 50, 100))
817+
mSymbolLayer.subSymbol().setColor(QColor(250, 150, 200))
818+
self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(250, 150, 200))
819+
self.assertEqual(mSymbolLayer.color(), QColor(250, 150, 200))
820+
807821
if __name__ == '__main__':
808822
unittest.main()

0 commit comments

Comments
 (0)