Skip to content
Permalink
Browse files

Add tests for fixedAspectRatio in SVG marker

  • Loading branch information
rldhont committed Sep 28, 2017
1 parent 60cf7bd commit 48514d2e84fdf431996ef3494f279cab357addc2
@@ -180,7 +180,7 @@
"QgsRangeConfigDlg": ["QgsRangeConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent)", "rangeWidgetChanged(int index)"],
"QgsMapMouseEvent": ["SnappingMode"],
"QgsScaleExpression": ["Type", "operator bool() const "],
"QgsSvgMarkerSymbolLayer": ["strokeWidthMapUnitScale() const ", "path() const ", "setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)", "setStrokeWidth(double w)", "strokeWidthUnit() const ", "QgsSvgMarkerSymbolLayer(const QString &name=DEFAULT_SVGMARKER_NAME, double size=DEFAULT_SVGMARKER_SIZE, double angle=DEFAULT_SVGMARKER_ANGLE, QgsSymbol::ScaleMethod scaleMethod=DEFAULT_SCALE_METHOD)", "create(const QgsStringMap &properties=QgsStringMap())", "setStrokeWidthUnit(QgsSymbol::OutputUnit unit)", "setPath(const QString &path)", "createFromSld(QDomElement &element)", "strokeWidth() const ", "fixedAspectRatio() const ", "setFixedAspectRatio(double far)", "updateDefaultAspectRatio()", "defaultAspectRatio() const "],
"QgsSvgMarkerSymbolLayer": ["strokeWidthMapUnitScale() const ", "setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)", "setStrokeWidth(double w)", "strokeWidthUnit() const ", "QgsSvgMarkerSymbolLayer(const QString &name=DEFAULT_SVGMARKER_NAME, double size=DEFAULT_SVGMARKER_SIZE, double angle=DEFAULT_SVGMARKER_ANGLE, QgsSymbol::ScaleMethod scaleMethod=DEFAULT_SCALE_METHOD)", "create(const QgsStringMap &properties=QgsStringMap())", "setStrokeWidthUnit(QgsSymbol::OutputUnit unit)", "createFromSld(QDomElement &element)", "strokeWidth() const "],
"QgsDateTimeEditWrapper": ["QgsDateTimeEditWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent=nullptr)"],
"QgsMultiBandColorRendererWidget": ["QgsMultiBandColorRendererWidget(QgsRasterLayer *layer, const QgsRectangle &extent=QgsRectangle())", "create(QgsRasterLayer *layer, const QgsRectangle &extent)", "setFromRenderer(const QgsRasterRenderer *r)", "loadMinMax(int bandNo, double min, double max, int origin)"],
"QgsAnimatedIcon": ["setIconPath(const QString &iconPath)", "iconPath() const ", "icon() const ", "onFrameChanged()"],
@@ -55,6 +55,12 @@ class TestQgsSvgMarkerSymbol : public QObject

void svgMarkerSymbol();
void bounds();
void boundsWidth();
void bench();
void aspectRatio();
void dynamicSizeWithAspectRatio();
void dynamicWidthWithAspectRatio();
void dynamicAspectRatio();

private:
bool mTestHasError = false ;
@@ -151,6 +157,97 @@ void TestQgsSvgMarkerSymbol::bounds()
mMapSettings.setFlag( QgsMapSettings::DrawSymbolBounds, true );
bool result = imageCheck( QStringLiteral( "svgmarker_bounds" ) );
mMapSettings.setFlag( QgsMapSettings::DrawSymbolBounds, false );
mSvgMarkerLayer->setDataDefinedProperty( QgsSymbolLayer::PropertySize, QgsProperty() );
QVERIFY( result );
}

void TestQgsSvgMarkerSymbol::boundsWidth()
{
//use a tall, narrow symbol (non-square to test calculation of height)
mSvgMarkerLayer->setPath( mTestDataDir + "test_symbol_svg.svg" );
mSvgMarkerLayer->setStrokeColor( Qt::black );
mSvgMarkerLayer->setColor( Qt::blue );
mSvgMarkerLayer->setStrokeWidth( 0.5 );
mSvgMarkerLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyWidth, QgsProperty::fromExpression( QStringLiteral( "min(\"importance\" * 2, 6)" ) ) );

