}
}
+ 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
};
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));
}
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;
}
if (aRemoved)
aResult.append(this);
+ if (aToSort)
+ sortChildren();
}
return aResult;
}