Skip to content
Permalink
Browse files
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
  • Loading branch information
mhugent committed Dec 8, 2008
1 parent 9410506 commit c0f67c11b0fd1737f25607313efecacede307fcd
Showing with 39 additions and 3 deletions.
  1. +3 −0 python/core/qgsvectorlayer.sip
  2. +10 −3 src/app/qgsmaptoolselect.cpp
  3. +23 −0 src/core/qgsvectorlayer.cpp
  4. +3 −0 src/core/qgsvectorlayer.h
@@ -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();

@@ -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
@@ -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();
}
@@ -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();
@@ -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();

0 comments on commit c0f67c1

Please sign in to comment.