Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Distinguish between toggle all and toggle independently
  • Loading branch information
suricactus committed Mar 30, 2020
1 parent 1dc0800 commit 7c9cd0b
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 4 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -298,6 +298,7 @@
<file>themes/default/mActionHelpSponsors.png</file>
<file>themes/default/mActionHideAllLayers.svg</file>
<file>themes/default/mActionToggleAllLayers.svg</file>
<file>themes/default/mActionToggleSelectedLayers.svg</file>
<file>themes/default/mActionHideSelectedLayers.svg</file>
<file>themes/default/mActionHideDeselectedLayers.svg</file>
<file>themes/default/mActionHistory.svg</file>
Expand Down
126 changes: 126 additions & 0 deletions images/themes/default/mActionToggleSelectedLayers.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgisinterface.sip.in
Expand Up @@ -582,6 +582,13 @@ Statistical summary action.
%Docstring
Returns the Toggle Selected Layers action.

.. versionadded:: 3.14
%End

virtual QAction *actionToggleSelectedLayersIndependently() = 0;
%Docstring
Returns the Toggle Selected Layers Independantly action.

.. versionadded:: 3.14
%End

Expand Down
24 changes: 22 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -2651,6 +2651,7 @@ void QgisApp::createActions()
connect( mActionShowSelectedLayers, &QAction::triggered, this, &QgisApp::showSelectedLayers );
connect( mActionHideSelectedLayers, &QAction::triggered, this, &QgisApp::hideSelectedLayers );
connect( mActionToggleSelectedLayers, &QAction::triggered, this, &QgisApp::toggleSelectedLayers );
connect( mActionToggleSelectedLayersIndependently, &QAction::triggered, this, &QgisApp::toggleSelectedLayersIndependently );
connect( mActionHideDeselectedLayers, &QAction::triggered, this, &QgisApp::hideDeselectedLayers );

// Plugin Menu Items
Expand Down Expand Up @@ -7561,9 +7562,28 @@ void QgisApp::toggleSelectedLayers()
QgsDebugMsg( QStringLiteral( "toggling selected layers!" ) );

const auto constSelectedNodes = mLayerTreeView->selectedNodes();
for ( QgsLayerTreeNode *node : constSelectedNodes )
if ( ! constSelectedNodes.isEmpty() )
{
node->setItemVisibilityChecked( ! node->isVisible() );
bool isFirstNodeChecked = constSelectedNodes[0]->itemVisibilityChecked();
for ( QgsLayerTreeNode *node : constSelectedNodes )
{
node->setItemVisibilityChecked( ! isFirstNodeChecked );
}
}
}

