From 79fa9dc40bb8b5bc1c58f0f24ee9166e9d4cf438 Mon Sep 17 00:00:00 2001 From: obrix Date: Wed, 6 May 2020 11:03:53 +0200 Subject: [PATCH 1/3] Update vertex tool to not override some of the global snapping parameters (especially snapping enabled on a scale range). Keep some of the specific behavior which is there for a reason (ie creation of of specific layer settings, now based on the existing one if present). Should fix #36229 --- src/app/vertextool/qgsvertextool.cpp | 36 ++++++++++++++++++++++++---- src/core/qgssnappingutils.cpp | 2 +- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/app/vertextool/qgsvertextool.cpp b/src/app/vertextool/qgsvertextool.cpp index 407cf6bb97af..5ca0bf335633 100644 --- a/src/app/vertextool/qgsvertextool.cpp +++ b/src/app/vertextool/qgsvertextool.cpp @@ -752,6 +752,12 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e ) config.setEnabled( true ); config.setMode( QgsSnappingConfig::AdvancedConfiguration ); config.setIntersectionSnapping( false ); // only snap to layers + config.setScaleDependencyMode( oldConfig.scaleDependencyMode() ); + config.setMinimumScale( oldConfig.minimumScale() ); + config.setMaximumScale( oldConfig.maximumScale() ); + + typedef QHash SettingsHashMap; + SettingsHashMap oldLayerSettings = oldConfig.individualLayerSettings(); Q_ASSERT( config.individualLayerSettings().isEmpty() ); // if there is a current layer, it should have priority over other layers @@ -768,8 +774,20 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e ) if ( !vlayer ) continue; - config.setIndividualLayerSettings( vlayer, QgsSnappingConfig::IndividualLayerSettings( - vlayer == currentVlayer, static_cast( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ), tol, QgsTolerance::ProjectUnits, 0.0, 0.0 ) ); + QgsSnappingConfig::IndividualLayerSettings layerSettings; + SettingsHashMap::const_iterator existingSettings = oldLayerSettings.find( vlayer ); + if ( existingSettings != oldLayerSettings.constEnd() ) + { + layerSettings = existingSettings.value(); + layerSettings.setEnabled( vlayer == currentVlayer ); + } + else + { + layerSettings = QgsSnappingConfig::IndividualLayerSettings( + vlayer == currentVlayer, static_cast( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ), tol, QgsTolerance::ProjectUnits, 0.0, 0.0 ); + } + + config.setIndividualLayerSettings( vlayer, layerSettings ); } snapUtils->setConfig( config ); @@ -795,8 +813,18 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e ) if ( !vlayer ) continue; - config.setIndividualLayerSettings( vlayer, QgsSnappingConfig::IndividualLayerSettings( - vlayer->isEditable(), static_cast( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ), tol, QgsTolerance::ProjectUnits, 0.0, 0.0 ) ); + QgsSnappingConfig::IndividualLayerSettings layerSettings; + SettingsHashMap::const_iterator existingSettings = oldLayerSettings.find( vlayer ); + if ( existingSettings != oldLayerSettings.constEnd() ) + { + layerSettings = existingSettings.value(); + layerSettings.setEnabled( vlayer->isEditable() ); + } + else + { + config.setIndividualLayerSettings( vlayer, QgsSnappingConfig::IndividualLayerSettings( + vlayer->isEditable(), static_cast( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ), tol, QgsTolerance::ProjectUnits, 0.0, 0.0 ) ); + } } snapUtils->setConfig( config ); diff --git a/src/core/qgssnappingutils.cpp b/src/core/qgssnappingutils.cpp index 0dd8be67a3ac..aaac15b32cbc 100644 --- a/src/core/qgssnappingutils.cpp +++ b/src/core/qgssnappingutils.cpp @@ -94,7 +94,7 @@ bool QgsSnappingUtils::isIndexPrepared( QgsPointLocator *loc, const QgsRectangle if ( mStrategy == IndexAlwaysFull && loc->hasIndex() ) return true; - if ( mStrategy == IndexExtent && loc->hasIndex() && loc->extent()->intersects( areaOfInterest ) ) + if ( mStrategy == IndexExtent && loc->hasIndex() && ( !loc->extent() || loc->extent()->intersects( areaOfInterest ) ) ) return true; QgsRectangle aoi( areaOfInterest ); From a367bce4e25e31ae9c8b4da6f23b3377dd2d6b1e Mon Sep 17 00:00:00 2001 From: obrix Date: Wed, 6 May 2020 12:34:02 +0200 Subject: [PATCH 2/3] Fix vertextool test : Specific tolerance, units and typeflag are mandatory. --- src/app/vertextool/qgsvertextool.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app/vertextool/qgsvertextool.cpp b/src/app/vertextool/qgsvertextool.cpp index 5ca0bf335633..ac8db14b8412 100644 --- a/src/app/vertextool/qgsvertextool.cpp +++ b/src/app/vertextool/qgsvertextool.cpp @@ -780,6 +780,9 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e ) { layerSettings = existingSettings.value(); layerSettings.setEnabled( vlayer == currentVlayer ); + layerSettings.setTolerance( tol ); + layerSettings.setTypeFlag( static_cast( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ) ); + layerSettings.setUnits( QgsTolerance::ProjectUnits ); } else { @@ -819,12 +822,15 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e ) { layerSettings = existingSettings.value(); layerSettings.setEnabled( vlayer->isEditable() ); + layerSettings.setTolerance( tol ); + layerSettings.setTypeFlag( static_cast( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ) ); + layerSettings.setUnits( QgsTolerance::ProjectUnits ); } else { - config.setIndividualLayerSettings( vlayer, QgsSnappingConfig::IndividualLayerSettings( - vlayer->isEditable(), static_cast( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ), tol, QgsTolerance::ProjectUnits, 0.0, 0.0 ) ); + layerSettings = QgsSnappingConfig::IndividualLayerSettings( vlayer->isEditable(), static_cast( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ), tol, QgsTolerance::ProjectUnits, 0.0, 0.0 ); } + config.setIndividualLayerSettings( vlayer, layerSettings ); } snapUtils->setConfig( config ); From d21b743368711a07e0245df11c5798213bdfa423 Mon Sep 17 00:00:00 2001 From: obrix Date: Tue, 12 May 2020 12:05:39 +0200 Subject: [PATCH 3/3] Initialize vertex tool snapping config with old config. --- src/app/vertextool/qgsvertextool.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/app/vertextool/qgsvertextool.cpp b/src/app/vertextool/qgsvertextool.cpp index ac8db14b8412..6a958ea7a852 100644 --- a/src/app/vertextool/qgsvertextool.cpp +++ b/src/app/vertextool/qgsvertextool.cpp @@ -748,17 +748,14 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e ) QgsPointXY mapPoint = toMapCoordinates( e->pos() ); double tol = QgsTolerance::vertexSearchRadius( canvas()->mapSettings() ); - QgsSnappingConfig config; + QgsSnappingConfig config = oldConfig; config.setEnabled( true ); config.setMode( QgsSnappingConfig::AdvancedConfiguration ); config.setIntersectionSnapping( false ); // only snap to layers - config.setScaleDependencyMode( oldConfig.scaleDependencyMode() ); - config.setMinimumScale( oldConfig.minimumScale() ); - config.setMaximumScale( oldConfig.maximumScale() ); + config.individualLayerSettings().clear(); typedef QHash SettingsHashMap; SettingsHashMap oldLayerSettings = oldConfig.individualLayerSettings(); - Q_ASSERT( config.individualLayerSettings().isEmpty() ); // if there is a current layer, it should have priority over other layers // because sometimes there may be match from multiple layers at one location