From: vsv Date: Fri, 24 Aug 2018 12:35:17 +0000 (+0300) Subject: Issue #2594: sort children if after deletion children have a wrong order. X-Git-Tag: SHAPER_V9_1_0RC1~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7ab96e5d52fe818903f12972ce2b68f374982884;p=modules%2Fshaper.git Issue #2594: sort children if after deletion children have a wrong order. --- diff --git a/src/ModuleBase/ModuleBase_ITreeNode.h b/src/ModuleBase/ModuleBase_ITreeNode.h index 362dad470..fcd6c7bd4 100644 --- a/src/ModuleBase/ModuleBase_ITreeNode.h +++ b/src/ModuleBase/ModuleBase_ITreeNode.h @@ -177,6 +177,27 @@ protected: } } + void sortChildren() { + int i = 0; + ModuleBase_ITreeNode* aNode = 0; + ObjectPtr aObject; + int aIdx; + while (i < myChildren.size()) { + aNode = myChildren.at(i); + aObject = aNode->object(); + if (aObject.get()) { + aIdx = aObject->document()->index(aObject, true); + if (aIdx != i) { + myChildren.removeAll(aNode); + myChildren.insert(aIdx, aNode); + i = 0; + continue; + } + } + i++; + } + } + ModuleBase_ITreeNode* myParent; //!< Parent of the node QTreeNodesList myChildren; //!< Children of the node }; diff --git a/src/PartSet/PartSet_TreeNodes.cpp b/src/PartSet/PartSet_TreeNodes.cpp index 4bbd2b593..81b3fec0f 100644 --- a/src/PartSet/PartSet_TreeNodes.cpp +++ b/src/PartSet/PartSet_TreeNodes.cpp @@ -571,19 +571,23 @@ QTreeNodesList PartSet_FolderNode::objectsDeleted(const DocumentPtr& theDoc, int aIndex; int aId = 0; bool aRemoved = false; + bool aToSort = false; while (aId < myChildren.size()) { ModuleBase_ITreeNode* aNode = myChildren.at(aId); aIndex = aDoc->index(aNode->object(), true); - if ((aIndex == -1) || (aId != aIndex)) { + aToSort |= ((aIndex != -1) && (aId != aIndex)); + if (aIndex == -1) { myChildren.removeAll(aNode); delete aNode; aRemoved = true; - } else + } + else aId++; } if (aRemoved) aResult.append(this); - + if (aToSort) + sortChildren(); foreach(ModuleBase_ITreeNode* aNode, myChildren) { aResult.append(aNode->objectsDeleted(theDoc, theGroup)); } @@ -662,11 +666,13 @@ QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theD int aIndex; int aId = 0; bool aRemoved = false; + bool aToSort = false; while (aId < myChildren.size()) { ModuleBase_ITreeNode* aNode = myChildren.at(aId); if (aNode->object().get()) { aIndex = aDoc->index(aNode->object(), true); - if ((aIndex == -1) || (aId != (aIndex + aNb))) { + aToSort |= ((aIndex != -1) && (aId != (aIndex + aNb))); + if (aIndex == -1) { myChildren.removeAll(aNode); delete aNode; aRemoved = true; @@ -677,6 +683,8 @@ QTreeNodesList PartSet_FeatureFolderNode::objectsDeleted(const DocumentPtr& theD } if (aRemoved) aResult.append(this); + if (aToSort) + sortChildren(); } return aResult; }