Skip to content

Commit 9f0ae9b

Browse files
committed
Make outline only simple markers work with categorised/graduated
etc renderers (fix #15132)
1 parent 972fc9f commit 9f0ae9b

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

python/core/symbology-ng/qgsmarkersymbollayerv2.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ class QgsSimpleMarkerSymbolLayerV2 : QgsSimpleMarkerSymbolLayerBase
220220
void setOutlineColor( const QColor& color );
221221
QColor fillColor() const;
222222
void setFillColor( const QColor& color );
223+
void setColor( const QColor& color );
224+
virtual QColor color() const;
223225

224226
// new methods
225227

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,32 @@ QRectF QgsSimpleMarkerSymbolLayerV2::bounds( QPointF point, QgsSymbolV2RenderCon
15161516
return symbolBounds;
15171517
}
15181518

1519+
void QgsSimpleMarkerSymbolLayerV2::setColor( const QColor& color )
1520+
{
1521+
if ( shapeIsFilled( mShape ) )
1522+
{
1523+
setFillColor( color );
1524+
}
1525+
else
1526+
{
1527+
setOutlineColor( color );
1528+
}
1529+
}
1530+
1531+
QColor QgsSimpleMarkerSymbolLayerV2::color() const
1532+
{
1533+
if ( shapeIsFilled( mShape ) )
1534+
{
1535+
return fillColor();
1536+
}
1537+
else
1538+
{
1539+
return outlineColor();
1540+
}
1541+
}
1542+
1543+
1544+
15191545

15201546
//
15211547
// QgsFilledMarkerSymbolLayer

src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsSimpleMarkerSymbolLay
257257
QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
258258
QColor outlineColor() const override { return borderColor(); }
259259
void setOutlineColor( const QColor& color ) override { setBorderColor( color ); }
260-
QColor fillColor() const override { return color(); }
261-
void setFillColor( const QColor& color ) override { setColor( color ); }
260+
QColor fillColor() const override { return mColor; }
261+
void setFillColor( const QColor& color ) override { mColor = color; }
262+
void setColor( const QColor& color ) override;
263+
virtual QColor color() const override;
262264

263265
// new methods
264266

src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer
493493
btnChangeColorBorder->setColor( mLayer->borderColor() );
494494
btnChangeColorBorder->blockSignals( false );
495495
btnChangeColorFill->blockSignals( true );
496-
btnChangeColorFill->setColor( mLayer->color() );
496+
btnChangeColorFill->setColor( mLayer->fillColor() );
497497
btnChangeColorFill->blockSignals( false );
498498
spinSize->blockSignals( true );
499499
spinSize->setValue( mLayer->size() );

tests/src/core/testqgssimplemarker.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class TestQgsSimpleMarkerSymbol : public QObject
6666
void boundsWithOffset();
6767
void boundsWithRotation();
6868
void boundsWithRotationAndOffset();
69+
void colors();
6970

7071
private:
7172
bool mTestHasError;
@@ -251,6 +252,27 @@ void TestQgsSimpleMarkerSymbol::boundsWithRotationAndOffset()
251252
QVERIFY( result );
252253
}
253254

255+
void TestQgsSimpleMarkerSymbol::colors()
256+
{
257+
//test logic for setting/retrieving symbol color
258+
259+
QgsSimpleMarkerSymbolLayerV2 marker;
260+
marker.setOutlineColor( QColor( 200, 200, 200 ) );
261+
marker.setFillColor( QColor( 100, 100, 100 ) );
262+
263+
//start with a filled shape - color should be fill color
264+
marker.setShape( QgsSimpleMarkerSymbolLayerBase::Circle );
265+
QCOMPARE( marker.color(), QColor( 100, 100, 100 ) );
266+
marker.setColor( QColor( 150, 150, 150 ) );
267+
QCOMPARE( marker.fillColor(), QColor( 150, 150, 150 ) );
268+
269+
//now try with a non-filled (outline only) shape - color should be outline color
270+
marker.setShape( QgsSimpleMarkerSymbolLayerBase::Cross );
271+
QCOMPARE( marker.color(), QColor( 200, 200, 200 ) );
272+
marker.setColor( QColor( 250, 250, 250 ) );
273+
QCOMPARE( marker.outlineColor(), QColor( 250, 250, 250 ) );
274+
}
275+
254276
//
255277
// Private helper functions not called directly by CTest
256278
//

0 commit comments

Comments
 (0)