Skip to content
Permalink
Browse files

[symbology] Fix setSize(size) not working for ellipse markers

  • Loading branch information
nirvn committed May 8, 2019
1 parent b5b0611 commit 9bad593a8243ae9745e97613263ab8a42a7134bd
@@ -48,6 +48,9 @@ A symbol layer for rendering objects with major and minor axis (e.g. ellipse, re
void setSymbolName( const QString &name );
QString symbolName() const;

virtual void setSize( double size );


void setSymbolWidth( double w );
double symbolWidth() const;

@@ -519,7 +519,7 @@ is usually used for orienting symbols to match a line's angle.
.. versionadded:: 2.9
%End

void setSize( double size );
virtual void setSize( double size );
%Docstring
Sets the symbol size.

@@ -50,6 +50,18 @@ QgsSymbolLayer *QgsEllipseSymbolLayer::create( const QgsStringMap &properties )
{
layer->setSymbolName( properties[ QStringLiteral( "symbol_name" )] );
}
if ( properties.contains( QStringLiteral( "size" ) ) )
{
layer->setSize( properties[QStringLiteral( "size" )].toDouble() );
}
if ( properties.contains( QStringLiteral( "size_unit" ) ) )
{
layer->setSizeUnit( QgsUnitTypes::decodeRenderUnit( properties[QStringLiteral( "size_unit" )] ) );
}
if ( properties.contains( QStringLiteral( "size_map_unit_scale" ) ) )
{
layer->setSizeMapUnitScale( QgsSymbolLayerUtils::decodeMapUnitScale( properties[QStringLiteral( "size_map_unit_scale" )] ) );
}
if ( properties.contains( QStringLiteral( "symbol_width" ) ) )
{
layer->setSymbolWidth( properties[QStringLiteral( "symbol_width" )].toDouble() );
@@ -127,18 +139,6 @@ QgsSymbolLayer *QgsEllipseSymbolLayer::create( const QgsStringMap &properties )
{
layer->setStrokeColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "line_color" )] ) );
}
if ( properties.contains( QStringLiteral( "size" ) ) )
{
layer->setSize( properties[QStringLiteral( "size" )].toDouble() );
}
if ( properties.contains( QStringLiteral( "size_unit" ) ) )
{
layer->setSizeUnit( QgsUnitTypes::decodeRenderUnit( properties[QStringLiteral( "size_unit" )] ) );
}
if ( properties.contains( QStringLiteral( "size_map_unit_scale" ) ) )
{
layer->setSizeMapUnitScale( QgsSymbolLayerUtils::decodeMapUnitScale( properties[QStringLiteral( "size_map_unit_scale" )] ) );
}
if ( properties.contains( QStringLiteral( "offset" ) ) )
{
layer->setOffset( QgsSymbolLayerUtils::decodePoint( properties[QStringLiteral( "offset" )] ) );
@@ -593,6 +593,33 @@ void QgsEllipseSymbolLayer::preparePath( const QString &symbolName, QgsSymbolRen
}
}

void QgsEllipseSymbolLayer::setSize( double size )
{
if ( mSymbolWidth >= mSymbolHeight )
{
mSymbolHeight = mSymbolHeight * size / mSymbolWidth;
mSymbolWidth = size;
}
else
{
mSymbolWidth = mSymbolWidth * size / mSymbolHeight;
mSymbolHeight = size;
}
QgsMarkerSymbolLayer::setSize( size );
}

void QgsEllipseSymbolLayer::setSymbolWidth( double w )
{
mSymbolWidth = w;
QgsMarkerSymbolLayer::setSize( mSymbolWidth >= mSymbolHeight ? mSymbolWidth : mSymbolHeight );
}

void QgsEllipseSymbolLayer::setSymbolHeight( double h )
{
mSymbolHeight = h;
QgsMarkerSymbolLayer::setSize( mSymbolWidth >= mSymbolHeight ? mSymbolWidth : mSymbolHeight );
}

void QgsEllipseSymbolLayer::setOutputUnit( QgsUnitTypes::RenderUnit unit )
{
QgsMarkerSymbolLayer::setOutputUnit( unit );
@@ -50,10 +50,12 @@ class CORE_EXPORT QgsEllipseSymbolLayer: public QgsMarkerSymbolLayer
void setSymbolName( const QString &name ) { mSymbolName = name; }
QString symbolName() const { return mSymbolName; }

void setSymbolWidth( double w ) { mSymbolWidth = w; }
void setSize( double size ) override;

void setSymbolWidth( double w );
double symbolWidth() const { return mSymbolWidth; }

void setSymbolHeight( double h ) { mSymbolHeight = h; }
void setSymbolHeight( double h );
double symbolHeight() const { return mSymbolHeight; }

Qt::PenStyle strokeStyle() const { return mStrokeStyle; }
@@ -527,7 +527,7 @@ class CORE_EXPORT QgsMarkerSymbolLayer : public QgsSymbolLayer
* \see setSizeUnit()
* \see setSizeMapUnitScale()
*/
void setSize( double size ) { mSize = size; }
virtual void setSize( double size ) { mSize = size; }

/**
* Returns the symbol size. Units are specified by sizeUnit().
@@ -54,6 +54,7 @@ class TestQgsEllipseMarkerSymbol : public QObject
void cleanup() {} // will be called after every testfunction.

void ellipseMarkerSymbol();
void ellipseMarkerSymbolSize();
void ellipseMarkerSymbolBevelJoin();
void ellipseMarkerSymbolMiterJoin();
void ellipseMarkerSymbolRoundJoin();
@@ -137,6 +138,21 @@ void TestQgsEllipseMarkerSymbol::ellipseMarkerSymbol()
QVERIFY( imageCheck( "ellipsemarker" ) );
}

void TestQgsEllipseMarkerSymbol::ellipseMarkerSymbolSize()
{
mReport += QLatin1String( "<h2>Ellipse marker symbol layer setSize / size test</h2>\n" );

mEllipseMarkerLayer->setSymbolHeight( 3 );
mEllipseMarkerLayer->setSymbolWidth( 6 );
// Verify size value derived from width/height (largest value)
QCOMPARE( mEllipseMarkerLayer->size(), 6.0 );

mEllipseMarkerLayer->setSize( 2 );
// Verify width / height values adjusted from setSize
QCOMPARE( mEllipseMarkerLayer->symbolHeight(), 1.0 );
QCOMPARE( mEllipseMarkerLayer->symbolWidth(), 2.0 );
}

void TestQgsEllipseMarkerSymbol::ellipseMarkerSymbolBevelJoin()
{
mReport += QLatin1String( "<h2>Ellipse marker symbol layer test</h2>\n" );
Binary file not shown.

0 comments on commit 9bad593

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