diff --git a/src/core/symbology-ng/qgssymbollayerv2utils.cpp b/src/core/symbology-ng/qgssymbollayerv2utils.cpp index 93d985c0de5c..c64cd81008d1 100644 --- a/src/core/symbology-ng/qgssymbollayerv2utils.cpp +++ b/src/core/symbology-ng/qgssymbollayerv2utils.cpp @@ -750,7 +750,11 @@ QList offsetLine( QPolygonF polyline, double dist, QGis::GeometryType if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBLineString ) { - resultLine.append( makeOffsetGeometry( tempGeometry->asPolyline() ) ); + QgsPolyline line = tempGeometry->asPolyline(); + // Reverse the line if offset was negative, see + // http://hub.qgis.org/issues/13811 + if ( dist < 0 ) std::reverse(line.begin(), line.end() ); + resultLine.append( makeOffsetGeometry( line ) ); delete tempGeometry; return resultLine; } diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt index ac7f4b364ecd..bbffec3e0a76 100644 --- a/tests/src/core/CMakeLists.txt +++ b/tests/src/core/CMakeLists.txt @@ -142,6 +142,7 @@ ADD_QGIS_TEST(colorscheme testqgscolorscheme.cpp) ADD_QGIS_TEST(maptopixeltest testqgsmaptopixel.cpp) ADD_QGIS_TEST(maprotationtest testqgsmaprotation.cpp) ADD_QGIS_TEST(mapsettingstest testqgsmapsettings.cpp) +ADD_QGIS_TEST(markerlinessymboltest testqgsmarkerlinesymbol.cpp) ADD_QGIS_TEST(networkcontentfetcher testqgsnetworkcontentfetcher.cpp ) ADD_QGIS_TEST(legendrenderertest testqgslegendrenderer.cpp ) ADD_QGIS_TEST(vectorlayerjoinbuffer testqgsvectorlayerjoinbuffer.cpp ) diff --git a/tests/src/core/testqgsmarkerlinesymbol.cpp b/tests/src/core/testqgsmarkerlinesymbol.cpp new file mode 100644 index 000000000000..fdec55ee1adf --- /dev/null +++ b/tests/src/core/testqgsmarkerlinesymbol.cpp @@ -0,0 +1,154 @@ +/*************************************************************************** + testqgsmarkerlinesymbol.cpp + -------------------------------------- + Date : Nov 12 2015 + Copyright : (C) 2015 by Sandro Santilli + Email : strk@keybit.net + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +//qgis includes... +#include "qgsrasterlayer.h" +#include "qgsvectorlayer.h" +#include "qgsmultibandcolorrenderer.h" +#include "qgsmaplayerregistry.h" +#include "qgsapplication.h" +#include "qgsmaprenderer.h" +#include "qgspallabeling.h" +#include "qgsfontutils.h" + +//qgis unit test includes +#include + +/** \ingroup UnitTests + * This is a unit test for the Marker Line symbol + */ +class TestQgsMarkerLineSymbol : public QObject +{ + Q_OBJECT + public: + TestQgsMarkerLineSymbol() + : mLinesLayer( 0 ) + , mMapSettings( 0 ) + { + mTestDataDir = QString( TEST_DATA_DIR ) + '/'; + } + + ~TestQgsMarkerLineSymbol(); + + private slots: + void initTestCase();// will be called before the first testfunction is executed. + void cleanupTestCase();// will be called after the last testfunction was executed. + void init() {} // will be called before each testfunction is executed. + void cleanup() {} // will be called after every testfunction. + + void lineOffset(); + + private: + bool render( const QString& theFileName ); + + QString mTestDataDir; + QgsVectorLayer* mLinesLayer; + QgsMapSettings *mMapSettings; + QString mReport; +}; + +//runs before all tests +void TestQgsMarkerLineSymbol::initTestCase() +{ + // init QGIS's paths - true means that all path will be inited from prefix + QgsApplication::init(); + QgsApplication::initQgis(); + + mMapSettings = new QgsMapSettings(); + + QList mapLayers; + + //create a line layer that will be used in all tests... + QString myLinesFileName = mTestDataDir + "lines_cardinals.shp"; + QFileInfo myLinesFileInfo( myLinesFileName ); + mLinesLayer = new QgsVectorLayer( myLinesFileInfo.filePath(), + myLinesFileInfo.completeBaseName(), "ogr" ); + mapLayers << mLinesLayer; + + // Register all layers with the registry + QgsMapLayerRegistry::instance()->addMapLayers( mapLayers ); + + // This is needed to correctly set rotation center, + // the actual size doesn't matter as QgsRenderChecker will + // re-set it to the size of the expected image + mMapSettings->setOutputSize( QSize( 256, 256 ) ); + + mReport += "

Line Marker Symbol Tests

\n"; + + QgsFontUtils::loadStandardTestFonts( QStringList() << "Bold" ); +} + +TestQgsMarkerLineSymbol::~TestQgsMarkerLineSymbol() +{ + +} + +//runs after all tests +void TestQgsMarkerLineSymbol::cleanupTestCase() +{ + delete mMapSettings; + QgsApplication::exitQgis(); + + QString myReportFile = QDir::tempPath() + "/qgistest.html"; + QFile myFile( myReportFile ); + if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) ) + { + QTextStream myQTextStream( &myFile ); + myQTextStream << mReport; + myFile.close(); + } +} + +void TestQgsMarkerLineSymbol::lineOffset() +{ + mMapSettings->setLayers( QStringList() << mLinesLayer->id() ); + + // Negative offset on marker line + // See http://hub.qgis.org/issues/13811 + + QString qml = mTestDataDir + "marker_line_offset.qml"; + bool success = false; + mLinesLayer->loadNamedStyle( qml, success ); + + QVERIFY( success ); + mMapSettings->setExtent( QgsRectangle(-140,-140,140,140) ); + QVERIFY( render( "line_offset" ) ); + + // TODO: -0.0 offset, see + // http://hub.qgis.org/issues/13811#note-1 +} + +bool TestQgsMarkerLineSymbol::render( const QString& theTestType ) +{ + mReport += "

" + theTestType + "

\n"; + mMapSettings->setOutputDpi( 96 ); + QgsRenderChecker checker; + checker.setControlPathPrefix( "markerlinesymbol" ); + checker.setControlName( "expected_" + theTestType ); + checker.setMapSettings( *mMapSettings ); + bool result = checker.runTest( theTestType ); + mReport += "\n\n\n" + checker.report(); + return result; +} + +QTEST_MAIN( TestQgsMarkerLineSymbol ) +#include "testqgsmarkerlinesymbol.moc" diff --git a/tests/testdata/control_images/markerlinesymbol/expected_line_offset/expected_line_offset.png b/tests/testdata/control_images/markerlinesymbol/expected_line_offset/expected_line_offset.png new file mode 100644 index 000000000000..756dad1a9096 Binary files /dev/null and b/tests/testdata/control_images/markerlinesymbol/expected_line_offset/expected_line_offset.png differ diff --git a/tests/testdata/marker_line_offset.qml b/tests/testdata/marker_line_offset.qml new file mode 100644 index 000000000000..20eb0ea3e5c5 --- /dev/null +++ b/tests/testdata/marker_line_offset.qml @@ -0,0 +1,284 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +