Commit 47b664f3 authored by naucoin's avatar naucoin
Browse files

BUG: stop the annotation tree view from auto expanding lists

Don't use calling setMRMLScene on the tree view to refresh the tree, 
as it resets the expand level on the tree view, only call it when 
the scene is different.
This stopped the auto added top level all annotations list and the fiducials/ruler
list nodes from expanding, so invoke an event from the logic when those default
hierarchy nodes are added to trigger the tree to expand them (using the
Expanded value on the hierarchy node).
Also expand the hierarchy node when it's added by the user via the add
hierarchy button.

Fixes issue #1735


git-svn-id: http://svn.slicer.org/Slicer4/trunk@21531 3bd1e089-480b-0410-8dfb-8563597acbee
parent bc6d19e2
......@@ -37,7 +37,9 @@
#include <vtkSmartPointer.h>
// MRML includes
#include "vtkMRMLDisplayableHierarchyNode.h"
#include "vtkMRMLInteractionNode.h"
#include "vtkMRMLNode.h"
#include "vtkMRMLSelectionNode.h"
//-----------------------------------------------------------------------------
......@@ -150,6 +152,10 @@ void qSlicerAnnotationModuleWidgetPrivate::setupUi(qSlicerWidget* widget)
q, SLOT(updateActiveHierarchyLabel()));
q->qvtkConnect(this->logic(), vtkSlicerAnnotationModuleLogic::RefreshRequestEvent,
q, SLOT(refreshTree()));
// listen to the logic for when it adds a new hierarchy node that has to be
// expanded
q->qvtkConnect(this->logic(), vtkSlicerAnnotationModuleLogic::HierarchyNodeAddedEvent,
q, SLOT(onHierarchyNodeAddedEvent(vtkObject*,vtkObject*)));
// update from the mrml scene
q->refreshTree();
......@@ -426,6 +432,22 @@ void qSlicerAnnotationModuleWidget::onAddHierarchyButtonClicked()
{
d->hierarchyTreeView->setSelectedNode(d->logic()->GetActiveHierarchyNodeID());
}
// set expanded state to match hierarchy node
vtkMRMLNode *mrmlNode = this->mrmlScene()->GetNodeByID(d->logic()->GetActiveHierarchyNodeID());
if (mrmlNode)
{
QModelIndex hierarchyIndex = d->hierarchyTreeView->sortFilterProxyModel()->indexFromMRMLNode(mrmlNode);
vtkMRMLDisplayableHierarchyNode *hierarchyNode = vtkMRMLDisplayableHierarchyNode::SafeDownCast(mrmlNode);
if (hierarchyNode)
{
d->hierarchyTreeView->setExpanded(hierarchyIndex, hierarchyNode->GetExpanded());
}
else
{
// otherwise just expand by default
d->hierarchyTreeView->expand(hierarchyIndex);
}
}
}
//-----------------------------------------------------------------------------
......@@ -461,13 +483,45 @@ void qSlicerAnnotationModuleWidget::refreshTree()
// scene is updating, return
return;
}
// this gets called on scene closed, can we make sure that the widget is
// visible?
d->hierarchyTreeView->setMRMLScene(d->logic()->GetMRMLScene());
// don't reset unless scene is different as it also resets the expanded
// level on the tree
if (d->hierarchyTreeView->mrmlScene() != d->logic()->GetMRMLScene())
{
// this gets called on scene closed, can we make sure that the widget is
// visible?
d->hierarchyTreeView->setMRMLScene(d->logic()->GetMRMLScene());
}
d->hierarchyTreeView->hideScene();
}
//-----------------------------------------------------------------------------
void qSlicerAnnotationModuleWidget::onHierarchyNodeAddedEvent(vtkObject *vtkNotUsed(caller), vtkObject *callData)
{
Q_D(qSlicerAnnotationModuleWidget);
// the call data should be the annotation hierarchy node that was just
// added, passed along from the logic
if (callData == NULL)
{
return;
}
vtkMRMLNode *node = NULL;
node = reinterpret_cast<vtkMRMLNode*>(callData);
if (node == NULL)
{
return;
}
// get the model index of the hierarchy node in the tree
QModelIndex hierarchyIndex = d->hierarchyTreeView->sortFilterProxyModel()->indexFromMRMLNode(node);
vtkMRMLDisplayableHierarchyNode *hierarchyNode = vtkMRMLDisplayableHierarchyNode::SafeDownCast(node);
if (hierarchyNode)
{
// set the expanded state to match the node
d->hierarchyTreeView->setExpanded(hierarchyIndex, hierarchyNode->GetExpanded());
}
}
//-----------------------------------------------------------------------------
// Annotation SnapShot functionality
......
......@@ -12,6 +12,7 @@ class qSlicerAnnotationModulePropertyDialog;
class qSlicerAnnotationModuleReportDialog;
class qSlicerAnnotationModuleWidgetPrivate;
class vtkMRMLInteractionNode;
class vtkMRMLNode;
/// \ingroup Slicer_QtModules_Annotation
class Q_SLICER_QTMODULES_ANNOTATIONS_EXPORT qSlicerAnnotationModuleWidget :
......@@ -50,7 +51,10 @@ public:
protected:
public slots:
/// a public slot that will refresh the tree view
void refreshTree();
/// a public slot that will expand a newly added hierarchy node item
void onHierarchyNodeAddedEvent(vtkObject *caller, vtkObject *obj);
/// a public slot allowing other modules to open up the screen capture
/// dialog
......
......@@ -2795,6 +2795,7 @@ char * vtkSlicerAnnotationModuleLogic::GetTopLevelHierarchyNodeID(vtkMRMLNode* n
{
vtkErrorMacro("GetTopLevelHierarchyNodeID: error adding a display node for new top level node " << toplevelNodeID);
}
this->InvokeEvent(HierarchyNodeAddedEvent, toplevelNode);
toplevelNode->Delete();
}
else
......@@ -2871,6 +2872,7 @@ char * vtkSlicerAnnotationModuleLogic::GetTopLevelHierarchyNodeIDForNodeClass(vt
// make it a child of the top annotation hierarchy
toplevelNode->SetParentNodeID(this->GetTopLevelHierarchyNodeID());
this->GetMRMLScene()->AddNode(toplevelNode);
this->InvokeEvent(HierarchyNodeAddedEvent, toplevelNode);
toplevelNodeID = toplevelNode->GetID();
if (this->AddDisplayNodeForHierarchyNode(toplevelNode) == NULL)
{
......@@ -2974,6 +2976,7 @@ char * vtkSlicerAnnotationModuleLogic::GetTopLevelHierarchyNodeIDForNodeClass(vt
this->GetMRMLScene()->GetUniqueNameByString("List"));
this->GetMRMLScene()->AddNode(hierarchyNode);
this->InvokeEvent(HierarchyNodeAddedEvent, hierarchyNode);
}
else
......
......@@ -21,7 +21,8 @@ class VTK_SLICER_ANNOTATIONS_MODULE_LOGIC_EXPORT vtkSlicerAnnotationModuleLogic
{
public:
enum Events{
RefreshRequestEvent = vtkCommand::UserEvent
RefreshRequestEvent = vtkCommand::UserEvent,
HierarchyNodeAddedEvent
};
static vtkSlicerAnnotationModuleLogic *New();
vtkTypeRevisionMacro(vtkSlicerAnnotationModuleLogic,vtkSlicerModuleLogic);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment