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()
31 mySignal->emitSignal();
32 mySignal->setOwner( 0 );
37 SUIT_DataObject* p = myParent;
42 p->removeChild( this );
44 for ( QPtrListIterator<SUIT_DataObject> it( myChildren ); it.current(); ++it )
45 it.current()->myParent = 0;
49 Returns the root object.
52 SUIT_DataObject* SUIT_DataObject::root() const
54 return parent() ? parent()->root() : (SUIT_DataObject*)this;
58 Returns the first child object.
61 SUIT_DataObject* SUIT_DataObject::firstChild() const
63 SUIT_DataObject* child = 0;
64 if ( !myChildren.isEmpty() )
65 child = myChildren.getFirst();
70 Returns the last child object.
73 SUIT_DataObject* SUIT_DataObject::lastChild() const
75 SUIT_DataObject* child = 0;
76 if ( !myChildren.isEmpty() )
77 child = myChildren.getLast();
82 Returns the number of the child objects.
85 int SUIT_DataObject::childCount() const
87 return myChildren.count();
91 Returns the index of the specified object in the child list or -1.
94 int SUIT_DataObject::childPos( const SUIT_DataObject* obj ) const
99 for ( DataObjectListIterator it( myChildren ); it.current() && res == -1; ++it, i++ )
101 if ( it.current() == obj )
109 Returns the child object with specified index.
112 SUIT_DataObject* SUIT_DataObject::childObject( const int idx ) const
114 SUIT_DataObject* child = 0;
116 if ( idx>= 0 && idx < (int)myChildren.count() )
118 SUIT_DataObject* that = (SUIT_DataObject*)this;
119 child = that->myChildren.at( idx );
126 Returns the next data object in the child list of the parent.
129 SUIT_DataObject* SUIT_DataObject::nextBrother() const
131 return myParent ? myParent->childObject( myParent->childPos( this ) + 1 ) : 0;
135 Returns the previous data object in the child list of the parent.
138 SUIT_DataObject* SUIT_DataObject::prevBrother() const
140 return myParent ? myParent->childObject( myParent->childPos( this ) - 1 ) : 0;
144 Returns 'true' if the object will delete children during destroying
147 bool SUIT_DataObject::autoDeleteChildren() const
149 return myChildren.autoDelete();
153 Specify should the object delete children during destroying
156 void SUIT_DataObject::setAutoDeleteChildren( const bool on )
158 myChildren.setAutoDelete( on );
162 Returns the list of the child objects. if 'rec' is 'true' then function get all sub children.
165 void SUIT_DataObject::children( DataObjectList& lst, const bool rec ) const
167 for ( DataObjectListIterator it( myChildren ); it.current(); ++it )
169 lst.append( it.current() );
171 it.current()->children( lst, rec );
176 Returns the list of the child objects. if 'rec' is 'true' then function get all sub children.
179 DataObjectList SUIT_DataObject::children( const bool rec )
182 children( lst, rec );
187 Append new child object to the end of the children list
190 void SUIT_DataObject::appendChild( SUIT_DataObject* theObj )
192 insertChild( theObj, myChildren.count() );
196 Insert new child object to the children list at specified position
199 void SUIT_DataObject::insertChild( SUIT_DataObject* theObj, int thePosition )
201 if ( !theObj || myChildren.find( theObj ) != -1 )
204 int pos = thePosition < 0 ? myChildren.count() : thePosition;
205 myChildren.insert( QMIN( pos, (int)myChildren.count() ), theObj );
206 theObj->setParent( this );
210 Removes the specified child object reference.
213 void SUIT_DataObject::removeChild( SUIT_DataObject* theObj )
218 bool ad = myChildren.autoDelete();
219 myChildren.setAutoDelete( false );
221 if ( myChildren.remove( theObj ) )
222 theObj->setParent( 0 );
224 myChildren.setAutoDelete( ad );
228 Replaces the specified child object by another object.
231 bool SUIT_DataObject::replaceChild( SUIT_DataObject* src, SUIT_DataObject* trg, const bool del )
236 int idx = childPos( trg );
239 int pos = childPos( src );
243 insertChild( trg, idx );
247 insertChild( trg, pos );
257 Transfer the all children from specified object 'obj' to self.
260 void SUIT_DataObject::reparentChildren( const SUIT_DataObject* obj )
263 obj->children( lst );
264 for ( DataObjectListIterator it( lst ); it.current(); ++it )
265 it.current()->setParent( this );
269 Set the parent object. Remove itself from current parent children
270 and append itself to the new parent children list.
273 void SUIT_DataObject::setParent( SUIT_DataObject* theParent )
275 if ( theParent == parent() )
279 parent()->removeChild( this );
281 myParent = theParent;
284 parent()->appendChild( this );
288 Returns the parent object.
291 SUIT_DataObject* SUIT_DataObject::parent() const
298 Connect to signal destroyed( SUIT_DataObject* ).
301 bool SUIT_DataObject::connect( QObject* reciever, const char* slot )
303 if ( !reciever || !slot )
307 mySignal = new Signal( this );
309 QObject::disconnect( mySignal, SIGNAL( destroyed( SUIT_DataObject* ) ), reciever, slot );
310 return QObject::connect( mySignal, SIGNAL( destroyed( SUIT_DataObject* ) ), reciever, slot );
314 Disconnect from signal destroyed( SUIT_DataObject* ).
317 bool SUIT_DataObject::disconnect( QObject* reciever, const char* slot )
319 if ( !reciever || !slot )
325 return QObject::disconnect( mySignal, SIGNAL( destroyed( SUIT_DataObject* ) ), reciever, slot );
332 void SUIT_DataObject::deleteLater()
335 mySignal = new Signal( this );
337 mySignal->emitSignal();
338 mySignal->deleteLater();
345 QString SUIT_DataObject::name() const
347 return QString::null;
354 QPixmap SUIT_DataObject::icon() const
363 QString SUIT_DataObject::text( const int ) const
365 return QString::null;
372 QColor SUIT_DataObject::color( const ColorRole ) const
378 Returns object tool tip
381 QString SUIT_DataObject::toolTip() const
383 return QString::null;
387 Returns 'true' if it is possible to drag this object
390 bool SUIT_DataObject::isDragable() const
396 Returns 'true' if it is possible to drop an object "obj" to this object.
399 bool SUIT_DataObject::isDropAccepted( SUIT_DataObject* )
405 Returns type of check possibility.
408 SUIT_DataObject::CheckType SUIT_DataObject::checkType() const
414 Returns the checked state of the object.
417 bool SUIT_DataObject::isOn() const
423 Sets the checked state of the object.
426 void SUIT_DataObject::setOn( const bool on )
432 Returns object personal indentification key.
435 SUIT_DataObjectKey* SUIT_DataObject::key() const
441 Dump this data object and its children to cout
443 void SUIT_DataObject::dump( const int indent ) const
445 QString strIndent = QString().fill( ' ', indent ); // indentation string
446 std::cout << strIndent << name() << std::endl; // dump to cout
447 for ( DataObjectListIterator it( myChildren ); it.current(); ++it ) // iterate all children
448 it.current()->dump( indent + 2 ); // dump every child with indent + 2 spaces
452 Class: SUIT_DataObject::Signal [Internal]
455 SUIT_DataObject::Signal::Signal( SUIT_DataObject* o )
461 SUIT_DataObject::Signal::~Signal()
463 SUIT_DataObject* o = myOwner;
472 void SUIT_DataObject::Signal::setOwner( SUIT_DataObject* o )
477 void SUIT_DataObject::Signal::emitSignal()
480 emit destroyed( myOwner );