Skip to content
Permalink
Browse files

Update vertex tool to base its snapping parameters on global ones

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
  • Loading branch information
obrix committed Jun 4, 2020
1 parent f68f730 commit 537a2478d10edac12b955e322310bbe1cd30cbe2
Showing with 38 additions and 7 deletions.
  1. +37 −6 src/app/vertextool/qgsvertextool.cpp
  2. +1 −1 src/core/qgssnappingutils.cpp
@@ -748,11 +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
Q_ASSERT( config.individualLayerSettings().isEmpty() );
config.individualLayerSettings().clear();

typedef QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> SettingsHashMap;
SettingsHashMap oldLayerSettings = oldConfig.individualLayerSettings();

// 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
@@ -768,8 +771,23 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e )
if ( !vlayer )
continue;

config.setIndividualLayerSettings( vlayer, QgsSnappingConfig::IndividualLayerSettings(
vlayer == currentVlayer, static_cast<QgsSnappingConfig::SnappingTypeFlag>( 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 );
layerSettings.setTolerance( tol );
layerSettings.setTypeFlag( static_cast<QgsSnappingConfig::SnappingTypeFlag>( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ) );
layerSettings.setUnits( QgsTolerance::ProjectUnits );
}
else
{
layerSettings = QgsSnappingConfig::IndividualLayerSettings(
vlayer == currentVlayer, static_cast<QgsSnappingConfig::SnappingTypeFlag>( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ), tol, QgsTolerance::ProjectUnits, 0.0, 0.0 );
}

config.setIndividualLayerSettings( vlayer, layerSettings );
}

snapUtils->setConfig( config );
@@ -795,8 +813,21 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e )
if ( !vlayer )
continue;

config.setIndividualLayerSettings( vlayer, QgsSnappingConfig::IndividualLayerSettings(
vlayer->isEditable(), static_cast<QgsSnappingConfig::SnappingTypeFlag>( 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() );
layerSettings.setTolerance( tol );
layerSettings.setTypeFlag( static_cast<QgsSnappingConfig::SnappingTypeFlag>( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ) );
layerSettings.setUnits( QgsTolerance::ProjectUnits );
}
else
{
layerSettings = QgsSnappingConfig::IndividualLayerSettings( vlayer->isEditable(), static_cast<QgsSnappingConfig::SnappingTypeFlag>( QgsSnappingConfig::VertexFlag | QgsSnappingConfig::SegmentFlag ), tol, QgsTolerance::ProjectUnits, 0.0, 0.0 );
}
config.setIndividualLayerSettings( vlayer, layerSettings );
}

snapUtils->setConfig( config );
@@ -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 );

0 comments on commit 537a247

Please sign in to comment.
You can’t perform that action at this time.