Make outline only simple markers work with categorised/graduated

etc renderers (fix #15132)
This commit is contained in:
Nyall Dawson 2016-06-27 09:45:33 +10:00
parent 972fc9fa11
commit 9f0ae9b408
5 changed files with 55 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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() );

View File

@ -66,6 +66,7 @@ class TestQgsSimpleMarkerSymbol : public QObject
void boundsWithOffset();
void boundsWithRotation();
void boundsWithRotationAndOffset();
void colors();
private:
bool mTestHasError;
@ -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
//