@@ -178,7 +178,7 @@ static void _replaceIfBetter( QgsPointLocator::Match &bestMatch, const QgsPointL
178
178
}
179
179
180
180
181
- static void _updateBestMatch ( QgsPointLocator::Match &bestMatch, const QgsPointXY &pointMap, QgsPointLocator *loc, int type, double tolerance, QgsPointLocator::MatchFilter *filter )
181
+ static void _updateBestMatch ( QgsPointLocator::Match &bestMatch, const QgsPointXY &pointMap, QgsPointLocator *loc, QgsPointLocator::Types type, double tolerance, QgsPointLocator::MatchFilter *filter )
182
182
{
183
183
if ( type & QgsPointLocator::Vertex )
184
184
{
@@ -191,6 +191,23 @@ static void _updateBestMatch( QgsPointLocator::Match &bestMatch, const QgsPointX
191
191
}
192
192
193
193
194
+ static QgsPointLocator::Types _snappingTypeToPointLocatorType ( QgsSnappingConfig::SnappingType type )
195
+ {
196
+ // watch out: vertex+segment vs segment are in different order in the two enums
197
+ switch ( type )
198
+ {
199
+ case QgsSnappingConfig::Vertex:
200
+ return QgsPointLocator::Vertex;
201
+ case QgsSnappingConfig::VertexAndSegment:
202
+ return QgsPointLocator::Types ( QgsPointLocator::Vertex | QgsPointLocator::Edge );
203
+ case QgsSnappingConfig::Segment:
204
+ return QgsPointLocator::Edge;
205
+ default :
206
+ return QgsPointLocator::Invalid;
207
+ }
208
+ }
209
+
210
+
194
211
QgsPointLocator::Match QgsSnappingUtils::snapToMap ( QPoint point, QgsPointLocator::MatchFilter *filter )
195
212
{
196
213
return snapToMap ( mMapSettings .mapToPixel ().toMapCoordinates ( point ), filter );
@@ -216,7 +233,7 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
216
233
217
234
// data from project
218
235
double tolerance = QgsTolerance::toleranceInProjectUnits ( mSnappingConfig .tolerance (), mCurrentLayer , mMapSettings , mSnappingConfig .units () );
219
- int type = mSnappingConfig .type ();
236
+ QgsPointLocator::Types type = _snappingTypeToPointLocatorType ( mSnappingConfig .type () );
220
237
221
238
prepareIndex ( QList<LayerAndAreaOfInterest>() << qMakePair ( mCurrentLayer , _areaOfInterest ( pointMap, tolerance ) ) );
222
239
@@ -275,7 +292,7 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
275
292
{
276
293
// data from project
277
294
double tolerance = QgsTolerance::toleranceInProjectUnits ( mSnappingConfig .tolerance (), nullptr , mMapSettings , mSnappingConfig .units () );
278
- int type = mSnappingConfig .type ();
295
+ QgsPointLocator::Types type = _snappingTypeToPointLocatorType ( mSnappingConfig .type () );
279
296
QgsRectangle aoi = _areaOfInterest ( pointMap, tolerance );
280
297
281
298
QList<LayerAndAreaOfInterest> layers;
@@ -426,7 +443,7 @@ void QgsSnappingUtils::toggleEnabled()
426
443
emit configChanged ( mSnappingConfig );
427
444
}
428
445
429
- QgsPointLocator::Match QgsSnappingUtils::snapToCurrentLayer ( QPoint point, int type, QgsPointLocator::MatchFilter *filter )
446
+ QgsPointLocator::Match QgsSnappingUtils::snapToCurrentLayer ( QPoint point, QgsPointLocator::Types type, QgsPointLocator::MatchFilter *filter )
430
447
{
431
448
if ( !mCurrentLayer )
432
449
return QgsPointLocator::Match ();
@@ -478,14 +495,14 @@ QString QgsSnappingUtils::dump()
478
495
return msg;
479
496
}
480
497
481
- layers << LayerConfig ( mCurrentLayer , QgsPointLocator::Types ( mSnappingConfig .type () ), mSnappingConfig .tolerance (), mSnappingConfig .units () );
498
+ layers << LayerConfig ( mCurrentLayer , _snappingTypeToPointLocatorType ( mSnappingConfig .type () ), mSnappingConfig .tolerance (), mSnappingConfig .units () );
482
499
}
483
500
else if ( mSnappingConfig .mode () == QgsSnappingConfig::AllLayers )
484
501
{
485
502
Q_FOREACH ( QgsMapLayer *layer, mMapSettings .layers () )
486
503
{
487
504
if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
488
- layers << LayerConfig ( vl, QgsPointLocator::Types ( mSnappingConfig .type () ), mSnappingConfig .tolerance (), mSnappingConfig .units () );
505
+ layers << LayerConfig ( vl, _snappingTypeToPointLocatorType ( mSnappingConfig .type () ), mSnappingConfig .tolerance (), mSnappingConfig .units () );
489
506
}
490
507
}
491
508
else if ( mSnappingConfig .mode () == QgsSnappingConfig::AdvancedConfiguration )
@@ -554,13 +571,7 @@ void QgsSnappingUtils::onIndividualLayerSettingsChanged( const QHash<QgsVectorLa
554
571
{
555
572
if ( i->enabled () )
556
573
{
557
- QgsPointLocator::Types t ( i->type () == QgsSnappingConfig::Vertex ? QgsPointLocator::Vertex :
558
- ( i->type () == QgsSnappingConfig::Segment ? QgsPointLocator::Edge :
559
- QgsPointLocator::Vertex | QgsPointLocator::Edge
560
- )
561
- );
562
-
563
- mLayers .append ( LayerConfig ( i.key (), t, i->tolerance (), i->units () ) );
574
+ mLayers .append ( LayerConfig ( i.key (), _snappingTypeToPointLocatorType ( i->type () ), i->tolerance (), i->units () ) );
564
575
}
565
576
}
566
577
}
0 commit comments