@@ -60,6 +60,8 @@ class TestQgsVertexTool : public QObject
6060 void testMoveEdge ();
6161 void testAddVertex ();
6262 void testAddVertexAtEndpoint ();
63+ void testAddVertexDoubleClick ();
64+ void testAddVertexDoubleClickWithShift ();
6365 void testDeleteVertex ();
6466 void testMoveMultipleVertices ();
6567 void testMoveMultipleVertices2 ();
@@ -102,6 +104,18 @@ class TestQgsVertexTool : public QObject
102104 mouseRelease ( mapX, mapY, button, stateKey );
103105 }
104106
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+
105119 void keyClick ( int key )
106120 {
107121 QKeyEvent e1 ( QEvent::KeyPress, key, Qt::KeyboardModifiers () );
@@ -397,6 +411,70 @@ void TestQgsVertexTool::testAddVertexAtEndpoint()
397411 QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 1, 1 1, 1 3)" ) );
398412}
399413
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+
400478
401479void TestQgsVertexTool::testDeleteVertex ()
402480{
0 commit comments