From c8f3f8f97e5416e7f850225cea029fdc7869e5ae Mon Sep 17 00:00:00 2001 From: Julien Cabieces Date: Tue, 17 Sep 2024 18:47:54 +0200 Subject: [PATCH] fix(ReshapeMapTool): fix snapping matches with tracing Fixes #57225 --- src/gui/maptools/qgsmaptoolcapture.cpp | 2 +- tests/src/app/testqgsmaptoolreshape.cpp | 37 +++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/gui/maptools/qgsmaptoolcapture.cpp b/src/gui/maptools/qgsmaptoolcapture.cpp index 66cf52e0f5fd..e9bb1da9eb6f 100644 --- a/src/gui/maptools/qgsmaptoolcapture.cpp +++ b/src/gui/maptools/qgsmaptoolcapture.cpp @@ -316,8 +316,8 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point ) mSnappingMatches.removeLast(); mSnappingMatches.append( QgsPointLocator::Match() ); - int pointBefore = mCaptureCurve.numPoints(); addCurve( new QgsLineString( mapPoints ) ); + int pointBefore = mCaptureCurve.numPoints(); resetRubberBand(); diff --git a/tests/src/app/testqgsmaptoolreshape.cpp b/tests/src/app/testqgsmaptoolreshape.cpp index 054597d92071..f1deca08169c 100644 --- a/tests/src/app/testqgsmaptoolreshape.cpp +++ b/tests/src/app/testqgsmaptoolreshape.cpp @@ -16,17 +16,15 @@ #include "qgstest.h" #include "qgisapp.h" -#include "qgsadvanceddigitizingdockwidget.h" #include "qgsgeometry.h" #include "qgsmapcanvas.h" -#include "qgsmapcanvassnappingutils.h" #include "qgssnappingconfig.h" #include "qgssnappingutils.h" #include "qgsmaptoolreshape.h" #include "qgsproject.h" #include "qgssettingsregistrycore.h" #include "qgsvectorlayer.h" -#include "qgsmapmouseevent.h" +#include "qgsmapcanvastracer.h" #include "testqgsmaptoolutils.h" @@ -48,6 +46,7 @@ class TestQgsMapToolReshape: public QObject void testTopologicalEditing(); void testAvoidIntersectionAndTopoEdit(); void reshapeWithBindingLine(); + void testWithTracing(); private: QgisApp *mQgisApp = nullptr; @@ -378,6 +377,38 @@ void TestQgsMapToolReshape::reshapeWithBindingLine() vl->rollBack(); } +void TestQgsMapToolReshape::testWithTracing() +{ + QgsProject::instance()->addMapLayers( QList() << mLayerTopo ); + mCanvas->setLayers( QList() << mLayerTopo ); + + std::unique_ptr tracer( new QgsMapCanvasTracer( mCanvas, nullptr ) ); + + const bool topologicalEditing = QgsProject::instance()->topologicalEditing(); + QgsProject::instance()->setTopologicalEditing( true ); + mCanvas->setCurrentLayer( mLayerTopo ); + TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool ); + + // test with default Z value = 333 + QgsSettingsRegistryCore::settingsDigitizingDefaultZValue->setValue( 333 ); + + utils.mouseClick( 7, 0, Qt::LeftButton, Qt::KeyboardModifiers(), true ); + utils.mouseClick( 4, 0, Qt::LeftButton, Qt::KeyboardModifiers(), true ); + utils.mouseClick( 4, 4, Qt::LeftButton, Qt::KeyboardModifiers(), true ); + utils.mouseClick( 7, 4, Qt::LeftButton, Qt::KeyboardModifiers(), true ); + utils.mouseClick( 8, 5, Qt::RightButton ); + + QCOMPARE( mLayerTopo->getFeature( 1 ).geometry().asWkt(), "Polygon ((0 0, 4 0, 4 4, 0 4))" ); + QCOMPARE( mLayerTopo->getFeature( 2 ).geometry().asWkt(), "Polygon ((7 0, 8 0, 8 4, 7 4, 4 4, 4 0, 7 0))" ); + + mLayerTopo->undoStack()->undo(); + + QCOMPARE( mLayerTopo->getFeature( 1 ).geometry().asWkt(), QStringLiteral( "Polygon ((0 0, 4 0, 4 4, 0 4))" ) ); + QCOMPARE( mLayerTopo->getFeature( 2 ).geometry().asWkt(), QStringLiteral( "Polygon ((7 0, 8 0, 8 4, 7 4))" ) ); + + QgsProject::instance()->setTopologicalEditing( topologicalEditing ); +} + QGSTEST_MAIN( TestQgsMapToolReshape ) #include "testqgsmaptoolreshape.moc"