From: stv Date: Wed, 1 Jun 2005 10:04:41 +0000 (+0000) Subject: no message X-Git-Tag: T3_0_0_a1~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ec43b17a200bb62311dadf4593f8acd08c7c0084;p=modules%2Fgui.git no message --- diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 3866f6c7e..cfac73697 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -71,6 +71,7 @@ OB_Browser::OB_Browser( QWidget* parent, SUIT_DataObject* root ) myRoot( 0 ), myTooltip( 0 ), +myAutoOpenLevel( 0 ), myAutoUpdate( false ), myAutoDelObjs( false ), myRootDecorated( true ) @@ -84,7 +85,7 @@ myRootDecorated( true ) QVBoxLayout* main = new QVBoxLayout( this ); main->addWidget( myView ); - + myShowToolTips = true; myTooltip = new ToolTip( this, myView->viewport() ); @@ -115,6 +116,21 @@ void OB_Browser::setRootIsDecorated( const bool decor ) 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; @@ -179,6 +195,8 @@ void OB_Browser::setRootObject( SUIT_DataObject* theRoot ) restoreState( selObjs, openObjs, curObj, selKeys, openKeys, curKey ); + autoOpenBranches(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } @@ -394,6 +412,8 @@ void OB_Browser::updateTree( SUIT_DataObject* o ) restoreState( selObjs, openObjs, curObj, selKeys, openKeys, curKey ); + autoOpenBranches(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } @@ -429,6 +449,8 @@ void OB_Browser::replaceTree( SUIT_DataObject* src, SUIT_DataObject* trg ) restoreState( selObjs, openObjs, curObj, selKeys, openKeys, curKey ); + autoOpenBranches(); + if ( selNum != numberOfSelected() ) emit selectionChanged(); } @@ -739,15 +761,6 @@ void OB_Browser::keyPressEvent( QKeyEvent* e ) 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 ); } @@ -766,31 +779,7 @@ void OB_Browser::onRefresh() void OB_Browser::onDestroyed( SUIT_DataObject* obj ) { - if ( !obj ) - return; - - // Removing list view items from recursively for all children. - // Otherwise, "delete item" line will destroy all item's children, - // and 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 items, QListViewItem* item, int action ) @@ -884,3 +873,63 @@ bool OB_Browser::hasClosed( QListViewItem* item ) const return has; } + +void OB_Browser::removeObject( SUIT_DataObject* obj, const bool autoUpd ) +{ + if ( !obj ) + return; + + // Removing list view items from recursively for all children. + // Otherwise, "delete item" line will destroy all item's children, + // and 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(); + } +} diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index 37df3ff2a..e1ea16ad3 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -68,6 +68,9 @@ public: 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 ); @@ -108,8 +111,12 @@ private: 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; @@ -132,6 +139,7 @@ private: bool myAutoDelObjs; bool myShowToolTips; bool myRootDecorated; + int myAutoOpenLevel; friend class OB_Browser::ToolTip; }; diff --git a/src/ObjBrowser/OB_ListView.cxx b/src/ObjBrowser/OB_ListView.cxx index 866161e4a..c815071ff 100755 --- a/src/ObjBrowser/OB_ListView.cxx +++ b/src/ObjBrowser/OB_ListView.cxx @@ -47,24 +47,6 @@ bool OB_ListView::isOk( QListViewItem* item ) const 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(); @@ -105,6 +87,19 @@ void OB_ListView::dropEvent( QDropEvent* e ) 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; @@ -149,8 +144,3 @@ bool OB_ListView::isDropAccepted( QListViewItem* drag, QListViewItem* drop ) con return dropObj->isDropAccepted( dragObj ); } - -void OB_ListView::updateHeader() -{ - -} diff --git a/src/ObjBrowser/OB_ListView.h b/src/ObjBrowser/OB_ListView.h index 6fca182eb..7db429dcc 100755 --- a/src/ObjBrowser/OB_ListView.h +++ b/src/ObjBrowser/OB_ListView.h @@ -28,9 +28,6 @@ public: 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: @@ -42,6 +39,8 @@ protected: virtual void dragMoveEvent( QDragMoveEvent* ); virtual void dragEnterEvent( QDragEnterEvent* ); + virtual void keyPressEvent( QKeyEvent* ); + private: void updateHeader(); QListViewItem* dropItem( QDropEvent* ) const; diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index 952c2d399..8aa0b0a0c 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -26,6 +26,14 @@ SUIT_DataObject::SUIT_DataObject( SUIT_DataObject* p ) SUIT_DataObject::~SUIT_DataObject() { + if ( mySignal ) + { + mySignal->emitSignal(); + mySignal->setOwner( 0 ); + } + + delete mySignal; + SUIT_DataObject* p = myParent; myParent = 0; @@ -35,8 +43,6 @@ SUIT_DataObject::~SUIT_DataObject() for ( QPtrListIterator it( myChildren ); it.current(); ++it ) it.current()->myParent = 0; - - delete mySignal; } /*! @@ -242,11 +248,23 @@ bool SUIT_DataObject::replaceChild( SUIT_DataObject* src, SUIT_DataObject* trg, 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. @@ -311,6 +329,19 @@ bool SUIT_DataObject::disconnect( QObject* reciever, const char* slot ) 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; @@ -416,3 +447,35 @@ void SUIT_DataObject::dump( const int indent ) const 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 ); +} diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index c7e1f848e..e9a960fd0 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -51,6 +51,8 @@ public: 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; @@ -74,6 +76,8 @@ public: bool connect( QObject*, const char* ); bool disconnect( QObject*, const char* ); + + void deleteLater(); void dump( const int indent = 2 ) const; // dump to cout @@ -83,6 +87,7 @@ private: SUIT_DataObject* myParent; DataObjectList myChildren; + friend class SUIT_DataObject::Signal; friend class SUIT_DataObjectIterator; }; @@ -91,8 +96,11 @@ class SUIT_DataObject::Signal : public QObject 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* );