@@ -60,6 +60,8 @@ class TestQgsVertexTool : public QObject
60
60
void testMoveEdge ();
61
61
void testAddVertex ();
62
62
void testAddVertexAtEndpoint ();
63
+ void testAddVertexDoubleClick ();
64
+ void testAddVertexDoubleClickWithShift ();
63
65
void testDeleteVertex ();
64
66
void testMoveMultipleVertices ();
65
67
void testMoveMultipleVertices2 ();
@@ -102,6 +104,18 @@ class TestQgsVertexTool : public QObject
102
104
mouseRelease ( mapX, mapY, button, stateKey );
103
105
}
104
106
107
+ void mouseDoubleClick ( double mapX, double mapY, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers() )
108
+ {
109
+ // this is how Qt passes the events: 1. mouse press, 2. mouse release, 3. mouse double-click, 4. mouse release
110
+
111
+ mouseClick ( mapX, mapY, button, stateKey );
112
+
113
+ QgsMapMouseEvent e ( mCanvas , QEvent::MouseButtonDblClick, mapToScreen ( mapX, mapY ), button, button, stateKey );
114
+ mVertexTool ->canvasDoubleClickEvent ( &e );
115
+
116
+ mouseRelease ( mapX, mapY, button, stateKey );
117
+ }
118
+
105
119
void keyClick ( int key )
106
120
{
107
121
QKeyEvent e1 ( QEvent::KeyPress, key, Qt::KeyboardModifiers () );
@@ -397,6 +411,70 @@ void TestQgsVertexTool::testAddVertexAtEndpoint()
397
411
QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 1, 1 1, 1 3)" ) );
398
412
}
399
413
414
+ void TestQgsVertexTool::testAddVertexDoubleClick ()
415
+ {
416
+ // add vertex in linestring with double-click and then place the point to the new location
417
+
418
+ mouseDoubleClick ( 1 , 1.5 , Qt::LeftButton );
419
+ mouseClick ( 2 , 2 , Qt::LeftButton );
420
+
421
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 2 );
422
+ QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 1, 1 1, 2 2, 1 3)" ) );
423
+
424
+ mLayerLine ->undoStack ()->undo ();
425
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 1 );
426
+
427
+ QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 1, 1 1, 1 3)" ) );
428
+
429
+ // add vertex in polygon
430
+ mouseDoubleClick ( 4 , 2 , Qt::LeftButton );
431
+ mouseClick ( 3 , 2.5 , Qt::LeftButton );
432
+
433
+ QCOMPARE ( mLayerPolygon ->undoStack ()->index (), 2 );
434
+ QCOMPARE ( mLayerPolygon ->getFeature ( mFidPolygonF1 ).geometry (), QgsGeometry::fromWkt ( " POLYGON((4 1, 7 1, 7 4, 4 4, 3 2.5, 4 1))" ) );
435
+
436
+ mLayerPolygon ->undoStack ()->undo ();
437
+
438
+ QCOMPARE ( mLayerPolygon ->getFeature ( mFidPolygonF1 ).geometry (), QgsGeometry::fromWkt ( " POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );
439
+
440
+ // no other unexpected changes happened
441
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 1 );
442
+ QCOMPARE ( mLayerPolygon ->undoStack ()->index (), 1 );
443
+ QCOMPARE ( mLayerPoint ->undoStack ()->index (), 1 );
444
+
445
+ }
446
+
447
+ void TestQgsVertexTool::testAddVertexDoubleClickWithShift ()
448
+ {
449
+ // add vertex in linestring with shift + double-click to immediately place the new vertex
450
+
451
+ mouseDoubleClick ( 1 , 1.5 , Qt::LeftButton, Qt::ShiftModifier );
452
+
453
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 2 );
454
+ QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 1, 1 1, 1 1.5, 1 3)" ) );
455
+
456
+ mLayerLine ->undoStack ()->undo ();
457
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 1 );
458
+
459
+ QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 1, 1 1, 1 3)" ) );
460
+
461
+ // add vertex in polygon
462
+ mouseDoubleClick ( 4 , 2 , Qt::LeftButton, Qt::ShiftModifier );
463
+
464
+ QCOMPARE ( mLayerPolygon ->undoStack ()->index (), 2 );
465
+ QCOMPARE ( mLayerPolygon ->getFeature ( mFidPolygonF1 ).geometry (), QgsGeometry::fromWkt ( " POLYGON((4 1, 7 1, 7 4, 4 4, 4 2, 4 1))" ) );
466
+
467
+ mLayerPolygon ->undoStack ()->undo ();
468
+
469
+ QCOMPARE ( mLayerPolygon ->getFeature ( mFidPolygonF1 ).geometry (), QgsGeometry::fromWkt ( " POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );
470
+
471
+ // no other unexpected changes happened
472
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 1 );
473
+ QCOMPARE ( mLayerPolygon ->undoStack ()->index (), 1 );
474
+ QCOMPARE ( mLayerPoint ->undoStack ()->index (), 1 );
475
+
476
+ }
477
+
400
478
401
479
void TestQgsVertexTool::testDeleteVertex ()
402
480
{
0 commit comments