diff --git a/python/gui/qgisinterface.sip b/python/gui/qgisinterface.sip index d77f758e436..6449fff3bb0 100644 --- a/python/gui/qgisinterface.sip +++ b/python/gui/qgisinterface.sip @@ -483,6 +483,11 @@ class QgisInterface : QObject virtual QAction *actionHideAllLayers() = 0; virtual QAction *actionShowAllLayers() = 0; virtual QAction *actionHideSelectedLayers() = 0; + /** + * Returns the Hide Deselected Layers action. + * @note added in QGIS 3.0 + */ + virtual QAction *actionHideDeselectedLayers() = 0; virtual QAction *actionShowSelectedLayers() = 0; // Plugin menu actions diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 7dd14081c6b..f497560cd6a 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1707,6 +1707,7 @@ void QgisApp::createActions() connect( mActionHideAllLayers, SIGNAL( triggered() ), this, SLOT( hideAllLayers() ) ); connect( mActionShowSelectedLayers, SIGNAL( triggered() ), this, SLOT( showSelectedLayers() ) ); connect( mActionHideSelectedLayers, SIGNAL( triggered() ), this, SLOT( hideSelectedLayers() ) ); + connect( mActionHideDeselectedLayers, &QAction::triggered, this, &QgisApp::hideDeselectedLayers ); // Plugin Menu Items @@ -5783,6 +5784,17 @@ void QgisApp::hideSelectedLayers() } } +void QgisApp::hideDeselectedLayers() +{ + QList selectedLayerNodes = mLayerTreeView->selectedLayerNodes(); + + Q_FOREACH ( QgsLayerTreeLayer* nodeLayer, mLayerTreeView->layerTreeModel()->rootGroup()->findLayers() ) + { + if ( selectedLayerNodes.contains( nodeLayer ) ) + continue; + nodeLayer->setVisible( Qt::Unchecked ); + } +} // reimplements method from base (gui) class void QgisApp::showSelectedLayers() diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index 145a40c8e32..07dde561f59 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -411,6 +411,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow QAction *actionHideAllLayers() { return mActionHideAllLayers; } QAction *actionShowAllLayers() { return mActionShowAllLayers; } QAction *actionHideSelectedLayers() { return mActionHideSelectedLayers; } + QAction *actionHideDeselectedLayers() { return mActionHideDeselectedLayers; } QAction *actionShowSelectedLayers() { return mActionShowSelectedLayers; } QAction *actionManagePlugins() { return mActionManagePlugins; } @@ -1027,6 +1028,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow void showAllLayers(); //reimplements method from base (gui) class void hideSelectedLayers(); + //! Hides any layers which are not selected + void hideDeselectedLayers(); //reimplements method from base (gui) class void showSelectedLayers(); //! Return pointer to the active layer diff --git a/src/app/qgisappinterface.cpp b/src/app/qgisappinterface.cpp index a93236bd0ad..1618315cedc 100644 --- a/src/app/qgisappinterface.cpp +++ b/src/app/qgisappinterface.cpp @@ -631,6 +631,7 @@ QAction *QgisAppInterface::actionRemoveAllFromOverview() { return qgis->actionRe QAction *QgisAppInterface::actionHideAllLayers() { return qgis->actionHideAllLayers(); } QAction *QgisAppInterface::actionShowAllLayers() { return qgis->actionShowAllLayers(); } QAction *QgisAppInterface::actionHideSelectedLayers() { return qgis->actionHideSelectedLayers(); } +QAction*QgisAppInterface::actionHideDeselectedLayers() { return qgis->actionHideDeselectedLayers(); } QAction *QgisAppInterface::actionShowSelectedLayers() { return qgis->actionShowSelectedLayers(); } //! Plugin menu actions diff --git a/src/app/qgisappinterface.h b/src/app/qgisappinterface.h index 02de57d0d6d..5e7216de77d 100644 --- a/src/app/qgisappinterface.h +++ b/src/app/qgisappinterface.h @@ -445,6 +445,7 @@ class APP_EXPORT QgisAppInterface : public QgisInterface virtual QAction *actionHideAllLayers() override; virtual QAction *actionShowAllLayers() override; virtual QAction *actionHideSelectedLayers() override; + virtual QAction *actionHideDeselectedLayers() override; virtual QAction *actionShowSelectedLayers() override; //! Plugin menu actions diff --git a/src/app/qgsmapthemes.cpp b/src/app/qgsmapthemes.cpp index 179ba0654e0..1374cec68f3 100644 --- a/src/app/qgsmapthemes.cpp +++ b/src/app/qgsmapthemes.cpp @@ -42,6 +42,7 @@ QgsMapThemes::QgsMapThemes() mMenu->addAction( QgisApp::instance()->actionHideAllLayers() ); mMenu->addAction( QgisApp::instance()->actionShowSelectedLayers() ); mMenu->addAction( QgisApp::instance()->actionHideSelectedLayers() ); + mMenu->addAction( QgisApp::instance()->actionHideDeselectedLayers() ); mMenu->addSeparator(); mReplaceMenu = new QMenu( tr( "Replace Theme" ) ); diff --git a/src/gui/qgisinterface.h b/src/gui/qgisinterface.h index da8bb93bdf4..6b0485b173f 100644 --- a/src/gui/qgisinterface.h +++ b/src/gui/qgisinterface.h @@ -539,6 +539,12 @@ class GUI_EXPORT QgisInterface : public QObject virtual QAction *actionHideAllLayers() = 0; virtual QAction *actionShowAllLayers() = 0; virtual QAction *actionHideSelectedLayers() = 0; + + /** + * Returns the Hide Deselected Layers action. + * @note added in QGIS 3.0 + */ + virtual QAction *actionHideDeselectedLayers() = 0; virtual QAction *actionShowSelectedLayers() = 0; // Plugin menu actions diff --git a/src/ui/qgisapp.ui b/src/ui/qgisapp.ui index bab69681cc3..e4e5f46a8a3 100644 --- a/src/ui/qgisapp.ui +++ b/src/ui/qgisapp.ui @@ -118,6 +118,7 @@ + @@ -2425,6 +2426,15 @@ Acts on currently active editable layer Hide Selected Layers + + + + :/images/themes/default/mActionHideSelectedLayers.png:/images/themes/default/mActionHideSelectedLayers.png + + + Hide Deselected Layers + +