20
20
#include " qgsgeometry.h"
21
21
#include " qgsmapcanvas.h"
22
22
#include " qgsmapcanvassnappingutils.h"
23
+ #include " qgssnappingconfig.h"
23
24
#include " qgsmaptooladdfeature.h"
24
25
#include " qgsmapcanvastracer.h"
25
26
#include " qgsproject.h"
@@ -65,6 +66,7 @@ class TestQgsMapToolAddFeature : public QObject
65
66
void testTracing ();
66
67
void testTracingWithOffset ();
67
68
void testZ ();
69
+ void testZMSnapping ();
68
70
69
71
private:
70
72
QgisApp *mQgisApp = nullptr ;
@@ -74,6 +76,7 @@ class TestQgsMapToolAddFeature : public QObject
74
76
QgsMapToolAddFeature *mCaptureTool = nullptr ;
75
77
QgsVectorLayer *mLayerLine = nullptr ;
76
78
QgsVectorLayer *mLayerLineZ = nullptr ;
79
+ QgsVectorLayer *mLayerPointZM = nullptr ;
77
80
QgsFeatureId mFidLineF1 = 0 ;
78
81
};
79
82
@@ -139,7 +142,20 @@ void TestQgsMapToolAddFeature::initTestCase()
139
142
QCOMPARE ( mCanvas ->mapSettings ().outputSize (), QSize ( 512 , 512 ) );
140
143
QCOMPARE ( mCanvas ->mapSettings ().visibleExtent (), QgsRectangle ( 0 , 0 , 8 , 8 ) );
141
144
142
- mCanvas ->setLayers ( QList<QgsMapLayer *>() << mLayerLine << mLayerLineZ ); // << mLayerPolygon << mLayerPoint );
145
+ // make layer for snapping
146
+ mLayerPointZM = new QgsVectorLayer ( QStringLiteral ( " PointZM?crs=EPSG:27700" ), QStringLiteral ( " layer point ZM" ), QStringLiteral ( " memory" ) );
147
+ QVERIFY ( mLayerPointZM ->isValid () );
148
+ QgsProject::instance ()->addMapLayers ( QList<QgsMapLayer *>() << mLayerPointZM );
149
+
150
+ mLayerPointZM ->startEditing ();
151
+ QgsFeature pointF;
152
+ QString pointWktZM = " PointZM(6 6 3 4)" ;
153
+ pointF.setGeometry ( QgsGeometry::fromWkt ( pointWktZM ) );
154
+
155
+ mLayerPointZM ->addFeature ( pointF );
156
+ QCOMPARE ( mLayerPointZM ->featureCount (), ( long )1 );
157
+
158
+ mCanvas ->setLayers ( QList<QgsMapLayer *>() << mLayerLine << mLayerLineZ << mLayerPointZM ); // << mLayerPolygon << mLayerPoint );
143
159
144
160
mCanvas ->setSnappingUtils ( new QgsMapCanvasSnappingUtils ( mCanvas , this ) );
145
161
@@ -352,6 +368,33 @@ void TestQgsMapToolAddFeature::testZ()
352
368
mCanvas ->setCurrentLayer ( mLayerLine );
353
369
}
354
370
371
+ void TestQgsMapToolAddFeature::testZMSnapping ()
372
+ {
373
+ TestQgsMapToolAdvancedDigitizingUtils utils ( mCaptureTool );
374
+
375
+ mCanvas ->setCurrentLayer ( mLayerLine );
376
+
377
+ QSet<QgsFeatureId> oldFids = utils.existingFeatureIds ();
378
+
379
+ QgsSnappingConfig cfg = mCanvas ->snappingUtils ()->config ();
380
+ cfg.setMode ( QgsSnappingConfig::AllLayers );
381
+ cfg.setEnabled ( true );
382
+ mCanvas ->snappingUtils ()->setConfig ( cfg );
383
+
384
+ // snap a on a layer with ZM support
385
+ utils.mouseClick ( 6 , 6 , Qt::LeftButton, Qt::KeyboardModifiers (), true );
386
+ utils.mouseClick ( 5 , 0 , Qt::LeftButton );
387
+ utils.mouseClick ( 5 , 0 , Qt::RightButton );
388
+ QgsFeatureId newFid = utils.newFeatureId ( oldFids );
389
+
390
+ QCOMPARE ( mLayerLine ->getFeature ( newFid ).geometry ().get ()->is3D (), false );
391
+ QCOMPARE ( mLayerLine ->getFeature ( newFid ).geometry ().get ()->isMeasure (), false );
392
+
393
+ mLayerLine ->undoStack ()->undo ();
394
+
395
+ cfg.setEnabled ( false );
396
+ mCanvas ->snappingUtils ()->setConfig ( cfg );
397
+ }
355
398
356
399
QGSTEST_MAIN ( TestQgsMapToolAddFeature )
357
400
#include " testqgsmaptooladdfeature.moc"
0 commit comments