Skip to content

Commit

Permalink
Make outline only simple markers work with categorised/graduated
Browse files Browse the repository at this point in the history
etc renderers (fix #15132)
  • Loading branch information
nyalldawson committed Jun 27, 2016
1 parent 972fc9f commit 9f0ae9b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgsmarkersymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ class QgsSimpleMarkerSymbolLayerV2 : QgsSimpleMarkerSymbolLayerBase
void setOutlineColor( const QColor& color );
QColor fillColor() const;
void setFillColor( const QColor& color );
void setColor( const QColor& color );
virtual QColor color() const;

// new methods

Expand Down
26 changes: 26 additions & 0 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,32 @@ QRectF QgsSimpleMarkerSymbolLayerV2::bounds( QPointF point, QgsSymbolV2RenderCon
return symbolBounds;
}

void QgsSimpleMarkerSymbolLayerV2::setColor( const QColor& color )
{
if ( shapeIsFilled( mShape ) )
{
setFillColor( color );
}
else
{
setOutlineColor( color );
}
}

QColor QgsSimpleMarkerSymbolLayerV2::color() const
{
if ( shapeIsFilled( mShape ) )
{
return fillColor();
}
else
{
return outlineColor();
}
}




//
// QgsFilledMarkerSymbolLayer
Expand Down
6 changes: 4 additions & 2 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsSimpleMarkerSymbolLay
QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
QColor outlineColor() const override { return borderColor(); }
void setOutlineColor( const QColor& color ) override { setBorderColor( color ); }
QColor fillColor() const override { return color(); }
void setFillColor( const QColor& color ) override { setColor( color ); }
QColor fillColor() const override { return mColor; }
void setFillColor( const QColor& color ) override { mColor = color; }
void setColor( const QColor& color ) override;
virtual QColor color() const override;

// new methods

Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer
btnChangeColorBorder->setColor( mLayer->borderColor() );
btnChangeColorBorder->blockSignals( false );
btnChangeColorFill->blockSignals( true );
btnChangeColorFill->setColor( mLayer->color() );
btnChangeColorFill->setColor( mLayer->fillColor() );
btnChangeColorFill->blockSignals( false );
spinSize->blockSignals( true );
spinSize->setValue( mLayer->size() );
Expand Down
22 changes: 22 additions & 0 deletions tests/src/core/testqgssimplemarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TestQgsSimpleMarkerSymbol : public QObject
void boundsWithOffset();
void boundsWithRotation();
void boundsWithRotationAndOffset();
void colors();

private:
bool mTestHasError;
Expand Down Expand Up @@ -251,6 +252,27 @@ void TestQgsSimpleMarkerSymbol::boundsWithRotationAndOffset()
QVERIFY( result );
}

void TestQgsSimpleMarkerSymbol::colors()
{
//test logic for setting/retrieving symbol color

QgsSimpleMarkerSymbolLayerV2 marker;
marker.setOutlineColor( QColor( 200, 200, 200 ) );
marker.setFillColor( QColor( 100, 100, 100 ) );

//start with a filled shape - color should be fill color
marker.setShape( QgsSimpleMarkerSymbolLayerBase::Circle );
QCOMPARE( marker.color(), QColor( 100, 100, 100 ) );
marker.setColor( QColor( 150, 150, 150 ) );
QCOMPARE( marker.fillColor(), QColor( 150, 150, 150 ) );

//now try with a non-filled (outline only) shape - color should be outline color
marker.setShape( QgsSimpleMarkerSymbolLayerBase::Cross );
QCOMPARE( marker.color(), QColor( 200, 200, 200 ) );
marker.setColor( QColor( 250, 250, 250 ) );
QCOMPARE( marker.outlineColor(), QColor( 250, 250, 250 ) );
}

//
// Private helper functions not called directly by CTest
//
Expand Down

0 comments on commit 9f0ae9b

Please sign in to comment.