-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
testqgsrubberband.cpp
106 lines (82 loc) · 3.51 KB
/
testqgsrubberband.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/***************************************************************************
testqgsrubberband.cpp
--------------------------------------
Date : 28.4.2013
Copyright : (C) 2013 Vinayan Parameswaran
Email : vinayan123 at gmail dot com
***************************************************************************
* *
* 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>
#include <QObject>
#include <QString>
#include <QObject>
#include <QCoreApplication>
#include <QWidget>
#include <qgsapplication.h>
#include <qgsmapcanvas.h>
#include <qgsvectorlayer.h>
#include <qgsrubberband.h>
#include <qgslogger.h>
class TestQgsRubberband: public QObject
{
Q_OBJECT;
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 testAddSingleMultiGeometries(); //test for #7728
private:
QgsMapCanvas* mCanvas;
QgsVectorLayer* mPolygonLayer;
QString mTestDataDir;
QgsRubberBand* mRubberband;
};
void TestQgsRubberband::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();
// Setup a map canvas with a vector layer loaded...
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
mTestDataDir = myDataDir + QDir::separator();
//
// load a vector layer
//
QString myPolygonFileName = mTestDataDir + "polys.shp";
QFileInfo myPolygonFileInfo( myPolygonFileName );
mPolygonLayer = new QgsVectorLayer( myPolygonFileInfo.filePath(),
myPolygonFileInfo.completeBaseName(), "ogr" );
mCanvas = new QgsMapCanvas();
mRubberband = 0;
}
void TestQgsRubberband::cleanupTestCase()
{
delete mRubberband;
delete mPolygonLayer;
delete mCanvas;
}
void TestQgsRubberband::init()
{
}
void TestQgsRubberband::cleanup()
{
}
void TestQgsRubberband::testAddSingleMultiGeometries()
{
mRubberband = new QgsRubberBand( mCanvas, mPolygonLayer->geometryType() );
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))" );
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)))" );
mCanvas->setExtent(QgsRectangle(-1e-3,-1e-3,1e-3,1e-3)); // otherwise point cannot be converted to canvas coord
mRubberband->addGeometry( geomSinglePart, mPolygonLayer );
mRubberband->addGeometry( geomMultiPart, mPolygonLayer );
QVERIFY( mRubberband->numberOfVertices() == 15 );
}
QTEST_MAIN( TestQgsRubberband )
#include "moc_testqgsrubberband.cxx"