[QGIS Commit] r12224 - in trunk/qgis: images/themes/default src/app src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Nov 22 16:50:10 EST 2009


Author: jef
Date: 2009-11-22 16:50:09 -0500 (Sun, 22 Nov 2009)
New Revision: 12224

Added:
   trunk/qgis/images/themes/default/mActionDeselectAll.png
Modified:
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgisapp.h
   trunk/qgis/src/core/qgsvectorlayer.cpp
Log:
[FEATURE] remove selections of all layers (fixes #2135)

Added: trunk/qgis/images/themes/default/mActionDeselectAll.png
===================================================================
(Binary files differ)


Property changes on: trunk/qgis/images/themes/default/mActionDeselectAll.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2009-11-22 21:26:12 UTC (rev 12223)
+++ trunk/qgis/src/app/qgisapp.cpp	2009-11-22 21:50:09 UTC (rev 12224)
@@ -791,6 +791,12 @@
   connect( mActionSelect, SIGNAL( triggered() ), this, SLOT( select() ) );
   mActionSelect->setEnabled( false );
 
+  mActionDeselectAll = new QAction( getThemeIcon( "mActionDeselectAll.png" ), tr( "Deselect features from all layers" ), this );
+  shortcuts->registerAction( mActionDeselectAll );
+  mActionDeselectAll->setStatusTip( tr( "Deselect features from all layers" ) );
+  connect( mActionDeselectAll, SIGNAL( triggered() ), this, SLOT( deselectAll() ) );
+  mActionDeselectAll->setEnabled( true );
+
   mActionIdentify = new QAction( getThemeIcon( "mActionIdentify.png" ), tr( "Identify Features" ), this );
   shortcuts->registerAction( mActionIdentify, tr( "Ctrl+Shift+I", "Click on features to identify them" ) );
   mActionIdentify->setStatusTip( tr( "Click on features to identify them" ) );
@@ -1100,6 +1106,8 @@
   mMapToolGroup->addAction( mActionIdentify );
   mActionSelect->setCheckable( true );
   mMapToolGroup->addAction( mActionSelect );
+  mActionDeselectAll->setCheckable( false );
+  mMapToolGroup->addAction( mActionDeselectAll );
   mActionMeasure->setCheckable( true );
   mMapToolGroup->addAction( mActionMeasure );
   mActionMeasureArea->setCheckable( true );
@@ -1262,6 +1270,7 @@
   mViewMenu->addAction( mActionZoomIn );
   mViewMenu->addAction( mActionZoomOut );
   mViewMenu->addAction( mActionSelect );
+  mViewMenu->addAction( mActionDeselectAll );
   mViewMenu->addAction( mActionIdentify );
   mViewMenu->addAction( mActionMeasure );
   mViewMenu->addAction( mActionMeasureArea );
@@ -1479,6 +1488,7 @@
   mAttributesToolBar->setObjectName( "Attributes" );
   mAttributesToolBar->addAction( mActionIdentify );
   mAttributesToolBar->addAction( mActionSelect );
+  mAttributesToolBar->addAction( mActionDeselectAll );
   mAttributesToolBar->addAction( mActionOpenTable );
   mAttributesToolBar->addAction( mActionMeasure );
   mAttributesToolBar->addAction( mActionMeasureArea );
@@ -1722,6 +1732,7 @@
   mActionZoomToLayer->setIcon( getThemeIcon( "/mActionZoomToLayer.png" ) );
   mActionIdentify->setIcon( getThemeIcon( "/mActionIdentify.png" ) );
   mActionSelect->setIcon( getThemeIcon( "/mActionSelect.png" ) );
+  mActionDeselectAll->setIcon( getThemeIcon( "/mActionDeselectAll.png" ) );
   mActionOpenTable->setIcon( getThemeIcon( "/mActionOpenTable.png" ) );
   mActionMeasure->setIcon( getThemeIcon( "/mActionMeasure.png" ) );
   mActionMeasureArea->setIcon( getThemeIcon( "/mActionMeasureArea.png" ) );
@@ -4442,7 +4453,31 @@
   mMapCanvas->setMapTool( mMapTools.mSelect );
 }
 
+void QgisApp::deselectAll()
+{
+  if ( !mMapCanvas || mMapCanvas->isDrawing() )
+  {
+    return;
+  }
 
+  // Turn off rendering to improve speed.
+  bool renderFlagState = mMapCanvas->renderFlag();
+  mMapCanvas->setRenderFlag( false );
+
+  QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
+  for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it!=layers.end(); it++ )
+  {
+    QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() );
+    if( !vl )
+      continue;
+
+    vl->removeSelection();
+  }
+
+  // Turn on rendering (if it was on previously)
+  mMapCanvas->setRenderFlag( renderFlagState );
+}
+
 void QgisApp::addVertex()
 {
   if ( mMapCanvas && mMapCanvas->isDrawing() )

Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h	2009-11-22 21:26:12 UTC (rev 12223)
+++ trunk/qgis/src/app/qgisapp.h	2009-11-22 21:50:09 UTC (rev 12224)
@@ -540,6 +540,10 @@
 
     //! activates the selection tool
     void select();
+
+    //! deselect features from all layers
+    void deselectAll();
+
     //! refresh map canvas
     void refreshMapCanvas();
     //! returns pointer to map legend
@@ -773,6 +777,7 @@
     QAction *mActionZoomIn;
     QAction *mActionZoomOut;
     QAction *mActionSelect;
+    QAction *mActionDeselectAll;
     QAction *mActionIdentify;
     QAction *mActionMeasure;
     QAction *mActionMeasureArea;

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2009-11-22 21:26:12 UTC (rev 12223)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2009-11-22 21:50:09 UTC (rev 12224)
@@ -1130,6 +1130,9 @@
 
 void QgsVectorLayer::removeSelection( bool emitSignal )
 {
+  if( mSelectedFeatureIds.size() == 0 )
+    return;
+
   mSelectedFeatureIds.clear();
 
   if ( emitSignal )



More information about the QGIS-commit mailing list