mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
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:
parent
d367081e7e
commit
c569639b7c
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user