1 #include "SUIT_DataObjectIterator.h"
6 SUIT_DataObjectIterator::SUIT_DataObjectIterator( SUIT_DataObject* root, const int det, const bool fromTrueRoot )
11 if ( myRoot && fromTrueRoot )
12 myRoot = myRoot->root();
14 myCurrent = myExtremeChild = myRoot;
18 Gets parent for object \a obj.
20 SUIT_DataObject* SUIT_DataObjectIterator::parent( SUIT_DataObject* obj ) const
22 SUIT_DataObject* result = 0;
23 if ( obj && obj != myRoot )
24 result = obj->parent();
31 void SUIT_DataObjectIterator::operator++()
33 SUIT_DataObject* aNext = 0;
34 SUIT_DataObject* aParent = 0;
40 if ( myDetourType == DepthLeft || myDetourType == DepthRight )
42 //Depth detour algorithm
43 if ( myCurrent->myChildren.count() > 0 )
45 myCurrent = extreme( myCurrent->myChildren, myDetourType == DepthLeft );
51 aParent = parent( myCurrent );
54 myCurrent = 0; //the tree is passed completely
59 aParent->myChildren.find( myCurrent );
60 if ( myDetourType == DepthLeft )
61 myCurrent = aParent->myChildren.next();
63 myCurrent = aParent->myChildren.prev();
75 else if ( myDetourType == BreadthLeft || myDetourType == BreadthRight )
77 //Breadth detour algorithm
78 aNext = globalSibling( myCurrent, myDetourType == BreadthLeft );
82 for ( SUIT_DataObject* cur = myExtremeChild; cur && !myCurrent; cur = globalSibling( cur, myDetourType == BreadthLeft ) )
84 if ( cur->myChildren.count() > 0 )
86 myExtremeChild = extreme( cur->myChildren, myDetourType == BreadthLeft );
87 myCurrent = myExtremeChild;
99 Gets current data object.
101 SUIT_DataObject* SUIT_DataObjectIterator::current() const
107 Gets depth of current lavel.
109 int SUIT_DataObjectIterator::depth() const
111 return myCurrentLevel;
117 int SUIT_DataObjectIterator::detour() const
123 Gets global sibling for object \a obj
125 SUIT_DataObject* SUIT_DataObjectIterator::globalSibling( SUIT_DataObject* obj, bool next ) const
127 SUIT_DataObject* par;
129 if ( obj && ( par = parent( obj ) ) )
131 par->myChildren.find( obj );
132 if ( par->myChildren.next() )
133 return par->myChildren.current();
136 for ( ; par; par = globalSibling( par, next ) )
138 if ( par->myChildren.count() > 0 )
139 return extreme( par->myChildren, next );
149 * Gets first or last data object from list.
150 * Get firls, if \a FromLeft == true, else last.
152 SUIT_DataObject* SUIT_DataObjectIterator::extreme( DataObjectList& aList, bool FromLeft ) const
155 return aList.getFirst();
157 return aList.getLast();
163 SUIT_DataObjectLevelIterator::SUIT_DataObjectLevelIterator( SUIT_DataObject* root,
164 int start, int end, bool LeftToRight )
165 : SUIT_DataObjectIterator( root, LeftToRight ? BreadthLeft : BreadthRight )
167 myStartLevel = start;
171 myEndLevel = myStartLevel;
173 while ( current() && depth() < myStartLevel )
174 SUIT_DataObjectIterator::operator++();
180 void SUIT_DataObjectLevelIterator::operator++()
184 SUIT_DataObjectIterator::operator++();
185 if ( depth() > myEndLevel )