myRoot( 0 ),
myTooltip( 0 ),
+myAutoOpenLevel( 0 ),
myAutoUpdate( false ),
myAutoDelObjs( false ),
myRootDecorated( true )
QVBoxLayout* main = new QVBoxLayout( this );
main->addWidget( myView );
-
+
myShowToolTips = true;
myTooltip = new ToolTip( this, myView->viewport() );
updateTree();
}
+int OB_Browser::autoOpenLevel() const
+{
+ return myAutoOpenLevel;
+}
+
+void OB_Browser::setAutoOpenLevel( const int level )
+{
+ if ( myAutoOpenLevel == level )
+ return;
+
+ myAutoOpenLevel = level;
+
+ autoOpenBranches();
+}
+
bool OB_Browser::isShowToolTips()
{
return myShowToolTips;
restoreState( selObjs, openObjs, curObj, selKeys, openKeys, curKey );
+ autoOpenBranches();
+
if ( selNum != numberOfSelected() )
emit selectionChanged();
}
restoreState( selObjs, openObjs, curObj, selKeys, openKeys, curKey );
+ autoOpenBranches();
+
if ( selNum != numberOfSelected() )
emit selectionChanged();
}
restoreState( selObjs, openObjs, curObj, selKeys, openKeys, curKey );
+ autoOpenBranches();
+
if ( selNum != numberOfSelected() )
emit selectionChanged();
}
if ( e->key() == Qt::Key_F5 )
updateTree();
- if ( ( e->key() == Qt::Key_Plus || e->key() == Qt::Key_Minus ) &&
- e->state() & ControlButton && getListView() )
- {
- bool isOpen = e->key() == Qt::Key_Plus;
- for ( QListViewItemIterator it( getListView() ); it.current(); ++it )
- if ( it.current()->childCount() )
- it.current()->setOpen( isOpen );
- }
-
QFrame::keyPressEvent( e );
}
void OB_Browser::onDestroyed( SUIT_DataObject* obj )
{
- if ( !obj )
- return;
-
- // Removing list view items from <myItems> recursively for all children.
- // Otherwise, "delete item" line will destroy all item's children,
- // and <myItems> will contain invalid pointers (see ~QListViewItem() description in Qt docs)
- DataObjectList childList;
- obj->children( childList );
- for ( DataObjectListIterator it( childList ); it.current(); ++it )
- onDestroyed( it.current() );
-
- QListViewItem* item = listViewItem( obj );
-
- myItems.remove( obj );
-
- if ( obj == myRoot )
- myRoot = 0;
-
- if ( isAutoUpdate() )
- {
- SUIT_DataObject* pObj = item && item->parent() ? dataObject( item->parent() ) : 0;
- updateTree( pObj );
- }
- else
- delete item;
+ removeObject( obj );
}
void OB_Browser::onDropped( QPtrList<QListViewItem> items, QListViewItem* item, int action )
return has;
}
+
+void OB_Browser::removeObject( SUIT_DataObject* obj, const bool autoUpd )
+{
+ if ( !obj )
+ return;
+
+ // Removing list view items from <myItems> recursively for all children.
+ // Otherwise, "delete item" line will destroy all item's children,
+ // and <myItems> will contain invalid pointers (see ~QListViewItem() description in Qt docs)
+ DataObjectList childList;
+ obj->children( childList );
+ for ( DataObjectListIterator it( childList ); it.current(); ++it )
+ removeObject( it.current(), false );
+
+ QListViewItem* item = listViewItem( obj );
+
+ myItems.remove( obj );
+
+ if ( obj == myRoot )
+ myRoot = 0;
+
+ if ( !autoUpd )
+ return;
+
+ if ( isAutoUpdate() )
+ {
+ SUIT_DataObject* pObj = item && item->parent() ? dataObject( item->parent() ) : 0;
+ updateTree( pObj );
+ }
+ else
+ delete item;
+}
+
+void OB_Browser::autoOpenBranches()
+{
+ int level = autoOpenLevel();
+ QListView* lv = getListView();
+ if ( !lv || level < 1 )
+ return;
+
+ QListViewItem* item = lv->firstChild();
+ while ( item )
+ {
+ openBranch( item, level );
+ item = item->nextSibling();
+ }
+}
+
+void OB_Browser::openBranch( QListViewItem* item, const int level )
+{
+ if ( !item || level < 1 || !item->childCount() )
+ return;
+
+ item->setOpen( true );
+ while ( item )
+ {
+ openBranch( item, level - 1 );
+ item = item->nextSibling();
+ }
+}
bool rootIsDecorated() const;
void setRootIsDecorated( const bool );
+ int autoOpenLevel() const;
+ void setAutoOpenLevel( const int );
+
virtual int addColumn( const QString & label, int width = -1, int index = -1 );
virtual int addColumn( const QIconSet & iconset, const QString & label, int width = -1, int index = -1 );
virtual void removeColumn( int index );
void expand( QListViewItem* );
bool hasClosed( QListViewItem* ) const;
+ void autoOpenBranches();
+ void openBranch( QListViewItem*, const int );
+
void removeReferences( QListViewItem* );
void createConnections( SUIT_DataObject* );
+ void removeObject( SUIT_DataObject*, const bool = true );
DataObjectKey objectKey( QListViewItem* ) const;
DataObjectKey objectKey( SUIT_DataObject* ) const;
bool myAutoDelObjs;
bool myShowToolTips;
bool myRootDecorated;
+ int myAutoOpenLevel;
friend class OB_Browser::ToolTip;
};
return ok;
}
-int OB_ListView::addColumn( const QString& label, int width )
-{
- int res = QListView::addColumn( label, width );
-
- updateHeader();
-
- return res;
-}
-
-int OB_ListView::addColumn( const QIconSet& iconset, const QString& label, int width )
-{
- int res = QListView::addColumn( iconset, label, width );
-
- updateHeader();
-
- return res;
-}
-
QDragObject* OB_ListView::dragObject()
{
myItems.clear();
myItems.clear();
}
+void OB_ListView::keyPressEvent( QKeyEvent* ke )
+{
+ if ( ( ke->key() == Qt::Key_Plus || ke->key() == Qt::Key_Minus ) && ke->state() & ControlButton )
+ {
+ bool isOpen = ke->key() == Qt::Key_Plus;
+ for ( QListViewItemIterator it( this ); it.current(); ++it )
+ if ( it.current()->childCount() )
+ it.current()->setOpen( isOpen );
+ }
+ else
+ QtxListView::keyPressEvent( ke );
+}
+
QListViewItem* OB_ListView::dropItem( QDropEvent* e ) const
{
QListViewItem* item = 0;
return dropObj->isDropAccepted( dragObj );
}
-
-void OB_ListView::updateHeader()
-{
-
-}
OB_Filter* filter() const;
void setFilter( OB_Filter* );
- virtual int addColumn( const QString& label, int width = -1 );
- virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 );
-
bool isOk( QListViewItem* ) const;
signals:
virtual void dragMoveEvent( QDragMoveEvent* );
virtual void dragEnterEvent( QDragEnterEvent* );
+ virtual void keyPressEvent( QKeyEvent* );
+
private:
void updateHeader();
QListViewItem* dropItem( QDropEvent* ) const;
SUIT_DataObject::~SUIT_DataObject()
{
+ if ( mySignal )
+ {
+ mySignal->emitSignal();
+ mySignal->setOwner( 0 );
+ }
+
+ delete mySignal;
+
SUIT_DataObject* p = myParent;
myParent = 0;
for ( QPtrListIterator<SUIT_DataObject> it( myChildren ); it.current(); ++it )
it.current()->myParent = 0;
-
- delete mySignal;
}
/*!
removeChild( src );
if ( del )
- delete src;
+ src->deleteLater();
return true;
}
+/*!
+ Transfer the all children from specified object 'obj' to self.
+*/
+
+void SUIT_DataObject::reparentChildren( const SUIT_DataObject* obj )
+{
+ DataObjectList lst;
+ obj->children( lst );
+ for ( DataObjectListIterator it( lst ); it.current(); ++it )
+ it.current()->setParent( this );
+}
+
/*!
Set the parent object. Remove itself from current parent children
and append itself to the new parent children list.
Returns object name
*/
+void SUIT_DataObject::deleteLater()
+{
+ if ( !mySignal )
+ mySignal = new Signal( this );
+
+ mySignal->emitSignal();
+ mySignal->deleteLater();
+}
+
+/*!
+ Returns object name
+*/
+
QString SUIT_DataObject::name() const
{
return QString::null;
for ( DataObjectListIterator it( myChildren ); it.current(); ++it ) // iterate all children
it.current()->dump( indent + 2 ); // dump every child with indent + 2 spaces
}
+
+/*!
+ Class: SUIT_DataObject::Signal [Internal]
+*/
+
+SUIT_DataObject::Signal::Signal( SUIT_DataObject* o )
+: QObject(),
+myOwner( o )
+{
+}
+
+SUIT_DataObject::Signal::~Signal()
+{
+ SUIT_DataObject* o = myOwner;
+ myOwner = 0;
+ if ( o )
+ {
+ o->mySignal = 0;
+ delete o;
+ }
+}
+
+void SUIT_DataObject::Signal::setOwner( SUIT_DataObject* o )
+{
+ myOwner = o;
+}
+
+void SUIT_DataObject::Signal::emitSignal()
+{
+ if ( myOwner )
+ emit destroyed( myOwner );
+}
virtual void insertChild( SUIT_DataObject*, int thePosition );
bool replaceChild( SUIT_DataObject*, SUIT_DataObject*, const bool = false );
+ void reparentChildren( const SUIT_DataObject* );
+
QString text() const { return text( 0 ); }
QColor color() const { return color( Foreground ); }
virtual QString name() const;
bool connect( QObject*, const char* );
bool disconnect( QObject*, const char* );
+
+ void deleteLater();
void dump( const int indent = 2 ) const; // dump to cout
SUIT_DataObject* myParent;
DataObjectList myChildren;
+ friend class SUIT_DataObject::Signal;
friend class SUIT_DataObjectIterator;
};
Q_OBJECT
public:
- Signal( SUIT_DataObject* o ) : QObject(), myOwner( o ) {};
- virtual ~Signal() { emit destroyed( myOwner ); };
+ Signal( SUIT_DataObject* );
+ virtual ~Signal();
+
+ void emitSignal();
+ void setOwner( SUIT_DataObject* o );
signals:
void destroyed( SUIT_DataObject* );