Skip to content

Commit

Permalink
[BUGFIX] Fix snapping for middle of segment
Browse files Browse the repository at this point in the history
Refs #36850
  • Loading branch information
lbartoletti committed Dec 9, 2020
1 parent 80ea0f8 commit fc64cab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -457,7 +457,7 @@ int QgsMapToolCapture::fetchLayerPoint( const QgsPointLocator::Match &match, Qgs
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
QgsVectorLayer *sourceLayer = match.layer();
if ( match.isValid() && ( match.hasVertex() || ( QgsProject::instance()->topologicalEditing() && match.hasEdge() ) ) && sourceLayer &&
if ( match.isValid() && ( match.hasVertex() || ( QgsProject::instance()->topologicalEditing() && ( match.hasEdge() || match.hasMiddleSegment() ) ) ) && sourceLayer &&
( sourceLayer->crs() == vlayer->crs() ) )
{
QgsFeature f;
Expand All @@ -471,7 +471,7 @@ int QgsMapToolCapture::fetchLayerPoint( const QgsPointLocator::Match &match, Qgs
return 2;

const QgsGeometry geom( f.geometry() );
if ( QgsProject::instance()->topologicalEditing() && match.hasEdge() )
if ( QgsProject::instance()->topologicalEditing() && ( match.hasEdge() || match.hasMiddleSegment() ) )
{
QgsVertexId vId2;
if ( !f.geometry().vertexIdFromVertexNr( match.vertexIndex() + 1, vId2 ) )
Expand Down
33 changes: 32 additions & 1 deletion tests/src/app/testqgsmaptooladdfeatureline.cpp
Expand Up @@ -642,7 +642,38 @@ void TestQgsMapToolAddFeatureLine::testZMSnapping()

mLayerLine->undoStack()->undo();

cfg.setEnabled( false );

// Snap on middle Segment
mCanvas->setCurrentLayer( mLayerLineZ );
cfg.setTypeFlag( QgsSnappingConfig::MiddleOfSegmentFlag );
mCanvas->snappingUtils()->setConfig( cfg );

// create geometry will be snapped
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 123 );

oldFids = utils.existingFeatureIds();
utils.mouseClick( 20, 20, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseClick( 30, 20, Qt::LeftButton );
utils.mouseClick( 30, 20, Qt::RightButton );
newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry().get()->is3D(), true );
wkt = "LineStringZ (20 20 123, 30 20 123)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 321 );
oldFids = utils.existingFeatureIds();
utils.mouseClick( 25, 20, Qt::LeftButton, Qt::KeyboardModifiers(), true );
utils.mouseClick( 25, 25, Qt::LeftButton );
utils.mouseClick( 25, 25, Qt::RightButton );
newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry().get()->is3D(), true );
wkt = "LineStringZ (25 20 123, 25 25 321)";
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLineZ->undoStack()->undo();
mLayerLineZ->undoStack()->undo();

cfg.setEnabled( false );
mCanvas->snappingUtils()->setConfig( cfg );
Expand Down

0 comments on commit fc64cab

Please sign in to comment.