Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
nyalldawson committed Dec 28, 2016
1 parent c83426e commit 4f73c28
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/gui/qgisinterface.sip
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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

Expand Down Expand Up @@ -5783,6 +5784,17 @@ void QgisApp::hideSelectedLayers()
}
}

void QgisApp::hideDeselectedLayers()
{
QList<QgsLayerTreeLayer*> 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()
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisappinterface.cpp
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisappinterface.h
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmapthemes.cpp
Expand Up @@ -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" ) );
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgisinterface.h
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -118,6 +118,7 @@
<addaction name="mActionHideAllLayers"/>
<addaction name="mActionShowSelectedLayers"/>
<addaction name="mActionHideSelectedLayers"/>
<addaction name="mActionHideDeselectedLayers"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="mLayerMenu">
Expand Down Expand Up @@ -2425,6 +2426,15 @@ Acts on currently active editable layer</string>
<string>Hide Selected Layers</string>
</property>
</action>
<action name="mActionHideDeselectedLayers">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionHideSelectedLayers.png</normaloff>:/images/themes/default/mActionHideSelectedLayers.png</iconset>
</property>
<property name="text">
<string>Hide Deselected Layers</string>
</property>
</action>
<action name="mActionNewMemoryLayer">
<property name="icon">
<iconset resource="../../images/images.qrc">
Expand Down

0 comments on commit 4f73c28

Please sign in to comment.