diff --git a/src/gui/qgsmaptoolcapture.cpp b/src/gui/qgsmaptoolcapture.cpp index e1044acb0825..e17ae834bb74 100644 --- a/src/gui/qgsmaptoolcapture.cpp +++ b/src/gui/qgsmaptoolcapture.cpp @@ -316,7 +316,6 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point ) mSnappingMatches.removeLast(); mSnappingMatches.append( QgsPointLocator::Match() ); - int pointBefore = mCaptureCurve.numPoints(); addCurve( new QgsLineString( mapPoints ) ); resetRubberBand(); @@ -324,6 +323,10 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point ) // Curves de-approximation if ( QgsSettingsRegistryCore::settingsDigitizingConvertToCurve->value() ) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + int pointBefore = mCaptureCurve.numPoints(); +#endif + // If the tool and the layer support curves QgsVectorLayer *vlayer = qobject_cast( layer() ); if ( vlayer && capabilities().testFlag( QgsMapToolCapture::Capability::SupportsCurves ) && vlayer->dataProvider()->capabilities().testFlag( QgsVectorDataProvider::Capability::CircularGeometries ) ) @@ -343,12 +346,20 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point ) mCaptureCurve = *qgsgeometry_cast( curved.constGet() ); } } - } - // sync the snapping matches list - const int pointAfter = mCaptureCurve.numPoints(); - for ( ; pointBefore < pointAfter; ++pointBefore ) - mSnappingMatches.append( QgsPointLocator::Match() ); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + // sync the snapping matches list + const int pointAfter = mCaptureCurve.numPoints(); + + for ( ; pointBefore < pointAfter; ++pointBefore ) + mSnappingMatches.append( QgsPointLocator::Match() ); + + for ( ; pointBefore > pointAfter; --pointBefore ) + mSnappingMatches.removeLast(); +#else + mSnappingMatches.resize( mCaptureCurve.numPoints() ); +#endif + } tracer->reportError( QgsTracer::ErrNone, true ); // clear messagebar if there was any error diff --git a/tests/src/app/testqgsmaptoolreshape.cpp b/tests/src/app/testqgsmaptoolreshape.cpp index 6306bfbe2e8a..caba1868fb13 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" @@ -47,6 +45,7 @@ class TestQgsMapToolReshape: public QObject void testReshapeZ(); void testTopologicalEditing(); void reshapeWithBindingLine(); + void testWithTracing(); private: QgisApp *mQgisApp = nullptr; @@ -319,6 +318,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"