Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix endpoint swap on negative marker line offset #2442

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,11 @@ QList<QPolygonF> 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;
}
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
154 changes: 154 additions & 0 deletions tests/src/core/testqgsmarkerlinesymbol.cpp
Original file line number Diff line number Diff line change
@@ -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 <QtTest/QtTest>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QApplication>
#include <QFileInfo>
#include <QDir>

//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 <qgsrenderchecker.h>

/** \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<QgsMapLayer *> 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 += "<h1>Line Marker Symbol Tests</h1>\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 += "<h2>" + theTestType + "</h2>\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"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading