1 #include "SUIT_DataObject.h"
5 #include "SUIT_DataObjectKey.h"
7 #include <iostream> // for cout in dump()
13 SUIT_DataObject::SUIT_DataObject( SUIT_DataObject* p )
18 myChildren.setAutoDelete( true );
27 SUIT_DataObject::~SUIT_DataObject()
29 SUIT_DataObject* p = myParent;
34 p->removeChild( this );
36 for ( QPtrListIterator<SUIT_DataObject> it( myChildren ); it.current(); ++it )
37 it.current()->myParent = 0;
43 Returns the root object.
46 SUIT_DataObject* SUIT_DataObject::root() const
48 return parent() ? parent()->root() : (SUIT_DataObject*)this;
52 Returns the first child object.
55 SUIT_DataObject* SUIT_DataObject::firstChild() const
57 SUIT_DataObject* child = 0;
58 if ( !myChildren.isEmpty() )
59 child = myChildren.getFirst();
64 Returns the last child object.
67 SUIT_DataObject* SUIT_DataObject::lastChild() const
69 SUIT_DataObject* child = 0;
70 if ( !myChildren.isEmpty() )
71 child = myChildren.getLast();
76 Returns the number of the child objects.
79 int SUIT_DataObject::childCount() const
81 return myChildren.count();
85 Returns the index of the specified object in the child list or -1.
88 int SUIT_DataObject::childPos( const SUIT_DataObject* obj ) const
93 for ( DataObjectListIterator it( myChildren ); it.current() && res == -1; ++it, i++ )
95 if ( it.current() == obj )
103 Returns the child object with specified index.
106 SUIT_DataObject* SUIT_DataObject::childObject( const int idx ) const
108 SUIT_DataObject* child = 0;
110 if ( idx>= 0 && idx < (int)myChildren.count() )
112 SUIT_DataObject* that = (SUIT_DataObject*)this;
113 child = that->myChildren.at( idx );
120 Returns the next data object in the child list of the parent.
123 SUIT_DataObject* SUIT_DataObject::nextBrother() const
125 return myParent ? myParent->childObject( myParent->childPos( this ) + 1 ) : 0;
129 Returns the previous data object in the child list of the parent.
132 SUIT_DataObject* SUIT_DataObject::prevBrother() const
134 return myParent ? myParent->childObject( myParent->childPos( this ) - 1 ) : 0;
138 Returns 'true' if the object will delete children during destroying
141 bool SUIT_DataObject::autoDeleteChildren() const
143 return myChildren.autoDelete();
147 Specify should the object delete children during destroying
150 void SUIT_DataObject::setAutoDeleteChildren( const bool on )
152 myChildren.setAutoDelete( on );
156 Returns the list of the child objects. if 'rec' is 'true' then function get all sub children.
159 void SUIT_DataObject::children( DataObjectList& lst, const bool rec ) const
161 for ( DataObjectListIterator it( myChildren ); it.current(); ++it )
163 lst.append( it.current() );
165 it.current()->children( lst, rec );
170 Returns the list of the child objects. if 'rec' is 'true' then function get all sub children.
173 DataObjectList SUIT_DataObject::children( const bool rec )
176 children( lst, rec );
181 Append new child object to the end of the children list
184 void SUIT_DataObject::appendChild( SUIT_DataObject* theObj )
186 insertChild( theObj, myChildren.count() );
190 Insert new child object to the children list at specified position
193 void SUIT_DataObject::insertChild( SUIT_DataObject* theObj, int thePosition )
195 if ( !theObj || myChildren.find( theObj ) != -1 )
198 int pos = thePosition < 0 ? myChildren.count() : thePosition;
199 myChildren.insert( QMIN( pos, (int)myChildren.count() ), theObj );
200 theObj->setParent( this );
204 Removes the specified child object reference.
207 void SUIT_DataObject::removeChild( SUIT_DataObject* theObj )
212 bool ad = myChildren.autoDelete();
213 myChildren.setAutoDelete( false );
215 if ( myChildren.remove( theObj ) )
216 theObj->setParent( 0 );
218 myChildren.setAutoDelete( ad );
222 Replaces the specified child object by another object.
225 bool SUIT_DataObject::replaceChild( SUIT_DataObject* src, SUIT_DataObject* trg, const bool del )
230 int idx = childPos( trg );
233 int pos = childPos( src );
237 insertChild( trg, idx );
241 insertChild( trg, pos );
251 Set the parent object. Remove itself from current parent children
252 and append itself to the new parent children list.
255 void SUIT_DataObject::setParent( SUIT_DataObject* theParent )
257 if ( theParent == parent() )
261 parent()->removeChild( this );
263 myParent = theParent;
266 parent()->appendChild( this );
270 Returns the parent object.
273 SUIT_DataObject* SUIT_DataObject::parent() const
280 Connect to signal destroyed( SUIT_DataObject* ).
283 bool SUIT_DataObject::connect( QObject* reciever, const char* slot )
285 if ( !reciever || !slot )
289 mySignal = new Signal( this );
291 QObject::disconnect( mySignal, SIGNAL( destroyed( SUIT_DataObject* ) ), reciever, slot );
292 return QObject::connect( mySignal, SIGNAL( destroyed( SUIT_DataObject* ) ), reciever, slot );
296 Disconnect from signal destroyed( SUIT_DataObject* ).
299 bool SUIT_DataObject::disconnect( QObject* reciever, const char* slot )
301 if ( !reciever || !slot )
307 return QObject::disconnect( mySignal, SIGNAL( destroyed( SUIT_DataObject* ) ), reciever, slot );
314 QString SUIT_DataObject::name() const
316 return QString::null;
323 QPixmap SUIT_DataObject::icon() const
332 QString SUIT_DataObject::text( const int ) const
334 return QString::null;
341 QColor SUIT_DataObject::color( const ColorRole ) const
347 Returns object tool tip
350 QString SUIT_DataObject::toolTip() const
352 return QString::null;
356 Returns 'true' if it is possible to drag this object
359 bool SUIT_DataObject::isDragable() const
365 Returns 'true' if it is possible to drop an object "obj" to this object.
368 bool SUIT_DataObject::isDropAccepted( SUIT_DataObject* )
374 Returns type of check possibility.
377 SUIT_DataObject::CheckType SUIT_DataObject::checkType() const
383 Returns the checked state of the object.
386 bool SUIT_DataObject::isOn() const
392 Sets the checked state of the object.
395 void SUIT_DataObject::setOn( const bool on )
401 Returns object personal indentification key.
404 SUIT_DataObjectKey* SUIT_DataObject::key() const
410 Dump this data object and its children to cout
412 void SUIT_DataObject::dump( const int indent ) const
414 QString strIndent = QString().fill( ' ', indent ); // indentation string
415 std::cout << strIndent << name() << std::endl; // dump to cout
416 for ( DataObjectListIterator it( myChildren ); it.current(); ++it ) // iterate all children
417 it.current()->dump( indent + 2 ); // dump every child with indent + 2 spaces