Skip to content

Commit ad61532

Browse files
author
jef
committed
[FEATURE] remove selections of all layers (fixes #2135)
git-svn-id: http://svn.osgeo.org/qgis/trunk@12224 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a1a8aa2 commit ad61532

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
1.74 KB
Loading

src/app/qgisapp.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,12 @@ void QgisApp::createActions()
791791
connect( mActionSelect, SIGNAL( triggered() ), this, SLOT( select() ) );
792792
mActionSelect->setEnabled( false );
793793

794+
mActionDeselectAll = new QAction( getThemeIcon( "mActionDeselectAll.png" ), tr( "Deselect features from all layers" ), this );
795+
shortcuts->registerAction( mActionDeselectAll );
796+
mActionDeselectAll->setStatusTip( tr( "Deselect features from all layers" ) );
797+
connect( mActionDeselectAll, SIGNAL( triggered() ), this, SLOT( deselectAll() ) );
798+
mActionDeselectAll->setEnabled( true );
799+
794800
mActionIdentify = new QAction( getThemeIcon( "mActionIdentify.png" ), tr( "Identify Features" ), this );
795801
shortcuts->registerAction( mActionIdentify, tr( "Ctrl+Shift+I", "Click on features to identify them" ) );
796802
mActionIdentify->setStatusTip( tr( "Click on features to identify them" ) );
@@ -1100,6 +1106,8 @@ void QgisApp::createActionGroups()
11001106
mMapToolGroup->addAction( mActionIdentify );
11011107
mActionSelect->setCheckable( true );
11021108
mMapToolGroup->addAction( mActionSelect );
1109+
mActionDeselectAll->setCheckable( false );
1110+
mMapToolGroup->addAction( mActionDeselectAll );
11031111
mActionMeasure->setCheckable( true );
11041112
mMapToolGroup->addAction( mActionMeasure );
11051113
mActionMeasureArea->setCheckable( true );
@@ -1262,6 +1270,7 @@ void QgisApp::createMenus()
12621270
mViewMenu->addAction( mActionZoomIn );
12631271
mViewMenu->addAction( mActionZoomOut );
12641272
mViewMenu->addAction( mActionSelect );
1273+
mViewMenu->addAction( mActionDeselectAll );
12651274
mViewMenu->addAction( mActionIdentify );
12661275
mViewMenu->addAction( mActionMeasure );
12671276
mViewMenu->addAction( mActionMeasureArea );
@@ -1479,6 +1488,7 @@ void QgisApp::createToolBars()
14791488
mAttributesToolBar->setObjectName( "Attributes" );
14801489
mAttributesToolBar->addAction( mActionIdentify );
14811490
mAttributesToolBar->addAction( mActionSelect );
1491+
mAttributesToolBar->addAction( mActionDeselectAll );
14821492
mAttributesToolBar->addAction( mActionOpenTable );
14831493
mAttributesToolBar->addAction( mActionMeasure );
14841494
mAttributesToolBar->addAction( mActionMeasureArea );
@@ -1722,6 +1732,7 @@ void QgisApp::setTheme( QString theThemeName )
17221732
mActionZoomToLayer->setIcon( getThemeIcon( "/mActionZoomToLayer.png" ) );
17231733
mActionIdentify->setIcon( getThemeIcon( "/mActionIdentify.png" ) );
17241734
mActionSelect->setIcon( getThemeIcon( "/mActionSelect.png" ) );
1735+
mActionDeselectAll->setIcon( getThemeIcon( "/mActionDeselectAll.png" ) );
17251736
mActionOpenTable->setIcon( getThemeIcon( "/mActionOpenTable.png" ) );
17261737
mActionMeasure->setIcon( getThemeIcon( "/mActionMeasure.png" ) );
17271738
mActionMeasureArea->setIcon( getThemeIcon( "/mActionMeasureArea.png" ) );
@@ -4442,6 +4453,30 @@ void QgisApp::select()
44424453
mMapCanvas->setMapTool( mMapTools.mSelect );
44434454
}
44444455

4456+
void QgisApp::deselectAll()
4457+
{
4458+
if ( !mMapCanvas || mMapCanvas->isDrawing() )
4459+
{
4460+
return;
4461+
}
4462+
4463+
// Turn off rendering to improve speed.
4464+
bool renderFlagState = mMapCanvas->renderFlag();
4465+
mMapCanvas->setRenderFlag( false );
4466+
4467+
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
4468+
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it!=layers.end(); it++ )
4469+
{
4470+
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() );
4471+
if( !vl )
4472+
continue;
4473+
4474+
vl->removeSelection();
4475+
}
4476+
4477+
// Turn on rendering (if it was on previously)
4478+
mMapCanvas->setRenderFlag( renderFlagState );
4479+
}
44454480

44464481
void QgisApp::addVertex()
44474482
{

src/app/qgisapp.h

+5
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,10 @@ class QgisApp : public QMainWindow
540540

541541
//! activates the selection tool
542542
void select();
543+
544+
//! deselect features from all layers
545+
void deselectAll();
546+
543547
//! refresh map canvas
544548
void refreshMapCanvas();
545549
//! returns pointer to map legend
@@ -773,6 +777,7 @@ class QgisApp : public QMainWindow
773777
QAction *mActionZoomIn;
774778
QAction *mActionZoomOut;
775779
QAction *mActionSelect;
780+
QAction *mActionDeselectAll;
776781
QAction *mActionIdentify;
777782
QAction *mActionMeasure;
778783
QAction *mActionMeasureArea;

src/core/qgsvectorlayer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,9 @@ void QgsVectorLayer::invertSelectionInRectangle( QgsRectangle & rect )
11301130

11311131
void QgsVectorLayer::removeSelection( bool emitSignal )
11321132
{
1133+
if( mSelectedFeatureIds.size() == 0 )
1134+
return;
1135+
11331136
mSelectedFeatureIds.clear();
11341137

11351138
if ( emitSignal )

0 commit comments

Comments
 (0)