Skip to content
Permalink
Browse files
fix #3246
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15004 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 7, 2011
1 parent 052dcb3 commit ba79bb2d7d3d814a46516c4f24eb6cf56bb1682c
Showing with 36 additions and 27 deletions.
  1. +12 −7 src/app/qgsmaptoolselectrectangle.cpp
  2. +24 −20 src/app/qgsmaptoolselectutils.cpp
@@ -89,13 +89,18 @@ void QgsMapToolSelectRectangle::canvasReleaseEvent( QMouseEvent * e )
}
}

QgsMapToolSelectUtils::setRubberBand( mCanvas, mSelectRect, mRubberBand );
QgsGeometry* selectGeom = mRubberBand->asGeometry();
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, e );
delete selectGeom;
if ( mRubberBand )
{
QgsMapToolSelectUtils::setRubberBand( mCanvas, mSelectRect, mRubberBand );

QgsGeometry* selectGeom = mRubberBand->asGeometry();
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, e );
delete selectGeom;

mRubberBand->reset( true );
delete mRubberBand;
mRubberBand = 0;
}

mRubberBand->reset( true );
delete mRubberBand;
mRubberBand = 0;
mDragging = false;
}
@@ -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 "
@@ -49,19 +49,23 @@ void QgsMapToolSelectUtils::setRubberBand( QgsMapCanvas* canvas, QRect& selectRe
const QgsMapToPixel* transform = canvas->getCoordinateTransform();
QgsPoint ll = transform->toMapCoordinates( selectRect.left(), selectRect.bottom() );
QgsPoint ur = transform->toMapCoordinates( selectRect.right(), selectRect.top() );
rubberBand->reset( true );
rubberBand->addPoint( ll, false );
rubberBand->addPoint( QgsPoint( ur.x(), ll.y() ), false );
rubberBand->addPoint( ur, false );
rubberBand->addPoint( QgsPoint( ll.x(), ur.y() ), true );

if ( rubberBand )
{
rubberBand->reset( true );
rubberBand->addPoint( ll, false );
rubberBand->addPoint( QgsPoint( ur.x(), ll.y() ), false );
rubberBand->addPoint( ur, false );
rubberBand->addPoint( QgsPoint( ll.x(), ur.y() ), true );
}
}

void QgsMapToolSelectUtils::expandSelectRectangle( QRect& selectRect,
QgsVectorLayer* vlayer,
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
@@ -84,12 +88,12 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
bool doDifference,
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;
}
@@ -100,14 +104,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
@@ -132,10 +136,10 @@ 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 )
if ( doContains )
{
if ( !selectGeomTrans.contains( g ) )
continue;
@@ -145,11 +149,11 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
if ( !selectGeomTrans.intersects( g ) )
continue;
}
if( singleSelect )
if ( singleSelect )
{
foundSingleFeature = true;
double distance = g->distance( selectGeomTrans );
if( distance <= closestFeatureDist )
if ( distance <= closestFeatureDist )
{
closestFeatureDist = distance;
closestFeatureId = f.id();
@@ -160,22 +164,22 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
newSelectedFeatures.insert( f.id() );
}
}
if( singleSelect && foundSingleFeature )
if ( singleSelect && foundSingleFeature )
{
newSelectedFeatures.insert( closestFeatureId );
}

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

QgsFeatureIds layerSelectedFeatures;
if( doDifference )
if ( doDifference )
{
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 );
}

0 comments on commit ba79bb2

Please sign in to comment.