Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ReshapeMapTool] Fix snapping matches with tracing #58779

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/gui/maptools/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,17 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
mSnappingMatches.removeLast();
mSnappingMatches.append( QgsPointLocator::Match() );

int pointBefore = mCaptureCurve.numPoints();
addCurve( new QgsLineString( mapPoints ) );

resetRubberBand();

// 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<QgsVectorLayer *>( layer() );
if ( vlayer && capabilities().testFlag( QgsMapToolCapture::Capability::SupportsCurves ) && vlayer->dataProvider()->capabilities().testFlag( Qgis::VectorProviderCapability::CircularGeometries ) )
Expand All @@ -343,12 +346,20 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
mCaptureCurve = *qgsgeometry_cast<QgsCompoundCurve *>( 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

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"
Loading