From 087614afa01f33db0bdbefb38322dd4fa10914bc Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sun, 2 Apr 2017 11:49:38 +0800 Subject: [PATCH] TreeView: fixed disappearing item The problem occurs when a child object is no longer claimed by its former parent. The child tree item is not added back to Document root even if it is the only instance left, which resulting the child object disappearing entirely from the tree view. --- src/Gui/Tree.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 6db5ef7c06..43a6416a17 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -1137,8 +1137,23 @@ void DocumentItem::populateItem(DocumentObjectItem *item, bool refresh) { item->addChild(childItem); } } - for(auto childItem : oldItems) + for(auto childItem : oldItems) { + if (childItem->type() == TreeWidget::ObjectType) { + DocumentObjectItem* obj = static_cast(childItem); + // Add the child item back to document root if it is the only + // instance. Now, because of the lazy loading strategy, this may + // not truely be the last instance of the object. It may belong to + // other parents not expanded yet. We don't want to traverse the + // whole tree to confirm that. Just let it be. If the other + // parent(s) later expanded, this child item will be moved from + // root to its parent. + if(obj->myselves->size()==1) { + this->addChild(childItem); + continue; + } + } delete childItem; + } } void DocumentItem::slotChangeObject(const Gui::ViewProviderDocumentObject& view)