Skip to content

Commit 4f73c28

Browse files
committedDec 28, 2016
[FEATURE] Hide Deselected Layers action
Allows you to quickly hide all deselected layers. This is very handy when you have a large project and want to quickly hide all except for a couple of layers
1 parent c83426e commit 4f73c28

File tree

8 files changed

+39
-0
lines changed

8 files changed

+39
-0
lines changed
 

‎python/gui/qgisinterface.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ class QgisInterface : QObject
483483
virtual QAction *actionHideAllLayers() = 0;
484484
virtual QAction *actionShowAllLayers() = 0;
485485
virtual QAction *actionHideSelectedLayers() = 0;
486+
/**
487+
* Returns the Hide Deselected Layers action.
488+
* @note added in QGIS 3.0
489+
*/
490+
virtual QAction *actionHideDeselectedLayers() = 0;
486491
virtual QAction *actionShowSelectedLayers() = 0;
487492

488493
// Plugin menu actions

‎src/app/qgisapp.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ void QgisApp::createActions()
17071707
connect( mActionHideAllLayers, SIGNAL( triggered() ), this, SLOT( hideAllLayers() ) );
17081708
connect( mActionShowSelectedLayers, SIGNAL( triggered() ), this, SLOT( showSelectedLayers() ) );
17091709
connect( mActionHideSelectedLayers, SIGNAL( triggered() ), this, SLOT( hideSelectedLayers() ) );
1710+
connect( mActionHideDeselectedLayers, &QAction::triggered, this, &QgisApp::hideDeselectedLayers );
17101711

17111712
// Plugin Menu Items
17121713

@@ -5783,6 +5784,17 @@ void QgisApp::hideSelectedLayers()
57835784
}
57845785
}
57855786

5787+
void QgisApp::hideDeselectedLayers()
5788+
{
5789+
QList<QgsLayerTreeLayer*> selectedLayerNodes = mLayerTreeView->selectedLayerNodes();
5790+
5791+
Q_FOREACH ( QgsLayerTreeLayer* nodeLayer, mLayerTreeView->layerTreeModel()->rootGroup()->findLayers() )
5792+
{
5793+
if ( selectedLayerNodes.contains( nodeLayer ) )
5794+
continue;
5795+
nodeLayer->setVisible( Qt::Unchecked );
5796+
}
5797+
}
57865798

57875799
// reimplements method from base (gui) class
57885800
void QgisApp::showSelectedLayers()

‎src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
411411
QAction *actionHideAllLayers() { return mActionHideAllLayers; }
412412
QAction *actionShowAllLayers() { return mActionShowAllLayers; }
413413
QAction *actionHideSelectedLayers() { return mActionHideSelectedLayers; }
414+
QAction *actionHideDeselectedLayers() { return mActionHideDeselectedLayers; }
414415
QAction *actionShowSelectedLayers() { return mActionShowSelectedLayers; }
415416

416417
QAction *actionManagePlugins() { return mActionManagePlugins; }
@@ -1027,6 +1028,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
10271028
void showAllLayers();
10281029
//reimplements method from base (gui) class
10291030
void hideSelectedLayers();
1031+
//! Hides any layers which are not selected
1032+
void hideDeselectedLayers();
10301033
//reimplements method from base (gui) class
10311034
void showSelectedLayers();
10321035
//! Return pointer to the active layer

‎src/app/qgisappinterface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ QAction *QgisAppInterface::actionRemoveAllFromOverview() { return qgis->actionRe
631631
QAction *QgisAppInterface::actionHideAllLayers() { return qgis->actionHideAllLayers(); }
632632
QAction *QgisAppInterface::actionShowAllLayers() { return qgis->actionShowAllLayers(); }
633633
QAction *QgisAppInterface::actionHideSelectedLayers() { return qgis->actionHideSelectedLayers(); }
634+
QAction*QgisAppInterface::actionHideDeselectedLayers() { return qgis->actionHideDeselectedLayers(); }
634635
QAction *QgisAppInterface::actionShowSelectedLayers() { return qgis->actionShowSelectedLayers(); }
635636

636637
//! Plugin menu actions

‎src/app/qgisappinterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
445445
virtual QAction *actionHideAllLayers() override;
446446
virtual QAction *actionShowAllLayers() override;
447447
virtual QAction *actionHideSelectedLayers() override;
448+
virtual QAction *actionHideDeselectedLayers() override;
448449
virtual QAction *actionShowSelectedLayers() override;
449450

450451
//! Plugin menu actions

‎src/app/qgsmapthemes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ QgsMapThemes::QgsMapThemes()
4242
mMenu->addAction( QgisApp::instance()->actionHideAllLayers() );
4343
mMenu->addAction( QgisApp::instance()->actionShowSelectedLayers() );
4444
mMenu->addAction( QgisApp::instance()->actionHideSelectedLayers() );
45+
mMenu->addAction( QgisApp::instance()->actionHideDeselectedLayers() );
4546
mMenu->addSeparator();
4647

4748
mReplaceMenu = new QMenu( tr( "Replace Theme" ) );

‎src/gui/qgisinterface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ class GUI_EXPORT QgisInterface : public QObject
539539
virtual QAction *actionHideAllLayers() = 0;
540540
virtual QAction *actionShowAllLayers() = 0;
541541
virtual QAction *actionHideSelectedLayers() = 0;
542+
543+
/**
544+
* Returns the Hide Deselected Layers action.
545+
* @note added in QGIS 3.0
546+
*/
547+
virtual QAction *actionHideDeselectedLayers() = 0;
542548
virtual QAction *actionShowSelectedLayers() = 0;
543549

544550
// Plugin menu actions

‎src/ui/qgisapp.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
<addaction name="mActionHideAllLayers"/>
119119
<addaction name="mActionShowSelectedLayers"/>
120120
<addaction name="mActionHideSelectedLayers"/>
121+
<addaction name="mActionHideDeselectedLayers"/>
121122
<addaction name="separator"/>
122123
</widget>
123124
<widget class="QMenu" name="mLayerMenu">
@@ -2425,6 +2426,15 @@ Acts on currently active editable layer</string>
24252426
<string>Hide Selected Layers</string>
24262427
</property>
24272428
</action>
2429+
<action name="mActionHideDeselectedLayers">
2430+
<property name="icon">
2431+
<iconset resource="../../images/images.qrc">
2432+
<normaloff>:/images/themes/default/mActionHideSelectedLayers.png</normaloff>:/images/themes/default/mActionHideSelectedLayers.png</iconset>
2433+
</property>
2434+
<property name="text">
2435+
<string>Hide Deselected Layers</string>
2436+
</property>
2437+
</action>
24282438
<action name="mActionNewMemoryLayer">
24292439
<property name="icon">
24302440
<iconset resource="../../images/images.qrc">

0 commit comments

Comments
 (0)
Please sign in to comment.