Skip to content
Permalink
Browse files

Fix SVG marker symbol layer aspect ratio is not recalculated when the

marker is pointed to a different source svg
  • Loading branch information
nyalldawson committed Aug 19, 2020
1 parent 2f2fb0b commit 2412a8d6c61f7e128365156bc775387bac2bcfa1
Showing with 29 additions and 0 deletions.
  1. +1 −0 src/core/symbology/qgsmarkersymbollayer.cpp
  2. +28 −0 tests/src/core/testqgssvgmarker.cpp
@@ -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;
@@ -62,6 +62,7 @@ class TestQgsSvgMarkerSymbol : public QObject
void dynamicSizeWithAspectRatio();
void dynamicWidthWithAspectRatio();
void dynamicAspectRatio();
void resetDefaultAspectRatio();

private:
bool mTestHasError = false ;
@@ -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
//

0 comments on commit 2412a8d

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