Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][BUGFIX][FEATURE][NEEDS-DOCS] Disable snapping on invisible features #6657

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions src/core/qgssnappingutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgslogger.h"
#include "qgsrenderer.h"

QgsSnappingUtils::QgsSnappingUtils( QObject *parent )
: QObject( parent )
Expand Down Expand Up @@ -92,6 +93,35 @@ bool QgsSnappingUtils::isIndexPrepared( QgsVectorLayer *vl, const QgsRectangle &
return ( mStrategy == IndexHybrid || mStrategy == IndexExtent ) && loc->hasIndex() && ( !loc->extent() || loc->extent()->contains( aoi ) ); // the index - even if it exists - is not suitable
}

static bool _isMatchAVisibleLayer( const QgsPointLocator::Match &candidateMatch )
{
bool visible = true;

// segmentIntersection haven't a layer
if ( candidateMatch.layer() )
{
visible = false;
QgsFeatureRequest request;
QString filterExpression( candidateMatch.layer()->renderer()->filter() );
if ( filterExpression.length() > 0 )
request.setFilterExpression( filterExpression );
else
request.setSubsetOfAttributes( QgsAttributeList() );

QgsFeatureIterator fi = candidateMatch.layer()->getFeatures( request );

QgsFeature f;
while ( fi.nextFeature( f ) )
{
if ( f.id() == candidateMatch.featureId() )
{
visible = true;
break;
}
}
}
return visible;
}

static QgsPointLocator::Match _findClosestSegmentIntersection( const QgsPointXY &pt, const QgsPointLocator::MatchList &segments )
{
Expand All @@ -104,7 +134,7 @@ static QgsPointLocator::Match _findClosestSegmentIntersection( const QgsPointXY
QVector<QgsGeometry> geoms;
Q_FOREACH ( const QgsPointLocator::Match &m, segments )
{
if ( m.hasEdge() )
if ( m.hasEdge() && _isMatchAVisibleLayer( m ) )
{
QgsPolylineXY pl( 2 );
m.edgePoints( pl[0], pl[1] );
Expand Down Expand Up @@ -156,9 +186,9 @@ static QgsPointLocator::Match _findClosestSegmentIntersection( const QgsPointXY
return QgsPointLocator::Match( QgsPointLocator::Vertex, nullptr, 0, std::sqrt( minSqrDist ), minP );
}


static void _replaceIfBetter( QgsPointLocator::Match &bestMatch, const QgsPointLocator::Match &candidateMatch, double maxDistance )
{

// is candidate match relevant?
if ( !candidateMatch.isValid() || candidateMatch.distance() > maxDistance )
return;
Expand All @@ -171,10 +201,12 @@ static void _replaceIfBetter( QgsPointLocator::Match &bestMatch, const QgsPointL
if ( bestMatch.type() == QgsPointLocator::Vertex && candidateMatch.type() == QgsPointLocator::Edge )
return;

if ( !_isMatchAVisibleLayer( candidateMatch ) )
return;

bestMatch = candidateMatch; // the other match is better!
}


static void _updateBestMatch( QgsPointLocator::Match &bestMatch, const QgsPointXY &pointMap, QgsPointLocator *loc, QgsPointLocator::Types type, double tolerance, QgsPointLocator::MatchFilter *filter )
{
if ( type & QgsPointLocator::Vertex )
Expand Down