mMapSettings.setFlag( QgsMapSettings::DrawSymbolBounds, true );
bool result = imageCheck( QStringLiteral( "svgmarker_bounds" ) );
mMapSettings.setFlag( QgsMapSettings::DrawSymbolBounds, false );
mSvgMarkerLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyWidth, QgsProperty() );
QVERIFY( result );
}

void TestQgsSvgMarkerSymbol::bench()
{
QString svgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "/amenity/amenity_bench.svg" ), QgsPathResolver() );

mSvgMarkerLayer->setPath( svgPath );
mSvgMarkerLayer->setStrokeColor( Qt::black );
mSvgMarkerLayer->setColor( Qt::black );
mSvgMarkerLayer->setSize( 20 );
mSvgMarkerLayer->setStrokeWidth( 0.0 );
QVERIFY( imageCheck( "svgmarker_bench" ) );
}

void TestQgsSvgMarkerSymbol::aspectRatio()
{
QString svgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "/amenity/amenity_bench.svg" ), QgsPathResolver() );

mSvgMarkerLayer->setPath( svgPath );
mSvgMarkerLayer->setStrokeColor( Qt::black );
mSvgMarkerLayer->setColor( Qt::black );
mSvgMarkerLayer->setSize( 20 );
mSvgMarkerLayer->setFixedAspectRatio( 0.5 );
mSvgMarkerLayer->setStrokeWidth( 0.0 );
QVERIFY( imageCheck( "svgmarker_aspectratio" ) );
}

void TestQgsSvgMarkerSymbol::dynamicSizeWithAspectRatio()
{
QString svgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "/amenity/amenity_bench.svg" ), QgsPathResolver() );

mSvgMarkerLayer->setPath( svgPath );
mSvgMarkerLayer->setStrokeColor( Qt::black );
mSvgMarkerLayer->setColor( Qt::black );
mSvgMarkerLayer->setDataDefinedProperty( QgsSymbolLayer::PropertySize, QgsProperty::fromExpression( QStringLiteral( "max(\"importance\" * 5, 10)" ) ) );
mSvgMarkerLayer->setFixedAspectRatio( 0.5 );
mSvgMarkerLayer->setStrokeWidth( 0.0 );

bool result = imageCheck( QStringLiteral( "svgmarker_dynamicsize_aspectratio" ) );
mSvgMarkerLayer->setDataDefinedProperty( QgsSymbolLayer::PropertySize, QgsProperty() );
QVERIFY( result );
}

void TestQgsSvgMarkerSymbol::dynamicWidthWithAspectRatio()
{
QString svgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "/amenity/amenity_bench.svg" ), QgsPathResolver() );

mSvgMarkerLayer->setPath( svgPath );
mSvgMarkerLayer->setStrokeColor( Qt::black );
mSvgMarkerLayer->setColor( Qt::black );
mSvgMarkerLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyWidth, QgsProperty::fromExpression( QStringLiteral( "max(\"importance\" * 5, 10)" ) ) );
mSvgMarkerLayer->setFixedAspectRatio( 0.5 );
mSvgMarkerLayer->setStrokeWidth( 0.0 );

bool result = imageCheck( QStringLiteral( "svgmarker_dynamicwidth_aspectratio" ) );
mSvgMarkerLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyWidth, QgsProperty() );
QVERIFY( result );
}

void TestQgsSvgMarkerSymbol::dynamicAspectRatio()
{
QString svgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "/amenity/amenity_bench.svg" ), QgsPathResolver() );

mSvgMarkerLayer->setPath( svgPath );
mSvgMarkerLayer->setStrokeColor( Qt::black );
mSvgMarkerLayer->setColor( Qt::black );
mSvgMarkerLayer->setSize( 20 );
mSvgMarkerLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyHeight, QgsProperty::fromExpression( QStringLiteral( "max(\"importance\" * 5, 10)" ) ) );
mSvgMarkerLayer->setFixedAspectRatio( 0.5 );
mSvgMarkerLayer->setStrokeWidth( 0.0 );

bool result = imageCheck( QStringLiteral( "svgmarker_dynamic_aspectratio" ) );
mSvgMarkerLayer->setDataDefinedProperty( QgsSymbolLayer::PropertyHeight, QgsProperty() );
QVERIFY( result );
}

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 48514d2

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