Skip to content

Commit 9d93514

Browse files
committedApr 28, 2013
fix QgsRubberband.addGeometry when adding multipart geometries
1 parent c47fbbe commit 9d93514

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed
 

‎src/gui/qgsrubberband.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
298298
case QGis::WKBMultiLineString:
299299
case QGis::WKBMultiLineString25D:
300300
{
301-
mPoints.clear();
302301

303302
QgsMultiPolyline mline = geom->asMultiPolyline();
304303
for ( int i = 0; i < mline.size(); ++i, ++idx )
@@ -347,7 +346,6 @@ void QgsRubberBand::addGeometry( QgsGeometry* geom, QgsVectorLayer* layer )
347346
case QGis::WKBMultiPolygon:
348347
case QGis::WKBMultiPolygon25D:
349348
{
350-
mPoints.clear();
351349

352350
QgsMultiPolygon multipoly = geom->asMultiPolygon();
353351
for ( int i = 0; i < multipoly.size(); ++i, ++idx )

‎tests/src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,5 @@ ADD_QGIS_TEST(histogramtest testqgsrasterhistogram.cpp)
121121
ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
122122
ADD_QGIS_TEST(scalecombobox testqgsscalecombobox.cpp)
123123
ADD_QGIS_TEST(dualviewtest testqgsdualview.cpp )
124+
ADD_QGIS_TEST(rubberbandtest testqgsrubberband.cpp )
124125

‎tests/src/gui/testqgsrubberband.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/***************************************************************************
2+
testqgsrubberband.cpp
3+
--------------------------------------
4+
Date : 28.4.2013
5+
Copyright : (C) 2013 Vinayan Parameswaran
6+
Email : vinayan123 at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
17+
#include <QtTest>
18+
#include <QObject>
19+
#include <QString>
20+
#include <QObject>
21+
#include <QCoreApplication>
22+
#include <QWidget>
23+
24+
#include <qgsapplication.h>
25+
#include <qgsmapcanvas.h>
26+
#include <qgsvectorlayer.h>
27+
#include <qgsrubberband.h>
28+
#include <qgslogger.h>
29+
30+
class TestQgsRubberband: public QObject
31+
{
32+
Q_OBJECT;
33+
private slots:
34+
void initTestCase(); // will be called before the first testfunction is executed.
35+
void cleanupTestCase(); // will be called after the last testfunction was executed.
36+
void init(); // will be called before each testfunction is executed.
37+
void cleanup(); // will be called after every testfunction.
38+
39+
void testAddSingleMultiGeometries(); //test for #7728
40+
41+
private:
42+
QgsMapCanvas* mCanvas;
43+
QgsVectorLayer* mPolygonLayer;
44+
QString mTestDataDir;
45+
QgsRubberBand* mRubberband;
46+
};
47+
48+
void TestQgsRubberband::initTestCase()
49+
{
50+
QgsApplication::init();
51+
QgsApplication::initQgis();
52+
QgsApplication::showSettings();
53+
54+
// Setup a map canvas with a vector layer loaded...
55+
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
56+
mTestDataDir = myDataDir + QDir::separator();
57+
58+
//
59+
// load a vector layer
60+
//
61+
QString myPolygonFileName = mTestDataDir + "polys.shp";
62+
QFileInfo myPolygonFileInfo( myPolygonFileName );
63+
mPolygonLayer = new QgsVectorLayer( myPolygonFileInfo.filePath(),
64+
myPolygonFileInfo.completeBaseName(), "ogr" );
65+
66+
mCanvas = new QgsMapCanvas();
67+
mRubberband = 0;
68+
}
69+
70+
void TestQgsRubberband::cleanupTestCase()
71+
{
72+
delete mRubberband;
73+
delete mPolygonLayer;
74+
delete mCanvas;
75+
}
76+
77+
void TestQgsRubberband::init()
78+
{
79+
80+
}
81+
82+
void TestQgsRubberband::cleanup()
83+
{
84+
85+
}
86+
87+
void TestQgsRubberband::testAddSingleMultiGeometries()
88+
{
89+
mRubberband = new QgsRubberBand( mCanvas, mPolygonLayer->geometryType() );
90+
QgsGeometry* geomSinglePart = QgsGeometry::fromWkt( "POLYGON((-0.00022418 -0.00000279,-0.0001039 0.00002395,-0.00008677 -0.00005313,-0.00020705 -0.00007987,-0.00022418 -0.00000279))" );
91+
QgsGeometry* geomMultiPart = QgsGeometry::fromWkt( "MULTIPOLYGON(((-0.00018203 0.00012178,-0.00009444 0.00014125,-0.00007861 0.00007001,-0.00016619 0.00005054,-0.00018203 0.00012178)),((-0.00030957 0.00009464,-0.00021849 0.00011489,-0.00020447 0.00005184,-0.00029555 0.00003158,-0.00030957 0.00009464)))" );
92+
93+
mRubberband->addGeometry( geomSinglePart, mPolygonLayer );
94+
mRubberband->addGeometry( geomMultiPart, mPolygonLayer );
95+
96+
QVERIFY( mRubberband->numberOfVertices() == 15 );
97+
}
98+
99+
QTEST_MAIN( TestQgsRubberband )
100+
#include "moc_testqgsrubberband.cxx"
101+
102+
103+
104+
105+

0 commit comments

Comments
 (0)
Please sign in to comment.