[QGIS Commit] r9754 - in trunk/qgis: python/core src/app src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Dec 8 12:02:01 EST 2008


Author: mhugent
Date: 2008-12-08 12:02:01 -0500 (Mon, 08 Dec 2008)
New Revision: 9754

Modified:
   trunk/qgis/python/core/qgsvectorlayer.sip
   trunk/qgis/src/app/qgsmaptoolselect.cpp
   trunk/qgis/src/core/qgsvectorlayer.cpp
   trunk/qgis/src/core/qgsvectorlayer.h
Log:
Applied patch from Borys to invert selection when ctrl-key pressed

Modified: trunk/qgis/python/core/qgsvectorlayer.sip
===================================================================
--- trunk/qgis/python/core/qgsvectorlayer.sip	2008-12-08 13:59:07 UTC (rev 9753)
+++ trunk/qgis/python/core/qgsvectorlayer.sip	2008-12-08 17:02:01 UTC (rev 9754)
@@ -70,6 +70,9 @@
   /** 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();
   

Modified: trunk/qgis/src/app/qgsmaptoolselect.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolselect.cpp	2008-12-08 13:59:07 UTC (rev 9753)
+++ trunk/qgis/src/app/qgsmaptoolselect.cpp	2008-12-08 17:02:01 UTC (rev 9754)
@@ -114,9 +114,9 @@
 
   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 @@
   }
 
   QApplication::setOverrideCursor( Qt::WaitCursor );
-  vlayer->select( search, lock );
+  if ( flip )
+  {
+    vlayer->invertSelectionInRectangle( search );
+  }
+  else
+  {
+    vlayer->select( search, false );
+  }
   QApplication::restoreOverrideCursor();
 }

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2008-12-08 13:59:07 UTC (rev 9753)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2008-12-08 17:02:01 UTC (rev 9754)
@@ -875,6 +875,29 @@
   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();

Modified: trunk/qgis/src/core/qgsvectorlayer.h
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.h	2008-12-08 13:59:07 UTC (rev 9753)
+++ trunk/qgis/src/core/qgsvectorlayer.h	2008-12-08 17:02:01 UTC (rev 9754)
@@ -132,6 +132,9 @@
     /** 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();
 



More information about the QGIS-commit mailing list