Skip to content
Permalink
Browse files

Add select all and invert selection to Attributes Toolbar

Took the opportunity to fix a bug where the selectByExpression action
was not disabled when a raster layer was selected.
  • Loading branch information
Patrick Valsecchi authored and nyalldawson committed Jan 30, 2016
1 parent 45489f6 commit 57fb7ce47aad2f4aabe4d72a9d780cf5bd368a15
Showing with 108 additions and 6 deletions.
  1. +1 −0 images/images.qrc
  2. BIN images/themes/default/mActionSelectAll.png
  3. +78 −4 src/app/qgisapp.cpp
  4. +6 −0 src/app/qgisapp.h
  5. +23 −2 src/ui/qgisapp.ui
@@ -276,6 +276,7 @@
<file>themes/default/mActionSaveMapAsImage.png</file>
<file>themes/default/mActionScaleBar.png</file>
<file>themes/default/mActionSelect.svg</file>
<file>themes/default/mActionSelectAll.png</file>
<file>themes/default/mActionSelectedToTop.png</file>
<file>themes/default/mActionSelectFreehand.svg</file>
<file>themes/default/mActionSelectPan.png</file>
Binary file not shown.
@@ -1385,6 +1385,8 @@ void QgisApp::createActions()
connect( mActionSelectFreehand, SIGNAL( triggered() ), this, SLOT( selectByFreehand() ) );
connect( mActionSelectRadius, SIGNAL( triggered() ), this, SLOT( selectByRadius() ) );
connect( mActionDeselectAll, SIGNAL( triggered() ), this, SLOT( deselectAll() ) );
connect( mActionSelectAll, SIGNAL( triggered() ), this, SLOT( selectAll() ) );
connect( mActionInvertSelection, SIGNAL( triggered() ), this, SLOT( invertSelection() ) );
connect( mActionSelectByExpression, SIGNAL( triggered() ), this, SLOT( selectByExpression() ) );
connect( mActionIdentify, SIGNAL( triggered() ), this, SLOT( identify() ) );
connect( mActionFeatureAction, SIGNAL( triggered() ), this, SLOT( doFeatureAction() ) );
@@ -1624,6 +1626,8 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionSelectFreehand );
mMapToolGroup->addAction( mActionSelectRadius );
mMapToolGroup->addAction( mActionDeselectAll );
mMapToolGroup->addAction( mActionSelectAll );
mMapToolGroup->addAction( mActionInvertSelection );
mMapToolGroup->addAction( mActionMeasure );
mMapToolGroup->addAction( mActionMeasureArea );
mMapToolGroup->addAction( mActionMeasureAngle );
@@ -1834,14 +1838,25 @@ void QgisApp::createToolBars()

mToolbarMenu->addActions( toolbarMenuActions );

// select tool button
// selection tool button

QToolButton *bt = new QToolButton( mAttributesToolBar );
bt->setPopupMode( QToolButton::MenuButtonPopup );
QList<QAction*> selectActions;
selectActions << mActionSelectFeatures << mActionSelectPolygon
<< mActionSelectFreehand << mActionSelectRadius;
selectActions << mActionDeselectAll << mActionSelectAll
<< mActionInvertSelection << mActionSelectByExpression;
bt->addActions( selectActions );
bt->setDefaultAction( mActionDeselectAll );
QAction* selectionAction = mAttributesToolBar->insertWidget( mActionOpenTable, bt );

// select tool button

bt = new QToolButton( mAttributesToolBar );
bt->setPopupMode( QToolButton::MenuButtonPopup );
QList<QAction*> selectionActions;
selectionActions << mActionSelectFeatures << mActionSelectPolygon
<< mActionSelectFreehand << mActionSelectRadius;
bt->addActions( selectionActions );

QAction* defSelectAction = mActionSelectFeatures;
switch ( settings.value( "/UI/selectTool", 0 ).toInt() )
@@ -1863,7 +1878,7 @@ void QgisApp::createToolBars()
break;
}
bt->setDefaultAction( defSelectAction );
QAction* selectAction = mAttributesToolBar->insertWidget( mActionDeselectAll, bt );
QAction* selectAction = mAttributesToolBar->insertWidget( selectionAction, bt );
selectAction->setObjectName( "ActionSelect" );
connect( bt, SIGNAL( triggered( QAction * ) ), this, SLOT( toolButtonActionTriggered( QAction * ) ) );

