Apply non-string parts of patch #2938

git-svn-id: http://svn.osgeo.org/qgis/trunk@14497 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2010-11-03 11:57:34 +00:00
parent ca8eebe6a5
commit 485ae1921f
3 changed files with 18 additions and 31 deletions

View File

@ -29,7 +29,7 @@
QgsMapToolSelect::QgsMapToolSelect( QgsMapCanvas* canvas ) QgsMapToolSelect::QgsMapToolSelect( QgsMapCanvas* canvas )
: QgsMapTool( canvas ) : QgsMapTool( canvas )
{ {
mCursor = Qt::ArrowCursor; mCursor = Qt::ArrowCursor;
} }
@ -37,7 +37,7 @@ QgsMapToolSelect::QgsMapToolSelect( QgsMapCanvas* canvas )
void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e ) void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )
{ {
QgsVectorLayer* vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( mCanvas ); QgsVectorLayer* vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( mCanvas );
if ( vlayer == NULL ) if( vlayer == NULL )
{ {
return; return;
} }
@ -46,9 +46,8 @@ void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )
QgsMapToolSelectUtils::expandSelectRectangle( selectRect, vlayer, e->pos() ); QgsMapToolSelectUtils::expandSelectRectangle( selectRect, vlayer, e->pos() );
QgsMapToolSelectUtils::setRubberBand( mCanvas, selectRect, &rubberBand ); QgsMapToolSelectUtils::setRubberBand( mCanvas, selectRect, &rubberBand );
QgsGeometry* selectGeom = rubberBand.asGeometry(); QgsGeometry* selectGeom = rubberBand.asGeometry();
bool addSelection = e->modifiers() & Qt::ControlModifier ? true : false; bool doDifference = e->modifiers() & Qt::ControlModifier ? true : false;
bool substractSelection = e->modifiers() & Qt::ShiftModifier ? true : false; QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, false, doDifference, true );
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, false, addSelection, substractSelection, true );
delete selectGeom; delete selectGeom;
rubberBand.reset( true ); rubberBand.reset( true );
} }

View File

@ -81,8 +81,7 @@ void QgsMapToolSelectUtils::expandSelectRectangle( QRect& selectRect,
void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas, void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
QgsGeometry* selectGeometry, QgsGeometry* selectGeometry,
bool doContains, bool doContains,
bool addSelection, bool doDifference,
bool substractSelection,
bool singleSelect ) bool singleSelect )
{ {
if( selectGeometry->type() != QGis::Polygon ) if( selectGeometry->type() != QGis::Polygon )
@ -124,8 +123,7 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
QgsDebugMsg( "Selection layer: " + vlayer->name() ); QgsDebugMsg( "Selection layer: " + vlayer->name() );
QgsDebugMsg( "Selection polygon: " + selectGeomTrans.exportToWkt() ); QgsDebugMsg( "Selection polygon: " + selectGeomTrans.exportToWkt() );
QgsDebugMsg( "doContains: " + QString( doContains ? "T" : "F" ) ); QgsDebugMsg( "doContains: " + QString( doContains ? "T" : "F" ) );
QgsDebugMsg( "addSelection: " + QString( addSelection ? "T" : "F" ) ); QgsDebugMsg( "doDifference: " + QString( doDifference ? "T" : "F" ) );
QgsDebugMsg( "substractSelection: " + QString( substractSelection ? "T" : "F" ) );
vlayer->select( QgsAttributeList(), selectGeomTrans.boundingBox(), true, true ); vlayer->select( QgsAttributeList(), selectGeomTrans.boundingBox(), true, true );
@ -161,20 +159,10 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
newSelectedFeatures.insert( closestFeatureId ); newSelectedFeatures.insert( closestFeatureId );
} }
QgsDebugMsg( "Number of selected features: " + QString::number( newSelectedFeatures.size() ) ); QgsDebugMsg( "Number of new selected features: " + QString::number( newSelectedFeatures.size() ) );
QgsFeatureIds layerSelectedFeatures; QgsFeatureIds layerSelectedFeatures;
if( addSelection ) if( doDifference )
{
layerSelectedFeatures = vlayer->selectedFeaturesIds();
QgsFeatureIds::const_iterator i = newSelectedFeatures.constEnd();
while( i != newSelectedFeatures.constBegin() )
{
--i;
layerSelectedFeatures.insert( *i );
}
}
else if( substractSelection )
{ {
layerSelectedFeatures = vlayer->selectedFeaturesIds(); layerSelectedFeatures = vlayer->selectedFeaturesIds();
QgsFeatureIds::const_iterator i = newSelectedFeatures.constEnd(); QgsFeatureIds::const_iterator i = newSelectedFeatures.constEnd();
@ -185,6 +173,10 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
{ {
layerSelectedFeatures.remove( *i ); layerSelectedFeatures.remove( *i );
} }
else
{
layerSelectedFeatures.insert( *i );
}
} }
} }
else else
@ -198,8 +190,7 @@ void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas,
void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas, QgsGeometry* selectGeometry, QMouseEvent * e ) void QgsMapToolSelectUtils::setSelectFeatures( QgsMapCanvas* canvas, QgsGeometry* selectGeometry, QMouseEvent * e )
{ {
bool doContains = e->modifiers() & Qt::AltModifier ? true : false; bool doContains = e->modifiers() & Qt::ShiftModifier ? true : false;
bool addSelection = e->modifiers() & Qt::ControlModifier ? true : false; bool doDifference = e->modifiers() & Qt::ControlModifier ? true : false;
bool substractSelection = e->modifiers() & Qt::ShiftModifier ? true : false; setSelectFeatures( canvas, selectGeometry, doContains, doDifference );
setSelectFeatures( canvas, selectGeometry, doContains, addSelection, substractSelection );
} }

View File

@ -40,17 +40,14 @@ namespace QgsMapToolSelectUtils
must be in terms of the canvas coordinate system. must be in terms of the canvas coordinate system.
@param doContains Features will only be selected if contained within the @param doContains Features will only be selected if contained within the
selection rubber band. selection rubber band.
@param addSelection New selected features will be added to the layer's @param doDifference Take the symmetric difference of the the current selected
currently selected features. features and the new features found within the provided selectGeometry.
@param substractSelection New selected features will be subtracted from
the layer's currently selected features.
@param singleSelect Only selects the closest feature to the selectGeometry. @param singleSelect Only selects the closest feature to the selectGeometry.
*/ */
void setSelectFeatures( QgsMapCanvas* canvas, void setSelectFeatures( QgsMapCanvas* canvas,
QgsGeometry* selectGeometry, QgsGeometry* selectGeometry,
bool doContains = true, bool doContains = true,
bool addSelection = false, bool doDifference = false,
bool substractSelection = false,
bool singleSelect = false ); bool singleSelect = false );
/** /**