Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix subject hierarchy table showing nodes removed during batch processing #6394

Merged
merged 1 commit into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -810,60 +810,6 @@ void qMRMLSubjectHierarchyModel::rebuildFromSubjectHierarchy()
emit subjectHierarchyUpdated();
}

//------------------------------------------------------------------------------
void qMRMLSubjectHierarchyModel::updateFromSubjectHierarchy()
{
Q_D(qMRMLSubjectHierarchyModel);

if (!d->SubjectHierarchyNode)
{
// Remove all items
const int oldColumnCount = this->columnCount();
this->removeRows(0, this->rowCount());
this->setColumnCount(oldColumnCount);
return;
}
else if (!this->subjectHierarchySceneItem())
{
this->rebuildFromSubjectHierarchy();
return;
}
else
{
// Update the scene item index in case subject hierarchy node has changed
this->subjectHierarchySceneItem()->setData(
QVariant::fromValue(d->SubjectHierarchyNode->GetSceneItemID()), qMRMLSubjectHierarchyModel::SubjectHierarchyItemIDRole );
d->RowCache[d->SubjectHierarchyNode->GetSceneItemID()] = this->subjectHierarchySceneItem()->index();
}

// Get all subject hierarchy items
std::vector<vtkIdType> allItemIDs;
d->SubjectHierarchyNode->GetItemChildren(d->SubjectHierarchyNode->GetSceneItemID(), allItemIDs, true);

// Update all items
for (std::vector<vtkIdType>::iterator itemIt=allItemIDs.begin(); itemIt!=allItemIDs.end(); ++itemIt)
{
vtkIdType itemID = (*itemIt);
for (int col=0; col<this->columnCount(); ++col)
{
QStandardItem* item = this->itemFromSubjectHierarchyItem(itemID, col);
this->updateItemFromSubjectHierarchyItem(item, itemID, col);
}
}

// Update expanded states (during inserting the update calls did not find valid indices, so
// expand and collapse statuses were not set in the tree view)
for (std::vector<vtkIdType>::iterator itemIt=allItemIDs.begin(); itemIt!=allItemIDs.end(); ++itemIt)
{
vtkIdType itemID = (*itemIt);
// Expanded states are handled with the name column
QStandardItem* item = this->itemFromSubjectHierarchyItem(itemID, this->nameColumn());
this->updateItemDataFromSubjectHierarchyItem(item, itemID, this->nameColumn());
}

emit subjectHierarchyUpdated();
}

//------------------------------------------------------------------------------
QStandardItem* qMRMLSubjectHierarchyModel::insertSubjectHierarchyItem(vtkIdType itemID)
{
Expand Down Expand Up @@ -1623,7 +1569,7 @@ void qMRMLSubjectHierarchyModel::onMRMLSceneStartBatchProcess(vtkMRMLScene* scen
void qMRMLSubjectHierarchyModel::onMRMLSceneEndBatchProcess(vtkMRMLScene* scene)
{
Q_UNUSED(scene);
this->updateFromSubjectHierarchy();
this->rebuildFromSubjectHierarchy();
}

//------------------------------------------------------------------------------
Expand Down
Expand Up @@ -217,11 +217,7 @@ protected slots:
virtual void setSubjectHierarchyNode(vtkMRMLSubjectHierarchyNode* shNode);

/// Rebuild model from scratch.
/// This is a hard-update that is uses more resources. Use sparingly.
virtual void rebuildFromSubjectHierarchy();
/// Updates properties in the model based on subject hierarchy.
/// This is a soft update that is quick. Calls \sa rebuildFromSubjectHierarchy if necessary.
virtual void updateFromSubjectHierarchy();

virtual QStandardItem* insertSubjectHierarchyItem(vtkIdType itemID);
virtual QStandardItem* insertSubjectHierarchyItem(vtkIdType itemID, QStandardItem* parent, int row=-1);
Expand Down
Expand Up @@ -68,7 +68,7 @@ class Q_SLICER_MODULE_SUBJECTHIERARCHY_WIDGETS_EXPORT qMRMLSubjectHierarchyModel
virtual ~qMRMLSubjectHierarchyModelPrivate();
void init();

/// This method is called by qMRMLSubjectHierarchyModel::updateFromSubjectHierarchy() to speed up
/// This method is called by qMRMLSubjectHierarchyModel::rebuildFromSubjectHierarchy() to speed up
/// the loading. By explicitly specifying the \a index, it skips item lookup within their parents
/// happening in qMRMLSubjectHierarchyModel::subjectHierarchyItemIndex(vtkIdType).
virtual QStandardItem* insertSubjectHierarchyItem(vtkIdType itemID, int index);
Expand Down