Skip to content

Commit

Permalink
Add an action to deselect features only from the current layer
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus authored and nyalldawson committed Mar 18, 2020
1 parent 8131799 commit 452ca91
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<file>themes/default/mActionDeleteSelected.svg</file>
<file>themes/default/mActionDeleteTable.svg</file>
<file>themes/default/mActionDeselectAll.svg</file>
<file>themes/default/mActionDeselectActiveLayer.svg</file>
<file>themes/default/mActionDuplicateLayer.svg</file>
<file>themes/default/mActionDuplicateComposer.svg</file>
<file>themes/default/mActionEditCopy.svg</file>
Expand Down
11 changes: 11 additions & 0 deletions images/themes/default/mActionDeselectActiveLayer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/themes/default/mActionDeselectAll.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 50 additions & 2 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2549,6 +2549,7 @@ void QgisApp::createActions()
connect( mActionSelectFreehand, &QAction::triggered, this, &QgisApp::selectByFreehand );
connect( mActionSelectRadius, &QAction::triggered, this, &QgisApp::selectByRadius );
connect( mActionDeselectAll, &QAction::triggered, this, &QgisApp::deselectAll );
connect( mActionDeselectActiveLayer, &QAction::triggered, this, &QgisApp::deselectActiveLayer );
connect( mActionSelectAll, &QAction::triggered, this, &QgisApp::selectAll );
connect( mActionReselect, &QAction::triggered, this, [ = ]
{
Expand Down Expand Up @@ -2806,6 +2807,7 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionSelectFreehand );
mMapToolGroup->addAction( mActionSelectRadius );
mMapToolGroup->addAction( mActionDeselectAll );
mMapToolGroup->addAction( mActionDeselectActiveLayer );
mMapToolGroup->addAction( mActionSelectAll );
mMapToolGroup->addAction( mActionReselect );
mMapToolGroup->addAction( mActionInvertSelection );
Expand Down Expand Up @@ -3134,10 +3136,34 @@ void QgisApp::createToolBars()
break;
}
bt->setDefaultAction( defSelectionAction );
QAction *selectionAction = mAttributesToolBar->insertWidget( mActionDeselectAll, bt );
QAction *selectionAction = mAttributesToolBar->insertWidget( mActionOpenTable, bt );
selectionAction->setObjectName( QStringLiteral( "ActionSelection" ) );
connect( bt, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );


// deselection tool button
bt = new QToolButton( mAttributesToolBar );
bt->setPopupMode( QToolButton::MenuButtonPopup );
QList<QAction *> deselectionActions;
deselectionActions << mActionDeselectAll << mActionDeselectActiveLayer;
bt->addActions( deselectionActions );

QAction *defDeselectionAction = mActionDeselectAll;
switch ( settings.value( QStringLiteral( "UI/deselectionTool" ), 0 ).toInt() )
{
case 0:
defDeselectionAction = mActionDeselectAll;
break;
case 1:
defDeselectionAction = mActionDeselectActiveLayer;
break;
}
bt->setDefaultAction( defDeselectionAction );
QAction *deselectionAction = mAttributesToolBar->insertWidget( mActionOpenTable, bt );
deselectionAction->setObjectName( QStringLiteral( "ActionDeselection" ) );
connect( bt, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );


// select tool button

bt = new QToolButton( mAttributesToolBar );
Expand All @@ -3164,7 +3190,7 @@ void QgisApp::createToolBars()
break;
}
bt->setDefaultAction( defSelectAction );
QAction *selectAction = mAttributesToolBar->insertWidget( selectionAction, bt );
QAction *selectAction = mAttributesToolBar->insertWidget( deselectionAction, bt );
selectAction->setObjectName( QStringLiteral( "ActionSelect" ) );
connect( bt, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );

Expand Down Expand Up @@ -3879,6 +3905,7 @@ void QgisApp::setTheme( const QString &themeName )
mActionSelectFreehand->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSelectFreehand.svg" ) ) );
mActionSelectRadius->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSelectRadius.svg" ) ) );
mActionDeselectAll->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDeselectAll.svg" ) ) );
mActionDeselectActiveLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDeselectActiveLayer.svg" ) ) );
mActionSelectAll->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSelectAll.svg" ) ) );
mActionInvertSelection->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionInvertSelection.svg" ) ) );
mActionSelectByExpression->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconExpressionSelect.svg" ) ) );
Expand Down Expand Up @@ -9519,6 +9546,23 @@ void QgisApp::deselectAll()
}
}

void QgisApp::deselectActiveLayer()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );

if ( !vlayer )
{
visibleMessageBar()->pushMessage(
tr( "No active vector layer" ),
tr( "To deselect all features, choose a vector layer in the legend" ),
Qgis::Info,
messageTimeout() );
return;
}

vlayer->removeSelection();
}

void QgisApp::invertSelection()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
Expand Down Expand Up @@ -15067,6 +15111,10 @@ void QgisApp::toolButtonActionTriggered( QAction *action )
settings.setValue( QStringLiteral( "UI/selectionTool" ), 2 );
else if ( action == mActionInvertSelection )
settings.setValue( QStringLiteral( "UI/selectionTool" ), 3 );
else if ( action == mActionDeselectAll )
settings.setValue( QStringLiteral( "UI/deselectionTool" ), 0 );
else if ( action == mActionDeselectActiveLayer )
settings.setValue( QStringLiteral( "UI/deselectionTool" ), 1 );
else if ( action == mActionMeasure )
settings.setValue( QStringLiteral( "UI/measureTool" ), 0 );
else if ( action == mActionMeasureArea )
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! deselect features from all layers
void deselectAll();

//! deselect features from the current active layer
void deselectActiveLayer();

//! select all features
void selectAll();

Expand Down
11 changes: 10 additions & 1 deletion src/ui/qgisapp.ui
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
<addaction name="mActionSelectByForm"/>
<addaction name="mActionSelectByExpression"/>
<addaction name="mActionDeselectAll"/>
<addaction name="mActionDeselectActiveLayer"/>
<addaction name="mActionReselect"/>
<addaction name="mActionSelectAll"/>
<addaction name="mActionInvertSelection"/>
Expand Down Expand Up @@ -542,7 +543,6 @@
<bool>true</bool>
</attribute>
<addaction name="mActionIdentify"/>
<addaction name="mActionDeselectAll"/>
<addaction name="mActionOpenTable"/>
<addaction name="mActionOpenFieldCalc"/>
<addaction name="mActionStatisticalSummary"/>
Expand Down Expand Up @@ -1213,6 +1213,15 @@
<string>Ctrl+Shift+A</string>
</property>
</action>
<action name="mActionDeselectActiveLayer">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionDeselectActiveLayer.svg</normaloff>:/images/themes/default/mActionDeselectActiveLayer.svg</iconset>
</property>
<property name="text">
<string>Deselect Features from the Current Active Layer</string>
</property>
</action>
<action name="mActionSelectAll">
<property name="icon">
<iconset resource="../../images/images.qrc">
Expand Down

0 comments on commit 452ca91

Please sign in to comment.