Skip to content

Commit

Permalink
Applied patch from Borys to invert selection when ctrl-key pressed
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9754 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Dec 8, 2008
1 parent d367081 commit c569639
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -70,6 +70,9 @@ public:
/** Select not selected features and deselect selected ones */
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 */
QList<QgsFeature> selectedFeatures();

Expand Down
13 changes: 10 additions & 3 deletions src/app/qgsmaptoolselect.cpp
Expand Up @@ -114,9 +114,9 @@ void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )

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
bool lock = ( e->modifiers() & Qt::ControlModifier );
bool flip = ( e->modifiers() & Qt::ControlModifier );

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

QApplication::setOverrideCursor( Qt::WaitCursor );
vlayer->select( search, lock );
if ( flip )
{
vlayer->invertSelectionInRectangle( search );
}
else
{
vlayer->select( search, false );
}
QApplication::restoreOverrideCursor();
}
23 changes: 23 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -875,6 +875,29 @@ void QgsVectorLayer::invertSelection()
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 )
{
mSelectedFeatureIds.clear();
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -132,6 +132,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Select not selected features and deselect selected ones */
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 */
QgsFeatureList selectedFeatures();

Expand Down

0 comments on commit c569639

Please sign in to comment.