Skip to content

Commit

Permalink
fix(ReshapeMapTool): fix snapping matches with tracing
Browse files Browse the repository at this point in the history
Fixes #57225
  • Loading branch information
troopa81 committed Sep 17, 2024
1 parent 2ef3cde commit c8f3f8f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/gui/maptools/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
37 changes: 34 additions & 3 deletions tests/src/app/testqgsmaptoolreshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand All @@ -48,6 +46,7 @@ class TestQgsMapToolReshape: public QObject
void testTopologicalEditing();
void testAvoidIntersectionAndTopoEdit();
void reshapeWithBindingLine();
void testWithTracing();

private:
QgisApp *mQgisApp = nullptr;
Expand Down Expand Up @@ -378,6 +377,38 @@ void TestQgsMapToolReshape::reshapeWithBindingLine()
vl->rollBack();
}

void TestQgsMapToolReshape::testWithTracing()
{
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerTopo );
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerTopo );

std::unique_ptr<QgsMapCanvasTracer> 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"

0 comments on commit c8f3f8f

Please sign in to comment.