Skip to content
Permalink
Browse files

Fix #12088 - selection tool - do not consider invisible features

This avoids dangerous situations where the user inadvertently selects features
that are not rendered and does further actions (like to delete them)
  • Loading branch information
wonder-sk committed Feb 19, 2015
1 parent 7f2fac1 commit ad86ffe18a85431fa16a6357457c0a081aa6a99b
Showing with 22 additions and 1 deletion.
  1. +22 −1 src/app/qgsmaptoolselectutils.cpp
@@ -22,6 +22,7 @@ email : jpalmer at linz dot govt dot nz
#include "qgsvectorlayer.h"
#include "qgsfeature.h"
#include "qgsgeometry.h"
#include "qgsrendererv2.h"
#include "qgsrubberband.h"
#include "qgscsexception.h"
#include "qgslogger.h"
@@ -135,7 +136,20 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
QgsDebugMsg( "doContains: " + QString( doContains ? "T" : "F" ) );
QgsDebugMsg( "doDifference: " + QString( doDifference ? "T" : "F" ) );

QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( selectGeomTrans.boundingBox() ).setFlags( QgsFeatureRequest::ExactIntersect ).setSubsetOfAttributes( QgsAttributeList() ) );
QgsRenderContext context = QgsRenderContext::fromMapSettings( canvas->mapSettings() );
QgsFeatureRendererV2* r = vlayer->rendererV2();
if ( r )
r->startRender( context, vlayer->pendingFields() );

QgsFeatureRequest request;
request.setFilterRect( selectGeomTrans.boundingBox() );
request.setFlags( QgsFeatureRequest::ExactIntersect );
if ( r )
request.setSubsetOfAttributes( r->usedAttributes(), vlayer->pendingFields() );
else
request.setSubsetOfAttributes( QgsAttributeList() );

QgsFeatureIterator fit = vlayer->getFeatures( request );

QgsFeatureIds newSelectedFeatures;
QgsFeature f;
@@ -144,6 +158,10 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
double closestFeatureDist = std::numeric_limits<double>::max();
while ( fit.nextFeature( f ) )
{
// make sure to only use features that are visible
if ( r && !r->willRenderFeature( f ) )
continue;

QgsGeometry* g = f.geometry();
if ( doContains )
{
@@ -175,6 +193,9 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
newSelectedFeatures.insert( closestFeatureId );
}

if ( r )
r->stopRender( context );

QgsDebugMsg( "Number of new selected features: " + QString::number( newSelectedFeatures.size() ) );

if ( doDifference )

1 comment on commit ad86ffe

@nirvn

This comment has been minimized.

Copy link
Contributor

nirvn commented on ad86ffe Feb 19, 2015

@wonder-sk , thanks for that!

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