Salome HOME
Modification for bug 22451: MoveUp/MoveDown items of ObjectBrowser
authorvsv <vsv@opencascade.com>
Mon, 23 Dec 2013 09:48:32 +0000 (09:48 +0000)
committervsv <vsv@opencascade.com>
Mon, 23 Dec 2013 09:48:32 +0000 (09:48 +0000)
src/SUIT/SUIT_DataObject.cxx
src/SUIT/SUIT_DataObject.h

index dd7c09e8387e5a684f9b1581ad18b5005b6beaee..182f5eb494acb68f3eec00a05b050507290e49c3 100755 (executable)
@@ -138,6 +138,25 @@ int SUIT_DataObject::childPos( const SUIT_DataObject* obj ) const
   return myChildren.indexOf( (SUIT_DataObject*)obj );
 }
 
+/*!
+  \brief Moves the child position from current to new one.
+  \param theObj child object
+  \param theNewPos child objectnew position in the children list
+
+*/
+void SUIT_DataObject::moveChildPos( SUIT_DataObject* theObj, int theNewPos)
+{
+  if (myChildren.size() <= 1)  return;
+
+  int aNewPos = theNewPos;
+  if (aNewPos < 0) aNewPos = 0;
+  if (aNewPos > (myChildren.size() - 1)) aNewPos = myChildren.size() - 1;
+
+  if (myChildren.removeOne(theObj))
+    myChildren.insert(aNewPos, theObj);
+}
+
+
 /*!
   \brief Get child object by the specified index.
   \param idx child object index
@@ -180,6 +199,16 @@ int SUIT_DataObject::position() const
   return myParent ? myParent->childPos( this ) : 0;
 }
 
+/*!
+  \brief Sets new position of the object in parent's list
+*/
+void SUIT_DataObject::setPosition(int theNewPos)
+{
+  if (theNewPos == position())  return;
+  if (!myParent)  return;
+  myParent->moveChildPos(this, theNewPos);
+}
+
 /*!
   \brief Get the next sibling data object in the children list.
   \return child object or 0 if there is no next sibling
index ab44bbdbe39fa5c81b5ee11f8d179588471d119b..b5f62d98652469043bd01f318702c2249dad38ad 100755 (executable)
@@ -76,9 +76,11 @@ public:
 
   int                         childCount() const;
   int                         childPos( const SUIT_DataObject* ) const;
+  void                        moveChildPos( SUIT_DataObject*, int );
   SUIT_DataObject*            childObject( const int ) const;
   int                         level() const;
   int                         position() const;
+  void                        setPosition(int);
 
   SUIT_DataObject*            nextBrother() const;
   SUIT_DataObject*            prevBrother() const;