//reimplements method from base (gui) class
void QgisApp::toggleSelectedLayersIndependently()
{
QgsDebugMsg( QStringLiteral( "toggling selected layers independently!" ) );

const auto constSelectedNodes = mLayerTreeView->selectedNodes();
if ( ! constSelectedNodes.isEmpty() )
{
for ( QgsLayerTreeNode *node : constSelectedNodes )
{
node->setItemVisibilityChecked( ! node->itemVisibilityChecked() );
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/app/qgisapp.h
Expand Up @@ -545,6 +545,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionShowAllLayers() { return mActionShowAllLayers; }
QAction *actionHideSelectedLayers() { return mActionHideSelectedLayers; }
QAction *actionToggleSelectedLayers() { return mActionToggleSelectedLayers; }
QAction *actionToggleSelectedLayersIndependently() { return mActionToggleSelectedLayersIndependently; }
QAction *actionHideDeselectedLayers() { return mActionHideDeselectedLayers; }
QAction *actionShowSelectedLayers() { return mActionShowSelectedLayers; }

Expand Down Expand Up @@ -1413,8 +1414,10 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void showAllLayers();
//reimplements method from base (gui) class
void hideSelectedLayers();
//! Toggles the visibility of the selected layers
//! Toggles the visibility of the selected layers depending on the state of the first layer in selection (first clicked)
void toggleSelectedLayers();
//! Toggles the visibility of the selected layers independently
void toggleSelectedLayersIndependently();
//! Hides any layers which are not selected
void hideDeselectedLayers();
//reimplements method from base (gui) class
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisappinterface.cpp
Expand Up @@ -685,6 +685,7 @@ QAction *QgisAppInterface::actionHideAllLayers() { return qgis->actionHideAllLay
QAction *QgisAppInterface::actionShowAllLayers() { return qgis->actionShowAllLayers(); }
QAction *QgisAppInterface::actionHideSelectedLayers() { return qgis->actionHideSelectedLayers(); }
QAction *QgisAppInterface::actionToggleSelectedLayers() { return qgis->actionToggleSelectedLayers(); }
QAction *QgisAppInterface::actionToggleSelectedLayersIndependently() { return qgis->actionToggleSelectedLayersIndependently(); }
QAction *QgisAppInterface::actionHideDeselectedLayers() { return qgis->actionHideDeselectedLayers(); }
QAction *QgisAppInterface::actionShowSelectedLayers() { return qgis->actionShowSelectedLayers(); }

Expand Down
1 change: 1 addition & 0 deletions src/app/qgisappinterface.h
Expand Up @@ -255,6 +255,7 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
QAction *actionShowAllLayers() override;
QAction *actionHideSelectedLayers() override;
QAction *actionToggleSelectedLayers() override;
QAction *actionToggleSelectedLayersIndependently() override;
QAction *actionHideDeselectedLayers() override;
QAction *actionShowSelectedLayers() override;
QAction *actionManagePlugins() override;
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmapthemes.cpp
Expand Up @@ -43,6 +43,7 @@ QgsMapThemes::QgsMapThemes()
mMenu->addAction( QgisApp::instance()->actionShowSelectedLayers() );
mMenu->addAction( QgisApp::instance()->actionHideSelectedLayers() );
mMenu->addAction( QgisApp::instance()->actionToggleSelectedLayers() );
mMenu->addAction( QgisApp::instance()->actionToggleSelectedLayersIndependently() );
mMenu->addAction( QgisApp::instance()->actionHideDeselectedLayers() );
mMenu->addSeparator();

Expand Down
3 changes: 2 additions & 1 deletion src/gui/layertree/qgslayertreeview.cpp
Expand Up @@ -513,9 +513,10 @@ void QgsLayerTreeView::keyPressEvent( QKeyEvent *event )

if ( ! constSelectedNodes.isEmpty() )
{
bool isFirstNodeChecked = constSelectedNodes[0]->itemVisibilityChecked();
for ( QgsLayerTreeNode *node : constSelectedNodes )
{
node->setItemVisibilityChecked( ! node->isVisible() );
node->setItemVisibilityChecked( ! isFirstNodeChecked );
}

// if we call the original keyPress handler, the current item will be checked to the original state yet again
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgisinterface.h
Expand Up @@ -517,6 +517,12 @@ class GUI_EXPORT QgisInterface : public QObject
*/
virtual QAction *actionToggleSelectedLayers() = 0;

/**
* Returns the Toggle Selected Layers Independantly action.
* \since QGIS 3.14
*/
virtual QAction *actionToggleSelectedLayersIndependently() = 0;

/**
* Returns the Hide Deselected Layers action.
* \since QGIS 3.0
Expand Down
10 changes: 10 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -152,6 +152,7 @@
<addaction name="mActionShowSelectedLayers"/>
<addaction name="mActionHideSelectedLayers"/>
<addaction name="mActionToggleSelectedLayers"/>
<addaction name="mActionIndependentlyToggleSelectedLayers"/>
<addaction name="mActionHideDeselectedLayers"/>
<addaction name="separator"/>
</widget>
Expand Down Expand Up @@ -2675,6 +2676,10 @@ Acts on the currently active layer only.</string>
</property>
</action>
<action name="mActionToggleSelectedLayers">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionToggleSelectedLayers.svg</normaloff>:/images/themes/default/mActionToggleSelectedLayers.svg</iconset>
</property>
<property name="text">
<string>Toggle Selected Layers</string>
</property>
Expand All @@ -2685,6 +2690,11 @@ Acts on the currently active layer only.</string>
<enum>Qt::WidgetShortcut</enum>
</property>
</action>
<action name="mActionToggleSelectedLayersIndependently">
<property name="text">
<string>Toggle Selected Layers Independently</string>
</property>
</action>
<action name="mActionHideDeselectedLayers">
<property name="icon">
<iconset resource="../../images/images.qrc">
Expand Down

0 comments on commit 7c9cd0b

Please sign in to comment.