23
23
#include " qgsmaptooladdfeature.h"
24
24
#include " qgsmapcanvastracer.h"
25
25
#include " qgsproject.h"
26
+ #include " qgssettings.h"
26
27
#include " qgsvectorlayer.h"
27
28
28
29
@@ -81,6 +82,7 @@ class TestQgsMapToolAddFeature : public QObject
81
82
void testNoTracing ();
82
83
void testTracing ();
83
84
void testTracingWithOffset ();
85
+ void testZ ();
84
86
85
87
private:
86
88
QPoint mapToScreen ( double mapX, double mapY )
@@ -129,6 +131,7 @@ class TestQgsMapToolAddFeature : public QObject
129
131
QAction *mEnableTracingAction = nullptr ;
130
132
QgsMapToolAddFeature *mCaptureTool = nullptr ;
131
133
QgsVectorLayer *mLayerLine = nullptr ;
134
+ QgsVectorLayer *mLayerLineZ = nullptr ;
132
135
QgsFeatureId mFidLineF1 = 0 ;
133
136
};
134
137
@@ -172,6 +175,20 @@ void TestQgsMapToolAddFeature::initTestCase()
172
175
// just one added feature
173
176
QCOMPARE ( mLayerLine ->undoStack ()->index (), 1 );
174
177
178
+ // make testing layers
179
+ mLayerLineZ = new QgsVectorLayer ( QStringLiteral ( " LineStringZ?crs=EPSG:27700" ), QStringLiteral ( " layer line Z" ), QStringLiteral ( " memory" ) );
180
+ QVERIFY ( mLayerLineZ ->isValid () );
181
+ QgsProject::instance ()->addMapLayers ( QList<QgsMapLayer *>() << mLayerLineZ );
182
+
183
+ QgsPolyline line2;
184
+ line2 << QgsPoint ( 1 , 1 , 0 ) << QgsPoint ( 2 , 1 , 1 ) << QgsPoint ( 3 , 2 , 2 ) << QgsPoint ( 1 , 2 , 3 ) << QgsPoint ( 1 , 1 , 0 );
185
+ QgsFeature lineF2;
186
+ lineF2.setGeometry ( QgsGeometry::fromPolyline ( line2 ) );
187
+
188
+ mLayerLineZ ->startEditing ();
189
+ mLayerLineZ ->addFeature ( lineF2 );
190
+ QCOMPARE ( mLayerLineZ ->featureCount (), ( long )1 );
191
+
175
192
mCanvas ->setFrameStyle ( QFrame::NoFrame );
176
193
mCanvas ->resize ( 512 , 512 );
177
194
mCanvas ->setExtent ( QgsRectangle ( 0 , 0 , 8 , 8 ) );
@@ -180,7 +197,7 @@ void TestQgsMapToolAddFeature::initTestCase()
180
197
QCOMPARE ( mCanvas ->mapSettings ().outputSize (), QSize ( 512 , 512 ) );
181
198
QCOMPARE ( mCanvas ->mapSettings ().visibleExtent (), QgsRectangle ( 0 , 0 , 8 , 8 ) );
182
199
183
- mCanvas ->setLayers ( QList<QgsMapLayer *>() << mLayerLine ); // << mLayerPolygon << mLayerPoint );
200
+ mCanvas ->setLayers ( QList<QgsMapLayer *>() << mLayerLine << mLayerLineZ ); // << mLayerPolygon << mLayerPoint );
184
201
185
202
mCanvas ->setSnappingUtils ( new QgsMapCanvasSnappingUtils ( mCanvas , this ) );
186
203
@@ -346,6 +363,45 @@ void TestQgsMapToolAddFeature::testTracingWithOffset()
346
363
mEnableTracingAction ->setChecked ( false );
347
364
}
348
365
366
+ void TestQgsMapToolAddFeature::testZ ()
367
+ {
368
+ mCanvas ->setCurrentLayer ( mLayerLineZ );
369
+
370
+ // test with default Z value = 333
371
+ QgsSettings ().setValue ( QStringLiteral ( " /qgis/digitizing/default_z_value" ), 333 );
372
+
373
+ QSet<QgsFeatureId> oldFids = _existingFeatureIds ( mLayerLineZ );
374
+ mouseClick ( 4 , 0 , Qt::LeftButton );
375
+ mouseClick ( 5 , 0 , Qt::LeftButton );
376
+ mouseClick ( 5 , 1 , Qt::LeftButton );
377
+ mouseClick ( 4 , 1 , Qt::LeftButton );
378
+ mouseClick ( 4 , 1 , Qt::RightButton );
379
+ QgsFeatureId newFid = _newFeatureId ( mLayerLineZ , oldFids );
380
+
381
+ QString wkt = " LineStringZ (4 0 333, 5 0 333, 5 1 333, 4 1 333)" ;
382
+ QCOMPARE ( mLayerLineZ ->getFeature ( newFid ).geometry (), QgsGeometry::fromWkt ( wkt ) );
383
+
384
+ mLayerLine ->undoStack ()->undo ();
385
+
386
+ // test with default Z value = 222
387
+ QgsSettings ().setValue ( QStringLiteral ( " /qgis/digitizing/default_z_value" ), 222 );
388
+
389
+ oldFids = _existingFeatureIds ( mLayerLineZ );
390
+ mouseClick ( 4 , 0 , Qt::LeftButton );
391
+ mouseClick ( 5 , 0 , Qt::LeftButton );
392
+ mouseClick ( 5 , 1 , Qt::LeftButton );
393
+ mouseClick ( 4 , 1 , Qt::LeftButton );
394
+ mouseClick ( 4 , 1 , Qt::RightButton );
395
+ newFid = _newFeatureId ( mLayerLineZ , oldFids );
396
+
397
+ wkt = " LineStringZ (4 0 222, 5 0 222, 5 1 222, 4 1 222)" ;
398
+ QCOMPARE ( mLayerLineZ ->getFeature ( newFid ).geometry (), QgsGeometry::fromWkt ( wkt ) );
399
+
400
+ mLayerLine ->undoStack ()->undo ();
401
+
402
+ mCanvas ->setCurrentLayer ( mLayerLine );
403
+ }
404
+
349
405
350
406
QGSTEST_MAIN ( TestQgsMapToolAddFeature )
351
407
#include " testqgsmaptooladdfeature.moc"
0 commit comments