Applied patch from Borys to invert selection when ctrl-key pressed

git-svn-id: http://svn.osgeo.org/qgis/trunk@9754 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2008-12-08 17:02:01 +00:00
parent d367081e7e
commit c569639b7c
4 changed files with 39 additions and 3 deletions

View File

@ -70,6 +70,9 @@ public:
/** Select not selected features and deselect selected ones */ /** Select not selected features and deselect selected ones */
void invertSelection(); void invertSelection();
/** Invert selection of features found within the search rectangle (in layer's coordinates) */
void invertSelectionInRectangle( QgsRectangle & rect);
/** Get a copy of the user-selected features */ /** Get a copy of the user-selected features */
QList<QgsFeature> selectedFeatures(); QList<QgsFeature> selectedFeatures();

View File

@ -114,9 +114,9 @@ void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )
QgsRectangle search( ll.x(), ll.y(), ur.x(), ur.y() ); QgsRectangle search( ll.x(), ll.y(), ur.x(), ur.y() );
// if Ctrl key is pressed, selected features will be added to selection // if Ctrl key is pressed, selected features will be flipped in selection
// instead of removing old selection // instead of removing old selection
bool lock = ( e->modifiers() & Qt::ControlModifier ); bool flip = ( e->modifiers() & Qt::ControlModifier );
// toLayerCoordinates will throw an exception for an 'invalid' rectangle. // toLayerCoordinates will throw an exception for an 'invalid' rectangle.
// For example, if you project a world map onto a globe using EPSG 2163 // For example, if you project a world map onto a globe using EPSG 2163
@ -136,6 +136,13 @@ void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )
} }
QApplication::setOverrideCursor( Qt::WaitCursor ); QApplication::setOverrideCursor( Qt::WaitCursor );
vlayer->select( search, lock ); if ( flip )
{
vlayer->invertSelectionInRectangle( search );
}
else
{
vlayer->select( search, false );
}
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }

View File

@ -875,6 +875,29 @@ void QgsVectorLayer::invertSelection()
emit selectionChanged(); emit selectionChanged();
} }
void QgsVectorLayer::invertSelectionInRectangle( QgsRectangle & rect )
{
// normalize the rectangle
rect.normalize();
select( QgsAttributeList(), rect, false, true );
QgsFeature fet;
while ( nextFeature( fet ) )
{
if ( mSelectedFeatureIds.contains( fet.id() ) )
{
deselect( fet.id(), false ); // don't emit signal
}
else
{
select( fet.id(), false ); // don't emit signal
}
}
emit selectionChanged();
}
void QgsVectorLayer::removeSelection( bool emitSignal ) void QgsVectorLayer::removeSelection( bool emitSignal )
{ {
mSelectedFeatureIds.clear(); mSelectedFeatureIds.clear();

View File

@ -132,6 +132,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Select not selected features and deselect selected ones */ /** Select not selected features and deselect selected ones */
void invertSelection(); void invertSelection();
/** Invert selection of features found within the search rectangle (in layer's coordinates) */
void invertSelectionInRectangle( QgsRectangle & rect);
/** Get a copy of the user-selected features */ /** Get a copy of the user-selected features */
QgsFeatureList selectedFeatures(); QgsFeatureList selectedFeatures();