Commit 2c6462ba authored by finetjul's avatar finetjul
Browse files

ENH: Add qMRMLTreeView::setCurrentNode()

Similarly to qMRMLTreeView::currentNode(), setCurrentNode abstracts
setCurrentIndex().

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21545 3bd1e089-480b-0410-8dfb-8563597acbee
parent 094b0145
......@@ -156,7 +156,7 @@ public:
QString hideNodesUnaffiliatedWithNodeID()const;
/// Return the scene model used as input if any.
qMRMLSceneModel* sceneModel()const;
Q_INVOKABLE qMRMLSceneModel* sceneModel()const;
public slots:
void setShowHidden(bool);
......
......@@ -363,6 +363,14 @@ vtkMRMLNode* qMRMLTreeView::currentNode()const
return d->SortFilterModel->mrmlNodeFromIndex(this->selectionModel()->currentIndex());
}
//------------------------------------------------------------------------------
void qMRMLTreeView::setCurrentNode(vtkMRMLNode* node)
{
Q_D(const qMRMLTreeView);
QModelIndex nodeIndex = d->SortFilterModel->indexFromMRMLNode(node);
this->setCurrentIndex(nodeIndex);
}
//------------------------------------------------------------------------------
void qMRMLTreeView::onCurrentRowChanged(const QModelIndex& index)
{
......
......@@ -247,6 +247,9 @@ public slots:
/// \sa rootNode(), setRootIndex(), showRootNode
void setRootNode(vtkMRMLNode* root);
/// Change the current view node to \a node.
/// \sa currentNode
void setCurrentNode(vtkMRMLNode* node);
void deleteCurrentNode();
void editCurrentNode();
void renameCurrentNode();
......
......@@ -205,10 +205,12 @@ void qSlicerAnnotationModuleWidget::moveDownSelected()
{
Q_D(qSlicerAnnotationModuleWidget);
const char* mrmlId = d->logic()->MoveAnnotationDown(d->hierarchyTreeView->firstSelectedNode());
const char* mrmlId =
d->logic()->MoveAnnotationDown(d->hierarchyTreeView->firstSelectedNode());
vtkMRMLNode* mrmlNode = this->mrmlScene()->GetNodeByID(mrmlId);
d->hierarchyTreeView->clearSelection();
d->hierarchyTreeView->setSelectedNode(mrmlId);
d->hierarchyTreeView->setCurrentNode(mrmlNode);
}
//-----------------------------------------------------------------------------
......@@ -217,9 +219,10 @@ void qSlicerAnnotationModuleWidget::moveUpSelected()
Q_D(qSlicerAnnotationModuleWidget);
const char* mrmlId = d->logic()->MoveAnnotationUp(d->hierarchyTreeView->firstSelectedNode());
vtkMRMLNode* mrmlNode = this->mrmlScene()->GetNodeByID(mrmlId);
d->hierarchyTreeView->clearSelection();
d->hierarchyTreeView->setSelectedNode(mrmlId);
d->hierarchyTreeView->setCurrentNode(mrmlNode);
}
//-----------------------------------------------------------------------------
......@@ -430,7 +433,9 @@ void qSlicerAnnotationModuleWidget::onAddHierarchyButtonClicked()
this->refreshTree();
if (d->logic()->AddHierarchy())
{
d->hierarchyTreeView->setSelectedNode(d->logic()->GetActiveHierarchyNodeID());
vtkMRMLNode* node = d->logic()->GetMRMLScene()->GetNodeByID(
d->logic()->GetActiveHierarchyNodeID());
d->hierarchyTreeView->setCurrentNode(node);
}
// set expanded state to match hierarchy node
vtkMRMLNode *mrmlNode = this->mrmlScene()->GetNodeByID(d->logic()->GetActiveHierarchyNodeID());
......
......@@ -479,19 +479,6 @@ void qMRMLAnnotationTreeView::mouseMoveEvent(QMouseEvent* e)
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void qMRMLAnnotationTreeView::setSelectedNode(const char* id)
{
Q_D(qMRMLAnnotationTreeView);
vtkMRMLNode* node = this->mrmlScene()->GetNodeByID(id);
if (node)
{
this->setCurrentIndex(d->SortFilterModel->indexFromMRMLNode(node));
}
}
//------------------------------------------------------------------------------
void qMRMLAnnotationTreeView::hideScene()
{
......
......@@ -66,8 +66,6 @@ public:
void selectedAsCollection(vtkCollection* collection);
void setSelectedNode(const char* id);
qMRMLSceneAnnotationModel* annotationModel()const;
public slots:
......
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