|
14 | 14 | ***************************************************************************/
|
15 | 15 |
|
16 | 16 | #include "qgstest.h"
|
17 |
| -#include "qgsapplication.h" |
| 17 | + |
| 18 | +#include "qgisapp.h" |
| 19 | +#include "qgsadvanceddigitizingdockwidget.h" |
| 20 | +#include "qgsgeometry.h" |
18 | 21 | #include "qgsmapcanvas.h"
|
19 |
| -#include "qgsvectorlayer.h" |
20 |
| -#include "qgslinestring.h" |
| 22 | +#include "qgsmapcanvassnappingutils.h" |
| 23 | +#include "qgssnappingconfig.h" |
| 24 | +#include "qgssnappingutils.h" |
21 | 25 | #include "qgsmaptoolreshape.h"
|
22 |
| -#include "qgisapp.h" |
| 26 | +#include "qgsproject.h" |
| 27 | +#include "qgssettings.h" |
| 28 | +#include "qgsvectorlayer.h" |
| 29 | +#include "qgsmapmouseevent.h" |
| 30 | +#include "testqgsmaptoolutils.h" |
| 31 | + |
23 | 32 |
|
24 |
| -class TestQgsMapToolReshape : public QObject |
| 33 | +/** |
| 34 | + * \ingroup UnitTests |
| 35 | + * This is a unit test for the vertex tool |
| 36 | + */ |
| 37 | +class TestQgsMapToolReshape: public QObject |
25 | 38 | {
|
26 | 39 | Q_OBJECT
|
27 | 40 | public:
|
28 |
| - TestQgsMapToolReshape() = default; |
| 41 | + TestQgsMapToolReshape(); |
29 | 42 |
|
30 | 43 | private slots:
|
31 |
| - void initTestCase(); // will be called before the first testfunction is executed. |
32 |
| - void cleanupTestCase(); // will be called after the last testfunction was executed. |
33 |
| - void init(); // will be called before each testfunction is executed. |
34 |
| - void cleanup(); // will be called after every testfunction. |
| 44 | + void initTestCase();// will be called before the first testfunction is executed. |
| 45 | + void cleanupTestCase();// will be called after the last testfunction was executed. |
35 | 46 |
|
| 47 | + void testReshapeZ(); |
36 | 48 | void reshapeWithBindingLine();
|
37 | 49 |
|
38 | 50 | private:
|
39 | 51 | QgisApp *mQgisApp = nullptr;
|
| 52 | + QgsMapCanvas *mCanvas = nullptr; |
| 53 | + QgsMapToolReshape *mCaptureTool = nullptr; |
| 54 | + QgsVectorLayer *mLayerLineZ = nullptr; |
40 | 55 | };
|
41 | 56 |
|
| 57 | +TestQgsMapToolReshape::TestQgsMapToolReshape() = default; |
| 58 | + |
| 59 | + |
| 60 | +//runs before all tests |
42 | 61 | void TestQgsMapToolReshape::initTestCase()
|
43 | 62 | {
|
| 63 | + qDebug() << "TestMapToolCapture::initTestCase()"; |
| 64 | + // init QGIS's paths - true means that all path will be inited from prefix |
44 | 65 | QgsApplication::init();
|
45 | 66 | QgsApplication::initQgis();
|
46 | 67 |
|
47 |
| - // Set up the QgsSettings environment |
| 68 | + // Set up the QSettings environment |
48 | 69 | QCoreApplication::setOrganizationName( QStringLiteral( "QGIS" ) );
|
49 | 70 | QCoreApplication::setOrganizationDomain( QStringLiteral( "qgis.org" ) );
|
50 | 71 | QCoreApplication::setApplicationName( QStringLiteral( "QGIS-TEST" ) );
|
51 | 72 |
|
52 |
| - QgsApplication::showSettings(); |
| 73 | + mQgisApp = new QgisApp(); |
53 | 74 |
|
54 |
| - // enforce C locale because the tests expect it |
55 |
| - // (decimal separators / thousand separators) |
56 |
| - QLocale::setDefault( QLocale::c() ); |
| 75 | + mCanvas = new QgsMapCanvas(); |
57 | 76 |
|
58 |
| - mQgisApp = new QgisApp(); |
| 77 | + mCanvas->setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3946" ) ) ); |
| 78 | + |
| 79 | + mCanvas->setFrameStyle( QFrame::NoFrame ); |
| 80 | + mCanvas->resize( 512, 512 ); |
| 81 | + mCanvas->setExtent( QgsRectangle( 0, 0, 8, 8 ) ); |
| 82 | + mCanvas->show(); // to make the canvas resize |
| 83 | + mCanvas->hide(); |
| 84 | + |
| 85 | + // make testing layers |
| 86 | + mLayerLineZ = new QgsVectorLayer( QStringLiteral( "LineStringZ?crs=EPSG:3946" ), QStringLiteral( "layer line Z" ), QStringLiteral( "memory" ) ); |
| 87 | + QVERIFY( mLayerLineZ->isValid() ); |
| 88 | + QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerLineZ ); |
| 89 | + |
| 90 | + mLayerLineZ->startEditing(); |
| 91 | + QString wkt1 = "LineStringZ (0 0 0, 1 1 0, 1 2 0)"; |
| 92 | + QString wkt2 = "LineStringZ (2 1 5, 3 3 5)"; |
| 93 | + QgsFeature f1; |
| 94 | + f1.setGeometry( QgsGeometry::fromWkt( wkt1 ) ); |
| 95 | + QgsFeature f2; |
| 96 | + f2.setGeometry( QgsGeometry::fromWkt( wkt2 ) ); |
| 97 | + |
| 98 | + QgsFeatureList flist; |
| 99 | + flist << f1 << f2; |
| 100 | + mLayerLineZ->dataProvider()->addFeatures( flist ); |
| 101 | + QCOMPARE( mLayerLineZ->featureCount(), ( long )2 ); |
| 102 | + QCOMPARE( mLayerLineZ->getFeature( 1 ).geometry().asWkt(), wkt1 ); |
| 103 | + QCOMPARE( mLayerLineZ->getFeature( 2 ).geometry().asWkt(), wkt2 ); |
| 104 | + |
| 105 | + QgsSnappingConfig cfg = mCanvas->snappingUtils()->config(); |
| 106 | + cfg.setMode( QgsSnappingConfig::AllLayers ); |
| 107 | + cfg.setTolerance( 100 ); |
| 108 | + cfg.setType( QgsSnappingConfig::VertexAndSegment ); |
| 109 | + cfg.setEnabled( true ); |
| 110 | + mCanvas->snappingUtils()->setConfig( cfg ); |
| 111 | + |
| 112 | + mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerLineZ ); |
| 113 | + mCanvas->setCurrentLayer( mLayerLineZ ); |
| 114 | + |
| 115 | + // create the tool |
| 116 | + mCaptureTool = new QgsMapToolReshape( mCanvas ); |
| 117 | + mCanvas->setMapTool( mCaptureTool ); |
| 118 | + |
| 119 | + QCOMPARE( mCanvas->mapSettings().outputSize(), QSize( 512, 512 ) ); |
| 120 | + QCOMPARE( mCanvas->mapSettings().visibleExtent(), QgsRectangle( 0, 0, 8, 8 ) ); |
59 | 121 | }
|
60 | 122 |
|
| 123 | +//runs after all tests |
61 | 124 | void TestQgsMapToolReshape::cleanupTestCase()
|
62 | 125 | {
|
| 126 | + delete mCaptureTool; |
| 127 | + delete mCanvas; |
63 | 128 | QgsApplication::exitQgis();
|
64 | 129 | }
|
65 | 130 |
|
66 |
| -void TestQgsMapToolReshape::init() |
| 131 | +void TestQgsMapToolReshape::testReshapeZ() |
67 | 132 | {
|
68 |
| -} |
| 133 | + TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool ); |
| 134 | + |
| 135 | + // test with default Z value = 333 |
| 136 | + QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 333 ); |
| 137 | + |
| 138 | + QSet<QgsFeatureId> oldFids = utils.existingFeatureIds(); |
| 139 | + |
| 140 | + utils.mouseClick( 1, 2, Qt::LeftButton, Qt::KeyboardModifiers(), true ); |
| 141 | + utils.mouseClick( 2, 1, Qt::LeftButton, Qt::KeyboardModifiers(), true ); |
| 142 | + utils.mouseClick( 2, 1, Qt::RightButton ); |
| 143 | + |
| 144 | + QString wkt = "LineStringZ (0 0 0, 1 1 0, 1 2 0, 2 1 5)"; |
| 145 | + QCOMPARE( mLayerLineZ->getFeature( 1 ).geometry().asWkt(), wkt ); |
| 146 | + |
| 147 | + mLayerLineZ->undoStack()->undo(); |
69 | 148 |
|
70 |
| -void TestQgsMapToolReshape::cleanup() |
71 |
| -{ |
72 | 149 | }
|
73 | 150 |
|
74 | 151 | void TestQgsMapToolReshape::reshapeWithBindingLine()
|
@@ -139,5 +216,6 @@ void TestQgsMapToolReshape::reshapeWithBindingLine()
|
139 | 216 | vl->rollBack();
|
140 | 217 | }
|
141 | 218 |
|
| 219 | + |
142 | 220 | QGSTEST_MAIN( TestQgsMapToolReshape )
|
143 | 221 | #include "testqgsmaptoolreshape.moc"
|
0 commit comments