mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Delete items from existing tree before building the map from pdmUiTreeOrdering to index
This commit is contained in:
parent
3683dc95cd
commit
aeeb445dae
@ -235,9 +235,28 @@ void PdmUiTreeViewModel::updateSubTreeRecursive(const QModelIndex& existingSubTr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build map for existing items
|
|
||||||
// Detect items to be deleted from existing tree
|
// Detect items to be deleted from existing tree
|
||||||
std::vector<int> indicesToRemoveFromExisting;
|
std::vector<int> indicesToRemoveFromExisting;
|
||||||
|
for (int i = 0; i < existingSubTreeRoot->childCount() ; ++i)
|
||||||
|
{
|
||||||
|
PdmUiTreeOrdering* child = existingSubTreeRoot->child(i);
|
||||||
|
|
||||||
|
std::map<caf::PdmUiItem*, int>::iterator it = sourceTreeMap.find(child->activeItem());
|
||||||
|
if (it == sourceTreeMap.end())
|
||||||
|
{
|
||||||
|
indicesToRemoveFromExisting.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete items with largest index first from existing
|
||||||
|
for (std::vector<int>::reverse_iterator it = indicesToRemoveFromExisting.rbegin(); it != indicesToRemoveFromExisting.rend(); it++)
|
||||||
|
{
|
||||||
|
this->beginRemoveRows(existingSubTreeRootModIdx, *it, *it);
|
||||||
|
existingSubTreeRoot->removeChildren(*it, 1);
|
||||||
|
this->endRemoveRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build map for existing items, now without the deleted items
|
||||||
std::map<caf::PdmUiItem*, int> existingTreeMap;
|
std::map<caf::PdmUiItem*, int> existingTreeMap;
|
||||||
for (int i = 0; i < existingSubTreeRoot->childCount() ; ++i)
|
for (int i = 0; i < existingSubTreeRoot->childCount() ; ++i)
|
||||||
{
|
{
|
||||||
@ -247,12 +266,6 @@ void PdmUiTreeViewModel::updateSubTreeRecursive(const QModelIndex& existingSubTr
|
|||||||
{
|
{
|
||||||
existingTreeMap[child->activeItem()] = i;
|
existingTreeMap[child->activeItem()] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<caf::PdmUiItem*, int>::iterator it = sourceTreeMap.find(child->activeItem());
|
|
||||||
if (it == sourceTreeMap.end())
|
|
||||||
{
|
|
||||||
indicesToRemoveFromExisting.push_back(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PdmUiTreeOrdering newOrdering("dummy", "dummy");
|
PdmUiTreeOrdering newOrdering("dummy", "dummy");
|
||||||
@ -281,13 +294,6 @@ void PdmUiTreeViewModel::updateSubTreeRecursive(const QModelIndex& existingSubTr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete items with largest index first from existing
|
|
||||||
for (std::vector<int>::reverse_iterator it = indicesToRemoveFromExisting.rbegin(); it != indicesToRemoveFromExisting.rend(); it++)
|
|
||||||
{
|
|
||||||
this->beginRemoveRows(existingSubTreeRootModIdx, *it, *it);
|
|
||||||
existingSubTreeRoot->removeChildren(*it, 1);
|
|
||||||
this->endRemoveRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete items with largest index first from source
|
// Delete items with largest index first from source
|
||||||
for (std::vector<int>::reverse_iterator it = indicesToRemoveFromSource.rbegin(); it != indicesToRemoveFromSource.rend(); it++)
|
for (std::vector<int>::reverse_iterator it = indicesToRemoveFromSource.rbegin(); it != indicesToRemoveFromSource.rend(); it++)
|
||||||
|
Loading…
Reference in New Issue
Block a user