Skip to content

Commit

Permalink
[symbology] Fix setSize(size) not working for ellipse markers
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 8, 2019
1 parent 18559de commit fd6a2f7
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/symbology/qgssymbollayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,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.

Expand Down
51 changes: 39 additions & 12 deletions src/core/symbology/qgsellipsesymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down Expand Up @@ -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" )] ) );
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 4 additions & 2 deletions src/core/symbology/qgsellipsesymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology/qgssymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,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().
Expand Down
16 changes: 16 additions & 0 deletions tests/src/core/testqgsellipsemarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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" );
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fd6a2f7

Please sign in to comment.