Skip to content

Commit 220b58d

Browse files
committedSep 12, 2017
Fix vertex+segment vs segment snapping type
When user picked snapping to current layer / all layers, snapping to vertex+segment vs segment were working the other way around (advanced configuration was working correctly though)
1 parent 88c8c71 commit 220b58d

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed
 

‎python/core/qgssnappingutils.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Snap to map according to the current configuration. Optional filter allows disca
5454
:rtype: QgsPointLocator.Match
5555
%End
5656

57-
QgsPointLocator::Match snapToCurrentLayer( QPoint point, int type, QgsPointLocator::MatchFilter *filter = 0 );
57+
QgsPointLocator::Match snapToCurrentLayer( QPoint point, QgsPointLocator::Types type, QgsPointLocator::MatchFilter *filter = 0 );
5858
%Docstring
5959
Snap to current layer
6060
:rtype: QgsPointLocator.Match

‎src/app/qgsmaptooldeletepart.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ QgsGeometry QgsMapToolDeletePart::partUnderPoint( QPoint point, QgsFeatureId &fi
125125
case QgsWkbTypes::PointGeometry:
126126
case QgsWkbTypes::LineGeometry:
127127
{
128-
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToCurrentLayer( point, QgsPointLocator::Vertex | QgsPointLocator::Edge );
128+
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToCurrentLayer( point, QgsPointLocator::Types( QgsPointLocator::Vertex | QgsPointLocator::Edge ) );
129129
if ( !match.isValid() )
130130
return geomPart;
131131

‎src/core/qgssnappingutils.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void _replaceIfBetter( QgsPointLocator::Match &bestMatch, const QgsPointL
178178
}
179179

180180

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 )
182182
{
183183
if ( type & QgsPointLocator::Vertex )
184184
{
@@ -191,6 +191,23 @@ static void _updateBestMatch( QgsPointLocator::Match &bestMatch, const QgsPointX
191191
}
192192

193193

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+
194211
QgsPointLocator::Match QgsSnappingUtils::snapToMap( QPoint point, QgsPointLocator::MatchFilter *filter )
195212
{
196213
return snapToMap( mMapSettings.mapToPixel().toMapCoordinates( point ), filter );
@@ -216,7 +233,7 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
216233

217234
// data from project
218235
double tolerance = QgsTolerance::toleranceInProjectUnits( mSnappingConfig.tolerance(), mCurrentLayer, mMapSettings, mSnappingConfig.units() );
219-
int type = mSnappingConfig.type();
236+
QgsPointLocator::Types type = _snappingTypeToPointLocatorType( mSnappingConfig.type() );
220237

221238
prepareIndex( QList<LayerAndAreaOfInterest>() << qMakePair( mCurrentLayer, _areaOfInterest( pointMap, tolerance ) ) );
222239

@@ -275,7 +292,7 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
275292
{
276293
// data from project
277294
double tolerance = QgsTolerance::toleranceInProjectUnits( mSnappingConfig.tolerance(), nullptr, mMapSettings, mSnappingConfig.units() );
278-
int type = mSnappingConfig.type();
295+
QgsPointLocator::Types type = _snappingTypeToPointLocatorType( mSnappingConfig.type() );
279296
QgsRectangle aoi = _areaOfInterest( pointMap, tolerance );
280297

281298
QList<LayerAndAreaOfInterest> layers;
@@ -426,7 +443,7 @@ void QgsSnappingUtils::toggleEnabled()
426443
emit configChanged( mSnappingConfig );
427444
}
428445

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 )
430447
{
431448
if ( !mCurrentLayer )
432449
return QgsPointLocator::Match();
@@ -478,14 +495,14 @@ QString QgsSnappingUtils::dump()
478495
return msg;
479496
}
480497

481-
layers << LayerConfig( mCurrentLayer, QgsPointLocator::Types( mSnappingConfig.type() ), mSnappingConfig.tolerance(), mSnappingConfig.units() );
498+
layers << LayerConfig( mCurrentLayer, _snappingTypeToPointLocatorType( mSnappingConfig.type() ), mSnappingConfig.tolerance(), mSnappingConfig.units() );
482499
}
483500
else if ( mSnappingConfig.mode() == QgsSnappingConfig::AllLayers )
484501
{
485502
Q_FOREACH ( QgsMapLayer *layer, mMapSettings.layers() )
486503
{
487504
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() );
489506
}
490507
}
491508
else if ( mSnappingConfig.mode() == QgsSnappingConfig::AdvancedConfiguration )
@@ -554,13 +571,7 @@ void QgsSnappingUtils::onIndividualLayerSettingsChanged( const QHash<QgsVectorLa
554571
{
555572
if ( i->enabled() )
556573
{
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() ) );
564575
}
565576
}
566577
}

‎src/core/qgssnappingutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CORE_EXPORT QgsSnappingUtils : public QObject
6363
QgsPointLocator::Match snapToMap( const QgsPointXY &pointMap, QgsPointLocator::MatchFilter *filter = nullptr );
6464

6565
//! Snap to current layer
66-
QgsPointLocator::Match snapToCurrentLayer( QPoint point, int type, QgsPointLocator::MatchFilter *filter = nullptr );
66+
QgsPointLocator::Match snapToCurrentLayer( QPoint point, QgsPointLocator::Types type, QgsPointLocator::MatchFilter *filter = nullptr );
6767

6868
// environment setup
6969

0 commit comments

Comments
 (0)
Please sign in to comment.