@@ -178,7 +178,7 @@ static void _replaceIfBetter( QgsPointLocator::Match &bestMatch, const QgsPointL
}
static void _updateBestMatch ( QgsPointLocator::Match &bestMatch, const QgsPointXY &pointMap, QgsPointLocator *loc, int type, double tolerance, QgsPointLocator::MatchFilter *filter )
static void _updateBestMatch ( QgsPointLocator::Match &bestMatch, const QgsPointXY &pointMap, QgsPointLocator *loc, QgsPointLocator::Types type, double tolerance, QgsPointLocator::MatchFilter *filter )
{
if ( type & QgsPointLocator::Vertex )
{
@@ -191,6 +191,23 @@ static void _updateBestMatch( QgsPointLocator::Match &bestMatch, const QgsPointX
}
static QgsPointLocator::Types _snappingTypeToPointLocatorType ( QgsSnappingConfig::SnappingType type )
{
// watch out: vertex+segment vs segment are in different order in the two enums
switch ( type )
{
case QgsSnappingConfig::Vertex:
return QgsPointLocator::Vertex;
case QgsSnappingConfig::VertexAndSegment:
return QgsPointLocator::Types ( QgsPointLocator::Vertex | QgsPointLocator::Edge );
case QgsSnappingConfig::Segment:
return QgsPointLocator::Edge;
default :
return QgsPointLocator::Invalid;
}
}
QgsPointLocator::Match QgsSnappingUtils::snapToMap ( QPoint point, QgsPointLocator::MatchFilter *filter )
{
return snapToMap ( mMapSettings .mapToPixel ().toMapCoordinates ( point ), filter );
@@ -216,7 +233,7 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
// data from project
double tolerance = QgsTolerance::toleranceInProjectUnits ( mSnappingConfig .tolerance (), mCurrentLayer , mMapSettings , mSnappingConfig .units () );
int type = mSnappingConfig .type ();
QgsPointLocator::Types type = _snappingTypeToPointLocatorType ( mSnappingConfig .type () );
prepareIndex ( QList<LayerAndAreaOfInterest>() << qMakePair ( mCurrentLayer , _areaOfInterest ( pointMap, tolerance ) ) );
@@ -275,7 +292,7 @@ QgsPointLocator::Match QgsSnappingUtils::snapToMap( const QgsPointXY &pointMap,
{
// data from project
double tolerance = QgsTolerance::toleranceInProjectUnits ( mSnappingConfig .tolerance (), nullptr , mMapSettings , mSnappingConfig .units () );
int type = mSnappingConfig .type ();
QgsPointLocator::Types type = _snappingTypeToPointLocatorType ( mSnappingConfig .type () );
QgsRectangle aoi = _areaOfInterest ( pointMap, tolerance );
QList<LayerAndAreaOfInterest> layers;
@@ -426,7 +443,7 @@ void QgsSnappingUtils::toggleEnabled()
emit configChanged ( mSnappingConfig );
}
QgsPointLocator::Match QgsSnappingUtils::snapToCurrentLayer ( QPoint point, int type, QgsPointLocator::MatchFilter *filter )
QgsPointLocator::Match QgsSnappingUtils::snapToCurrentLayer ( QPoint point, QgsPointLocator::Types type, QgsPointLocator::MatchFilter *filter )
{
if ( !mCurrentLayer )
return QgsPointLocator::Match ();
@@ -478,14 +495,14 @@ QString QgsSnappingUtils::dump()
return msg;
}
layers << LayerConfig ( mCurrentLayer , QgsPointLocator::Types ( mSnappingConfig .type () ), mSnappingConfig .tolerance (), mSnappingConfig .units () );
layers << LayerConfig ( mCurrentLayer , _snappingTypeToPointLocatorType ( mSnappingConfig .type () ), mSnappingConfig .tolerance (), mSnappingConfig .units () );
}
else if ( mSnappingConfig .mode () == QgsSnappingConfig::AllLayers )
{
Q_FOREACH ( QgsMapLayer *layer, mMapSettings .layers () )
{
if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer ) )
layers << LayerConfig ( vl, QgsPointLocator::Types ( mSnappingConfig .type () ), mSnappingConfig .tolerance (), mSnappingConfig .units () );
layers << LayerConfig ( vl, _snappingTypeToPointLocatorType ( mSnappingConfig .type () ), mSnappingConfig .tolerance (), mSnappingConfig .units () );
}
}
else if ( mSnappingConfig .mode () == QgsSnappingConfig::AdvancedConfiguration )
@@ -554,13 +571,7 @@ void QgsSnappingUtils::onIndividualLayerSettingsChanged( const QHash<QgsVectorLa
{
if ( i->enabled () )
{
QgsPointLocator::Types t ( i->type () == QgsSnappingConfig::Vertex ? QgsPointLocator::Vertex :
( i->type () == QgsSnappingConfig::Segment ? QgsPointLocator::Edge :
QgsPointLocator::Vertex | QgsPointLocator::Edge
)
);
mLayers .append ( LayerConfig ( i.key (), t, i->tolerance (), i->units () ) );
mLayers .append ( LayerConfig ( i.key (), _snappingTypeToPointLocatorType ( i->type () ), i->tolerance (), i->units () ) );
}
}
}