Skip to content

Commit

Permalink
[FEATURE] remove selections of all layers (fixes #2135)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12224 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 22, 2009
1 parent a1a8aa2 commit ad61532
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Binary file added images/themes/default/mActionDeselectAll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,12 @@ void QgisApp::createActions()
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" ) );
Expand Down Expand Up @@ -1100,6 +1106,8 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionIdentify );
mActionSelect->setCheckable( true );
mMapToolGroup->addAction( mActionSelect );
mActionDeselectAll->setCheckable( false );
mMapToolGroup->addAction( mActionDeselectAll );
mActionMeasure->setCheckable( true );
mMapToolGroup->addAction( mActionMeasure );
mActionMeasureArea->setCheckable( true );
Expand Down Expand Up @@ -1262,6 +1270,7 @@ void QgisApp::createMenus()
mViewMenu->addAction( mActionZoomIn );
mViewMenu->addAction( mActionZoomOut );
mViewMenu->addAction( mActionSelect );
mViewMenu->addAction( mActionDeselectAll );
mViewMenu->addAction( mActionIdentify );
mViewMenu->addAction( mActionMeasure );
mViewMenu->addAction( mActionMeasureArea );
Expand Down Expand Up @@ -1479,6 +1488,7 @@ void QgisApp::createToolBars()
mAttributesToolBar->setObjectName( "Attributes" );
mAttributesToolBar->addAction( mActionIdentify );
mAttributesToolBar->addAction( mActionSelect );
mAttributesToolBar->addAction( mActionDeselectAll );
mAttributesToolBar->addAction( mActionOpenTable );
mAttributesToolBar->addAction( mActionMeasure );
mAttributesToolBar->addAction( mActionMeasureArea );
Expand Down Expand Up @@ -1722,6 +1732,7 @@ void QgisApp::setTheme( QString theThemeName )
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" ) );
Expand Down Expand Up @@ -4442,6 +4453,30 @@ void QgisApp::select()
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()
{
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ class QgisApp : public QMainWindow

//! activates the selection tool
void select();

//! deselect features from all layers
void deselectAll();

//! refresh map canvas
void refreshMapCanvas();
//! returns pointer to map legend
Expand Down Expand Up @@ -773,6 +777,7 @@ class QgisApp : public QMainWindow
QAction *mActionZoomIn;
QAction *mActionZoomOut;
QAction *mActionSelect;
QAction *mActionDeselectAll;
QAction *mActionIdentify;
QAction *mActionMeasure;
QAction *mActionMeasureArea;
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,9 @@ void QgsVectorLayer::invertSelectionInRectangle( QgsRectangle & rect )

void QgsVectorLayer::removeSelection( bool emitSignal )
{
if( mSelectedFeatureIds.size() == 0 )
return;

mSelectedFeatureIds.clear();

if ( emitSignal )
Expand Down

0 comments on commit ad61532

Please sign in to comment.