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 )
19 myChildren.setAutoDelete( true );
28 SUIT_DataObject::~SUIT_DataObject()
32 mySignal->emitSignal();
33 mySignal->setOwner( 0 );
38 SUIT_DataObject* p = myParent;
43 p->removeChild( this );
45 for ( QPtrListIterator<SUIT_DataObject> it( myChildren ); it.current(); ++it )
46 it.current()->myParent = 0;
50 Returns the root object.
53 SUIT_DataObject* SUIT_DataObject::root() const
55 return parent() ? parent()->root() : (SUIT_DataObject*)this;
59 Returns the first child object.
62 SUIT_DataObject* SUIT_DataObject::firstChild() const
64 SUIT_DataObject* child = 0;
65 if ( !myChildren.isEmpty() )
66 child = myChildren.getFirst();
71 Returns the last child object.
74 SUIT_DataObject* SUIT_DataObject::lastChild() const
76 SUIT_DataObject* child = 0;
77 if ( !myChildren.isEmpty() )
78 child = myChildren.getLast();
83 Returns the number of the child objects.
86 int SUIT_DataObject::childCount() const
88 return myChildren.count();
92 Returns the index of the specified object in the child list or -1.
95 int SUIT_DataObject::childPos( const SUIT_DataObject* obj ) const
100 for ( DataObjectListIterator it( myChildren ); it.current() && res == -1; ++it, i++ )
102 if ( it.current() == obj )
110 Returns the child object with specified index.
113 SUIT_DataObject* SUIT_DataObject::childObject( const int idx ) const
115 SUIT_DataObject* child = 0;
117 if ( idx>= 0 && idx < (int)myChildren.count() )
119 SUIT_DataObject* that = (SUIT_DataObject*)this;
120 child = that->myChildren.at( idx );
127 Returns the next data object in the child list of the parent.
130 SUIT_DataObject* SUIT_DataObject::nextBrother() const
132 return myParent ? myParent->childObject( myParent->childPos( this ) + 1 ) : 0;
136 Returns the previous data object in the child list of the parent.
139 SUIT_DataObject* SUIT_DataObject::prevBrother() const
141 return myParent ? myParent->childObject( myParent->childPos( this ) - 1 ) : 0;
145 Returns 'true' if the object will delete children during destroying
148 bool SUIT_DataObject::autoDeleteChildren() const
150 return myChildren.autoDelete();
154 Specify should the object delete children during destroying
157 void SUIT_DataObject::setAutoDeleteChildren( const bool on )
159 myChildren.setAutoDelete( on );
163 Returns the list of the child objects. if 'rec' is 'true' then function get all sub children.
166 void SUIT_DataObject::children( DataObjectList& lst, const bool rec ) const
168 for ( DataObjectListIterator it( myChildren ); it.current(); ++it )
170 lst.append( it.current() );
172 it.current()->children( lst, rec );
177 Returns the list of the child objects. if 'rec' is 'true' then function get all sub children.
180 DataObjectList SUIT_DataObject::children( const bool rec )
183 children( lst, rec );
188 Append new child object to the end of the children list
191 void SUIT_DataObject::appendChild( SUIT_DataObject* theObj )
193 insertChild( theObj, myChildren.count() );
197 Insert new child object to the children list at specified position
200 void SUIT_DataObject::insertChild( SUIT_DataObject* theObj, int thePosition )
202 if ( !theObj || myChildren.find( theObj ) != -1 )
205 int pos = thePosition < 0 ? myChildren.count() : thePosition;
206 myChildren.insert( QMIN( pos, (int)myChildren.count() ), theObj );
207 theObj->setParent( this );
211 Removes the specified child object reference.
214 void SUIT_DataObject::removeChild( SUIT_DataObject* theObj )
219 bool ad = myChildren.autoDelete();
220 myChildren.setAutoDelete( false );
222 if ( myChildren.remove( theObj ) )
223 theObj->setParent( 0 );
225 myChildren.setAutoDelete( ad );
229 Replaces the specified child object by another object.
232 bool SUIT_DataObject::replaceChild( SUIT_DataObject* src, SUIT_DataObject* trg, const bool del )
237 int idx = childPos( trg );
240 int pos = childPos( src );
244 insertChild( trg, idx );
248 insertChild( trg, pos );
258 Transfer the all children from specified object 'obj' to self.
261 void SUIT_DataObject::reparentChildren( const SUIT_DataObject* obj )
264 obj->children( lst );
265 for ( DataObjectListIterator it( lst ); it.current(); ++it )
266 it.current()->setParent( this );
270 Set the parent object. Remove itself from current parent children
271 and append itself to the new parent children list.
274 void SUIT_DataObject::setParent( SUIT_DataObject* theParent )
276 if ( theParent == parent() )
280 parent()->removeChild( this );
282 myParent = theParent;
285 parent()->appendChild( this );
289 Returns the parent object.
292 SUIT_DataObject* SUIT_DataObject::parent() const
299 Connect to signal destroyed( SUIT_DataObject* ).
302 bool SUIT_DataObject::connect( QObject* reciever, const char* slot )
304 if ( !reciever || !slot )
308 mySignal = new Signal( this );
310 QObject::disconnect( mySignal, SIGNAL( destroyed( SUIT_DataObject* ) ), reciever, slot );
311 return QObject::connect( mySignal, SIGNAL( destroyed( SUIT_DataObject* ) ), reciever, slot );
315 Disconnect from signal destroyed( SUIT_DataObject* ).
318 bool SUIT_DataObject::disconnect( QObject* reciever, const char* slot )
320 if ( !reciever || !slot )
326 return QObject::disconnect( mySignal, SIGNAL( destroyed( SUIT_DataObject* ) ), reciever, slot );
333 void SUIT_DataObject::deleteLater()
336 mySignal = new Signal( this );
338 mySignal->emitSignal();
339 mySignal->deleteLater();
346 QString SUIT_DataObject::name() const
348 return QString::null;
355 QPixmap SUIT_DataObject::icon() const
364 QString SUIT_DataObject::text( const int ) const
366 return QString::null;
373 QColor SUIT_DataObject::color( const ColorRole ) const
379 Returns object tool tip
382 QString SUIT_DataObject::toolTip() const
384 return QString::null;
388 Returns 'true' if it is possible to drag this object
391 bool SUIT_DataObject::isDragable() const
397 Returns 'true' if it is possible to drop an object "obj" to this object.
400 bool SUIT_DataObject::isDropAccepted( SUIT_DataObject* )
406 Returns type of check possibility.
409 SUIT_DataObject::CheckType SUIT_DataObject::checkType() const
415 Returns the checked state of the object.
418 bool SUIT_DataObject::isOn() const
424 Sets the checked state of the object.
427 void SUIT_DataObject::setOn( const bool on )
432 bool SUIT_DataObject::isOpen() const
437 void SUIT_DataObject::setOpen( const bool on )
443 Returns object personal indentification key.
446 SUIT_DataObjectKey* SUIT_DataObject::key() const
452 Dump this data object and its children to cout
454 void SUIT_DataObject::dump( const int indent ) const
456 QString strIndent = QString().fill( ' ', indent ); // indentation string
457 std::cout << strIndent << name() << std::endl; // dump to cout
458 for ( DataObjectListIterator it( myChildren ); it.current(); ++it ) // iterate all children
459 it.current()->dump( indent + 2 ); // dump every child with indent + 2 spaces
463 Class: SUIT_DataObject::Signal [Internal]
466 SUIT_DataObject::Signal::Signal( SUIT_DataObject* o )
472 SUIT_DataObject::Signal::~Signal()
474 SUIT_DataObject* o = myOwner;
483 void SUIT_DataObject::Signal::setOwner( SUIT_DataObject* o )
488 void SUIT_DataObject::Signal::emitSignal()
491 emit destroyed( myOwner );