Skip to content

Commit 941ec4c

Browse files
committedFeb 8, 2019
[vertex tool] add new vertex without moving it (shift+double click)
Obviously this is something that some people find useful, but because it is not so common it uses shift modifier.
1 parent 471734a commit 941ec4c

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
 

‎src/app/vertextool/qgsvertextool.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,14 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
479479
// so we need to cancel edge moving before we start dragging new vertex
480480
stopDragging();
481481
startDraggingAddVertex( m );
482+
483+
if ( e->modifiers() & Qt::ShiftModifier )
484+
{
485+
// if this was shift + double click, immediately place the vertex
486+
moveVertex( m.point(), &m );
487+
// force update of rubber bands
488+
mouseMoveNotDragging( e );
489+
}
482490
}
483491
else if ( mSelectionRect )
484492
{

‎tests/src/app/testqgsvertextool.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

401479
void TestQgsVertexTool::testDeleteVertex()
402480
{

0 commit comments

Comments
 (0)
Please sign in to comment.