Skip to content

Commit c0f67c1

Browse files
author
mhugent
committed
Applied patch from Borys to invert selection when ctrl-key pressed
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9754 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9410506 commit c0f67c1

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

python/core/qgsvectorlayer.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public:
7070
/** Select not selected features and deselect selected ones */
7171
void invertSelection();
7272

73+
/** Invert selection of features found within the search rectangle (in layer's coordinates) */
74+
void invertSelectionInRectangle( QgsRectangle & rect);
75+
7376
/** Get a copy of the user-selected features */
7477
QList<QgsFeature> selectedFeatures();
7578

src/app/qgsmaptoolselect.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )
114114

115115
QgsRectangle search( ll.x(), ll.y(), ur.x(), ur.y() );
116116

117-
// if Ctrl key is pressed, selected features will be added to selection
117+
// if Ctrl key is pressed, selected features will be flipped in selection
118118
// instead of removing old selection
119-
bool lock = ( e->modifiers() & Qt::ControlModifier );
119+
bool flip = ( e->modifiers() & Qt::ControlModifier );
120120

121121
// toLayerCoordinates will throw an exception for an 'invalid' rectangle.
122122
// For example, if you project a world map onto a globe using EPSG 2163
@@ -136,6 +136,13 @@ void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )
136136
}
137137

138138
QApplication::setOverrideCursor( Qt::WaitCursor );
139-
vlayer->select( search, lock );
139+
if ( flip )
140+
{
141+
vlayer->invertSelectionInRectangle( search );
142+
}
143+
else
144+
{
145+
vlayer->select( search, false );
146+
}
140147
QApplication::restoreOverrideCursor();
141148
}

src/core/qgsvectorlayer.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,29 @@ void QgsVectorLayer::invertSelection()
875875
emit selectionChanged();
876876
}
877877

878+
void QgsVectorLayer::invertSelectionInRectangle( QgsRectangle & rect )
879+
{
880+
// normalize the rectangle
881+
rect.normalize();
882+
883+
select( QgsAttributeList(), rect, false, true );
884+
885+
QgsFeature fet;
886+
while ( nextFeature( fet ) )
887+
{
888+
if ( mSelectedFeatureIds.contains( fet.id() ) )
889+
{
890+
deselect( fet.id(), false ); // don't emit signal
891+
}
892+
else
893+
{
894+
select( fet.id(), false ); // don't emit signal
895+
}
896+
}
897+
898+
emit selectionChanged();
899+
}
900+
878901
void QgsVectorLayer::removeSelection( bool emitSignal )
879902
{
880903
mSelectedFeatureIds.clear();

src/core/qgsvectorlayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
132132
/** Select not selected features and deselect selected ones */
133133
void invertSelection();
134134

135+
/** Invert selection of features found within the search rectangle (in layer's coordinates) */
136+
void invertSelectionInRectangle( QgsRectangle & rect);
137+
135138
/** Get a copy of the user-selected features */
136139
QgsFeatureList selectedFeatures();
137140

0 commit comments

Comments
 (0)