Navigation Menu

Skip to content

Commit

Permalink
Reverse alt-key modification to be compatible with the old selection …
Browse files Browse the repository at this point in the history
…tool

git-svn-id: http://svn.osgeo.org/qgis/trunk@14476 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 1, 2010
1 parent ce3c837 commit b92c899
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/app/qgsmaptoolselectutils.cpp
Expand Up @@ -33,8 +33,8 @@ email : jpalmer at linz dot govt dot nz
QgsVectorLayer* QgsMapToolSelectUtils::getCurrentVectorLayer( QgsMapCanvas* canvas )
{
QgsVectorLayer* vlayer = NULL;
if ( !canvas->currentLayer()
|| ( vlayer = qobject_cast<QgsVectorLayer *>( canvas->currentLayer() ) ) == NULL )
if( !canvas->currentLayer()
|| ( vlayer = qobject_cast<QgsVectorLayer *>( canvas->currentLayer() ) ) == NULL )
{
QMessageBox::warning( canvas, QObject::tr( "No active vector layer" ),
QObject::tr( "To select features, you must choose a "
Expand All @@ -61,7 +61,7 @@ void QgsMapToolSelectUtils::expandSelectRectangle( QRect& selectRect,
QPoint point )
{
int boxSize = 0;
if ( vlayer->geometryType() != QGis::Polygon )
if( vlayer->geometryType() != QGis::Polygon )
{
//if point or line use an artificial bounding box of 10x10 pixels
//to aid the user to click on a feature accurately
Expand All @@ -85,12 +85,12 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
bool substractSelection,
bool singleSelect )
{
if ( selectGeometry->type() != QGis::Polygon )
if( selectGeometry->type() != QGis::Polygon )
{
return;
}
QgsVectorLayer* vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( canvas );
if ( vlayer == NULL )
if( vlayer == NULL )
{
return;
}
Expand All @@ -101,14 +101,14 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
// and then click somewhere off the globe, an exception will be thrown.
QgsGeometry selectGeomTrans( *selectGeometry );

if ( canvas->mapRenderer()->hasCrsTransformEnabled() )
if( canvas->mapRenderer()->hasCrsTransformEnabled() )
{
try
{
QgsCoordinateTransform ct( canvas->mapRenderer()->destinationSrs(), vlayer->crs() );
selectGeomTrans.transform( ct );
}
catch ( QgsCsException &cse )
catch( QgsCsException &cse )
{
Q_UNUSED( cse );
// catch exception for 'invalid' point and leave existing selection unchanged
Expand All @@ -134,18 +134,18 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
int closestFeatureId = 0;
bool foundSingleFeature = false;
double closestFeatureDist = std::numeric_limits<double>::max();
while ( vlayer->nextFeature( f ) )
while( vlayer->nextFeature( f ) )
{
QgsGeometry* g = f.geometry();
if ( doContains && !selectGeomTrans.contains( g ) )
if( doContains && !selectGeomTrans.contains( g ) )
{
continue;
}
if ( singleSelect )
if( singleSelect )
{
foundSingleFeature = true;
double distance = g->distance( selectGeomTrans );
if ( distance <= closestFeatureDist )
if( distance <= closestFeatureDist )
{
closestFeatureDist = distance;
closestFeatureId = f.id();
Expand All @@ -156,32 +156,32 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
newSelectedFeatures.insert( f.id() );
}
}
if ( singleSelect && foundSingleFeature )
if( singleSelect && foundSingleFeature )
{
newSelectedFeatures.insert( closestFeatureId );
}

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

QgsFeatureIds layerSelectedFeatures;
if ( addSelection )
if( addSelection )
{
layerSelectedFeatures = vlayer->selectedFeaturesIds();
QgsFeatureIds::const_iterator i = newSelectedFeatures.constEnd();
while ( i != newSelectedFeatures.constBegin() )
while( i != newSelectedFeatures.constBegin() )
{
--i;
layerSelectedFeatures.insert( *i );
}
}
else if ( substractSelection )
else if( substractSelection )
{
layerSelectedFeatures = vlayer->selectedFeaturesIds();
QgsFeatureIds::const_iterator i = newSelectedFeatures.constEnd();
while ( i != newSelectedFeatures.constBegin() )
while( i != newSelectedFeatures.constBegin() )
{
--i;
if ( layerSelectedFeatures.contains( *i ) )
if( layerSelectedFeatures.contains( *i ) )
{
layerSelectedFeatures.remove( *i );
}
Expand All @@ -198,7 +198,7 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,

void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas, QgsGeometry* selectGeometry, QMouseEvent * e )
{
bool doContains = e->modifiers() & Qt::AltModifier ? false : true;
bool doContains = e->modifiers() & Qt::AltModifier ? true : false;
bool addSelection = e->modifiers() & Qt::ControlModifier ? true : false;
bool substractSelection = e->modifiers() & Qt::ShiftModifier ? true : false;
setSelectFeatures( canvas, selectGeometry, doContains, addSelection, substractSelection );
Expand Down

0 comments on commit b92c899

Please sign in to comment.