Skip to content

Commit

Permalink
Fix SVG marker symbol layer aspect ratio is not recalculated when the
Browse files Browse the repository at this point in the history
marker is pointed to a different source svg
  • Loading branch information
nyalldawson committed Aug 19, 2020
1 parent 2f2fb0b commit 2412a8d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/symbology/qgsmarkersymbollayer.cpp
Expand Up @@ -1906,6 +1906,7 @@ void QgsSvgMarkerSymbolLayer::resolvePaths( QgsStringMap &properties, const QgsP

void QgsSvgMarkerSymbolLayer::setPath( const QString &path )
{
mDefaultAspectRatio = 0;
mPath = path;
QColor defaultFillColor, defaultStrokeColor;
double strokeWidth, fillOpacity, strokeOpacity;
Expand Down
28 changes: 28 additions & 0 deletions tests/src/core/testqgssvgmarker.cpp
Expand Up @@ -62,6 +62,7 @@ class TestQgsSvgMarkerSymbol : public QObject
void dynamicSizeWithAspectRatio();
void dynamicWidthWithAspectRatio();
void dynamicAspectRatio();
void resetDefaultAspectRatio();

private:
bool mTestHasError = false ;
Expand Down Expand Up @@ -252,6 +253,33 @@ void TestQgsSvgMarkerSymbol::dynamicAspectRatio()
QVERIFY( result );
}

void TestQgsSvgMarkerSymbol::resetDefaultAspectRatio()
{
// default aspect ratio must be updated as SVG path is changed
QString svgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "/amenity/amenity_bench.svg" ), QgsPathResolver() );
QgsSvgMarkerSymbolLayer layer( svgPath );
QCOMPARE( layer.defaultAspectRatio(), 1.0 );
QVERIFY( layer.preservedAspectRatio() );

// different aspect ratio
layer.setPath( mTestDataDir + "test_symbol_svg.svg" );
QGSCOMPARENEAR( layer.defaultAspectRatio(), 1.58258242005, 0.0001 );
QVERIFY( layer.preservedAspectRatio() );
layer.setPath( svgPath );
QCOMPARE( layer.defaultAspectRatio(), 1.0 );
QVERIFY( layer.preservedAspectRatio() );

layer.setFixedAspectRatio( 0.5 );
QCOMPARE( layer.defaultAspectRatio(), 1.0 );
QCOMPARE( layer.fixedAspectRatio(), 0.5 );
QVERIFY( !layer.preservedAspectRatio() );

layer.setPath( mTestDataDir + "test_symbol_svg.svg" );
QGSCOMPARENEAR( layer.defaultAspectRatio(), 1.58258242005, 0.0001 );
QCOMPARE( layer.fixedAspectRatio(), 0.5 );
QVERIFY( !layer.preservedAspectRatio() );
}

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

0 comments on commit 2412a8d

Please sign in to comment.