Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Applied patch from Borys to invert selection when ctrl-key pressed
- Loading branch information
|
@@ -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(); |
|
|
|
|
|