@@ -2294,6 +2309,8 @@ void QgisApp::setTheme( const QString& theThemeName )
mActionSelectFreehand->setIcon( QgsApplication::getThemeIcon( "/mActionSelectFreehand.svg" ) );
mActionSelectRadius->setIcon( QgsApplication::getThemeIcon( "/mActionSelectRadius.svg" ) );
mActionDeselectAll->setIcon( QgsApplication::getThemeIcon( "/mActionDeselectAll.svg" ) );
mActionSelectAll->setIcon( QgsApplication::getThemeIcon( "/mActionSelectAll.png" ) );
mActionInvertSelection->setIcon( QgsApplication::getThemeIcon( "/mActionInvertSelection.png" ) );
mActionSelectByExpression->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) );
mActionOpenTable->setIcon( QgsApplication::getThemeIcon( "/mActionOpenTable.png" ) );
mActionOpenFieldCalc->setIcon( QgsApplication::getThemeIcon( "/mActionCalculateField.png" ) );
@@ -6676,6 +6693,56 @@ void QgisApp::deselectAll()
mMapCanvas->setRenderFlag( true );
}

void QgisApp::invertSelection()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
if ( !vlayer )
{
messageBar()->pushMessage(
tr( "No active vector layer" ),
tr( "To invert selection, choose a vector layer in the legend" ),
QgsMessageBar::INFO,
messageTimeout() );
return;
}

// Turn off rendering to improve speed.
bool renderFlagState = mMapCanvas->renderFlag();
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );

vlayer->invertSelection();

// Turn on rendering (if it was on previously)
if ( renderFlagState )
mMapCanvas->setRenderFlag( true );
}

void QgisApp::selectAll()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
if ( !vlayer )
{
messageBar()->pushMessage(
tr( "No active vector layer" ),
tr( "To select all, choose a vector layer in the legend" ),
QgsMessageBar::INFO,
messageTimeout() );
return;
}

// Turn off rendering to improve speed.
bool renderFlagState = mMapCanvas->renderFlag();
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );

vlayer->selectAll();

// Turn on rendering (if it was on previously)
if ( renderFlagState )
mMapCanvas->setRenderFlag( true );
}

void QgisApp::selectByExpression()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
@@ -9804,6 +9871,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionSelectByExpression->setEnabled( false );
mActionLabeling->setEnabled( false );
mActionOpenTable->setEnabled( false );
mActionSelectAll->setEnabled( false );
mActionInvertSelection->setEnabled( false );
mActionOpenFieldCalc->setEnabled( false );
mActionToggleEditing->setEnabled( false );
mActionToggleEditing->setChecked( false );
@@ -9900,6 +9969,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionIdentify->setEnabled( true );
mActionSelectByExpression->setEnabled( true );
mActionOpenTable->setEnabled( true );
mActionSelectAll->setEnabled( true );
mActionInvertSelection->setEnabled( true );
mActionSaveLayerDefinition->setEnabled( true );
mActionLayerSaveAs->setEnabled( true );
mActionCopyFeatures->setEnabled( layerHasSelection );
@@ -10074,6 +10145,9 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionSelectRadius->setEnabled( false );
mActionZoomActualSize->setEnabled( true );
mActionOpenTable->setEnabled( false );
mActionSelectAll->setEnabled( false );
mActionInvertSelection->setEnabled( false );
mActionSelectByExpression->setEnabled( false );
mActionOpenFieldCalc->setEnabled( false );
mActionToggleEditing->setEnabled( false );
mActionToggleEditing->setChecked( false );
@@ -1050,6 +1050,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! deselect features from all layers
void deselectAll();

//! select all features
void selectAll();

//! invert the selection
void invertSelection();

//! select features by expression
void selectByExpression();

@@ -72,6 +72,8 @@
<addaction name="mActionSelectRadius"/>
<addaction name="mActionSelectByExpression"/>
<addaction name="mActionDeselectAll"/>
<addaction name="mActionSelectAll"/>
<addaction name="mActionInvertSelection"/>
</widget>
<widget class="QMenu" name="menuMeasure">
<property name="title">
@@ -439,8 +441,6 @@
<bool>true</bool>
</attribute>
<addaction name="mActionIdentify"/>
<addaction name="mActionDeselectAll"/>
<addaction name="mActionSelectByExpression"/>
<addaction name="mActionOpenTable"/>
<addaction name="mActionOpenFieldCalc"/>
<addaction name="mActionStatisticalSummary"/>
@@ -997,6 +997,27 @@
<string>Deselect Features from All Layers</string>
</property>
</action>
<action name="mActionSelectAll">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSelectAll.png</normaloff>:/images/themes/default/mActionSelectAll.png</iconset>
</property>
<property name="text">
<string>Select all Features</string>
</property>
<property name="shortcut">
<string>Ctrl+A</string>
</property>
</action>
<action name="mActionInvertSelection">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionInvertSelection.png</normaloff>:/images/themes/default/mActionInvertSelection.png</iconset>
</property>
<property name="text">
<string>Invert Feature selection</string>
</property>
</action>
<action name="mActionIdentify">
<property name="checkable">
<bool>true</bool>

0 comments on commit 57fb7ce

Please sign in to comment.
You can’t perform that action at this time.