Permalink
Browse files

ENH: Add toggle visibility for multi-select in Data module

It is useful to be able to change the visibility of multiple selected items in the Data module (Subject hierarchy tab). So far only the Delete action was visible on multiple selection. This commit adds a "Toggle visibility" action that toggles visibility on the selected items. To avoid multiple toggling of the same item, if any of the selected item's parents is also selected, then the child item is not toggled, only the parent.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@27578 3bd1e089-480b-0410-8dfb-8563597acbee
  • Loading branch information...
cpinter
cpinter committed Nov 29, 2018
1 parent b480ddf commit 40bc3970d2ad604661c812a6a9b6e9b771d5ff5d
@@ -91,6 +91,7 @@ class qMRMLSubjectHierarchyTreeViewPrivate
QAction* RenameAction;
QAction* DeleteAction;
QAction* EditAction;
QAction* ToggleVisibilityAction;
QList<QAction*> SelectPluginActions;
QMenu* SelectPluginSubMenu;
QActionGroup* SelectPluginActionGroup;
@@ -130,6 +131,7 @@ qMRMLSubjectHierarchyTreeViewPrivate::qMRMLSubjectHierarchyTreeViewPrivate(qMRML
, RenameAction(NULL)
, DeleteAction(NULL)
, EditAction(NULL)
, ToggleVisibilityAction(NULL)
, SelectPluginSubMenu(NULL)
, SelectPluginActionGroup(NULL)
, ExpandToDepthAction(NULL)
@@ -195,6 +197,10 @@ void qMRMLSubjectHierarchyTreeViewPrivate::init()
this->NodeMenu->addAction(this->EditAction);
QObject::connect(this->EditAction, SIGNAL(triggered()), q, SLOT(editCurrentItem()));
this->ToggleVisibilityAction = new QAction("Toggle visibility", this->NodeMenu);
this->NodeMenu->addAction(this->ToggleVisibilityAction);
QObject::connect(this->ToggleVisibilityAction, SIGNAL(triggered()), q, SLOT(toggleVisibilityOfSelectedItems()));
this->SceneMenu = new QMenu(q);
this->SceneMenu->setObjectName("sceneMenuTreeView");
@@ -948,9 +954,10 @@ void qMRMLSubjectHierarchyTreeView::populateContextMenuForItem(vtkIdType itemID)
if ( d->SelectedItems.size() > 1
&& itemID && itemID != d->SubjectHierarchyNode->GetSceneItemID() )
{
// Multi-selection: only show delete action
// Multi-selection: only show delete and toggle visibility actions
d->EditAction->setVisible(false);
d->RenameAction->setVisible(false);
d->ToggleVisibilityAction->setVisible(true);
d->SelectPluginSubMenu->menuAction()->setVisible(false);
// Hide all plugin context menu actions
@@ -974,11 +981,15 @@ void qMRMLSubjectHierarchyTreeView::populateContextMenuForItem(vtkIdType itemID)
if (!currentItemID || currentItemID == d->SubjectHierarchyNode->GetSceneItemID())
{
d->EditAction->setVisible(false);
d->RenameAction->setVisible(false);
d->ToggleVisibilityAction->setVisible(false);
d->SelectPluginSubMenu->menuAction()->setVisible(false);
}
else
{
d->EditAction->setVisible(d->EditActionVisible);
d->RenameAction->setVisible(true);
d->ToggleVisibilityAction->setVisible(false);
d->SelectPluginSubMenu->menuAction()->setVisible(true);
}
@@ -1223,6 +1234,45 @@ void qMRMLSubjectHierarchyTreeView::deleteSelectedItems()
}
}
//--------------------------------------------------------------------------
void qMRMLSubjectHierarchyTreeView::toggleVisibilityOfSelectedItems()
{
Q_D(qMRMLSubjectHierarchyTreeView);
if (!d->SubjectHierarchyNode)
{
qCritical() << Q_FUNC_INFO << ": Invalid subject hierarchy";
return;
}
// Remove items from the list whose ancestor item is also contained
// to prevent toggling visibility multiple times on the same item
QList<vtkIdType> consolidatedItemIDs(d->SelectedItems);
foreach (vtkIdType itemID, d->SelectedItems)
{
// Get children recursively for current item
std::vector<vtkIdType> childItemIDs;
d->SubjectHierarchyNode->GetItemChildren(itemID, childItemIDs, true);
// If any of the current item's children is also in the list,
// then remove that child item from the consolidated list
std::vector<vtkIdType>::iterator childIt;
for (childIt=childItemIDs.begin(); childIt!=childItemIDs.end(); ++childIt)
{
vtkIdType childItemID = (*childIt);
if (d->SelectedItems.contains(childItemID))
{
consolidatedItemIDs.removeOne(childItemID);
}
}
}
// Toggle visibility on the remaining items
foreach (vtkIdType itemID, consolidatedItemIDs)
{
this->toggleSubjectHierarchyItemVisibility(itemID);
}
}
//--------------------------------------------------------------------------
void qMRMLSubjectHierarchyTreeView::expandToDepthFromContextMenu()
{
@@ -129,6 +129,8 @@ public slots:
void renameCurrentItem();
/// Delete selected subject hierarchy items and associated data nodes
void deleteSelectedItems();
/// Toggle visibility of selected subject hierarchy items
void toggleVisibilityOfSelectedItems();
/// Edit properties of current item
virtual void editCurrentItem();

0 comments on commit 40bc397

Please sign in to comment.