Salome HOME
no message
authorstv <stv@opencascade.com>
Wed, 1 Jun 2005 10:04:41 +0000 (10:04 +0000)
committerstv <stv@opencascade.com>
Wed, 1 Jun 2005 10:04:41 +0000 (10:04 +0000)
src/ObjBrowser/OB_Browser.cxx
src/ObjBrowser/OB_Browser.h
src/ObjBrowser/OB_ListView.cxx
src/ObjBrowser/OB_ListView.h
src/SUIT/SUIT_DataObject.cxx
src/SUIT/SUIT_DataObject.h

index 3866f6c7e31af305ba0bd6dce1112832ec175ada..cfac7369726439136ef2b0173f1906b4f130a6bb 100755 (executable)
@@ -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 <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 )
@@ -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 <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();
+  }
+}
index 37df3ff2a1efa944a50be4320243e2b30b132242..e1ea16ad3ff45ecd0481dea154a6e9dd1e215b39 100755 (executable)
@@ -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;
 };
index 866161e4a544dc5a7c4fff63b4c84eabdb0b0184..c815071ff2b0134390292d2dbcb2076b399f3985 100755 (executable)
@@ -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()
-{
-
-}
index 6fca182eb78d6c847263e06d58c6e44d521c7670..7db429dcc12ffe0c344bb74669ce24f15044afd4 100755 (executable)
@@ -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;
index 952c2d399bd7021a2fdb0db1ff12255da1610ac5..8aa0b0a0c708b2581bc6b24ca7f6cf5d670f1c64 100755 (executable)
@@ -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<SUIT_DataObject> 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 );
+}
index c7e1f848ebb443ef5125c33d9e09a663d6695e02..e9a960fd0e00d5f952b89c7061b9b7ac6c36ea8c 100755 (executable)
@@ -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* );