Skip to content

Commit

Permalink
Add tests for fixedAspectRatio in SVG marker
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Sep 28, 2017
1 parent 60cf7bd commit 48514d2
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/code_layout/acceptable_missing_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()"],
Expand Down
97 changes: 97 additions & 0 deletions tests/src/core/testqgssvgmarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down Expand Up @@ -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 );
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 48514d2

Please sign in to comment.