From: vsv Date: Mon, 23 Dec 2013 09:48:32 +0000 (+0000) Subject: Modification for bug 22451: MoveUp/MoveDown items of ObjectBrowser X-Git-Tag: V7_4_0a1~33 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=94857ce574e1d6c0ffa602fd7f1a6dfd8546bf8c;p=modules%2Fgui.git Modification for bug 22451: MoveUp/MoveDown items of ObjectBrowser --- diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index dd7c09e83..182f5eb49 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -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 diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index ab44bbdbe..b5f62d986 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -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;