Salome HOME
Updated copyright comment
[modules/shaper.git] / src / ModuleBase / ModuleBase_ITreeNode.h
index 77d1d2a46fa6fb71b35ba5e52669f9eab5c59198..617b80ac0776ad63f1b4ee8aea37e410e7794709 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #ifndef ModuleBase_ITreeNode_H
 #include <QIcon>
 #include <QVariant>
 
+#ifdef _MSC_VER
+#pragma warning(disable: 4100)
+#endif
+
 class ModuleBase_ITreeNode;
 class ModuleBase_IWorkshop;
 
@@ -183,11 +186,20 @@ protected:
       ModuleBase_ITreeNode* aNode = 0;
       ObjectPtr aObject;
       int aIdx;
-      while (i < myChildren.size()) {
+      int aCount = 0;
+      int aSize = myChildren.size();
+      int aMaxCount = aSize * aSize;
+      int aShift = 0;
+      while (i < aSize) {
+        aCount++;
+        // To avoid unlimited cycling
+        if (aCount > aMaxCount)
+          break;
+
         aNode = myChildren.at(i);
         aObject = aNode->object();
         if (aObject.get()) {
-          aIdx = aObject->document()->index(aObject, true);
+          aIdx = aObject->document()->index(aObject, true) + aShift;
           if (aIdx != i) {
             myChildren.removeAll(aNode);
             myChildren.insert(aIdx, aNode);
@@ -195,6 +207,8 @@ protected:
             continue;
           }
         }
+        else
+          aShift++;
         i++;
       }
     }