Skip to content

Commit e693e81

Browse files
authoredMay 13, 2019
Merge pull request #9971 from olivierdalang/node-tool-chain-add
[nodetool] chained add vertex at endpoint
2 parents 6a3cd82 + 71a2766 commit e693e81

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
 

‎src/app/vertextool/qgsvertextool.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,18 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato
20402040

20412041
setHighlightedVertices( mSelectedVertices ); // update positions of existing highlighted vertices
20422042
setHighlightedVerticesVisible( true ); // time to show highlighted vertices again
2043+
2044+
// restart startDraggingAddVertexAtEndpoint right after it finishes
2045+
if ( addingAtEndpoint )
2046+
{
2047+
if ( mMouseAtEndpoint->vertexId != 0 )
2048+
{
2049+
// If we were adding at the end of the feature, we need to update the index
2050+
mMouseAtEndpoint.reset( new Vertex( mMouseAtEndpoint->layer, mMouseAtEndpoint->fid, mMouseAtEndpoint->vertexId + 1 ) );
2051+
}
2052+
// And then we just restart the drag
2053+
startDraggingAddVertexAtEndpoint( mapPoint );
2054+
}
20432055
}
20442056

20452057

‎tests/src/app/testqgsvertextool.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ void TestQgsVertexTool::testAddVertexAtEndpoint()
387387
mouseMove( 1, 3 ); // first we need to move to the vertex
388388
mouseClick( 1, 3 + offsetInMapUnits, Qt::LeftButton );
389389
mouseClick( 2, 3, Qt::LeftButton );
390+
mouseClick( 2, 3, Qt::RightButton ); // we need a right click to stop adding new nodes
390391

391392
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
392393
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3, 2 3)" ) );
@@ -401,6 +402,7 @@ void TestQgsVertexTool::testAddVertexAtEndpoint()
401402
mouseMove( 2, 1 ); // first we need to move to the vertex
402403
mouseClick( 2 + offsetInMapUnits, 1, Qt::LeftButton );
403404
mouseClick( 2, 2, Qt::LeftButton );
405+
mouseClick( 2, 2, Qt::RightButton ); // we need a right click to stop adding new nodes
404406

405407
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
406408
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 2, 2 1, 1 1, 1 3)" ) );
@@ -409,6 +411,25 @@ void TestQgsVertexTool::testAddVertexAtEndpoint()
409411
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
410412

411413
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
414+
415+
// add three vertices at once
416+
417+
mouseMove( 2, 1 ); // first we need to move to the vertex
418+
mouseClick( 2 + offsetInMapUnits, 1, Qt::LeftButton );
419+
mouseClick( 2, 2, Qt::LeftButton );
420+
mouseClick( 2, 3, Qt::LeftButton );
421+
mouseClick( 2, 4, Qt::LeftButton );
422+
mouseClick( 2, 2, Qt::RightButton ); // we need a right click to stop adding new nodes
423+
424+
QCOMPARE( mLayerLine->undoStack()->index(), 4 );
425+
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 4, 2 3, 2 2, 2 1, 1 1, 1 3)" ) );
426+
427+
mLayerLine->undoStack()->undo();
428+
mLayerLine->undoStack()->undo();
429+
mLayerLine->undoStack()->undo();
430+
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
431+
432+
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
412433
}
413434

414435
void TestQgsVertexTool::testAddVertexDoubleClick()

0 commit comments

Comments
 (0)
Please sign in to comment.