]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Optimisation of adjust item width after item expanding.
authorsan <san@opencascade.com>
Mon, 27 Sep 2010 12:20:14 +0000 (12:20 +0000)
committersan <san@opencascade.com>
Mon, 27 Sep 2010 12:20:14 +0000 (12:20 +0000)
src/SUIT/SUIT_DataBrowser.cxx
src/SUIT/SUIT_DataBrowser.h
src/SUIT/SUIT_TreeModel.cxx

index e2bff47ce073929a94bbc319fb513eb8887986cc..b08628fe4739e8dc1c94b32306c50a9939ac8199 100644 (file)
@@ -24,6 +24,7 @@
 #include <SUIT_TreeModel.h>
 #include <QtxTreeView.h>
 
+#include <QTimer>
 #include <QShortcut>
 #include <QModelIndex>
 
@@ -48,9 +49,12 @@ SUIT_DataBrowser::SUIT_DataBrowser( QWidget* parent )
   \param parent parent widget
 */
 SUIT_DataBrowser::SUIT_DataBrowser( SUIT_DataObject* root, QWidget* parent )
-: OB_Browser( parent )
+  : OB_Browser( parent )
 {
   init( root );
+
+  myExpandTimer = new QTimer( this );
+  connect( myExpandTimer, SIGNAL( timeout() ), this, SLOT( onExpandUpdate() ) );
 }
 
 /*!
@@ -404,9 +408,26 @@ void SUIT_DataBrowser::onDblClicked( const QModelIndex& index )
 */
 void SUIT_DataBrowser::onExpanded( const QModelIndex& index )
 {
-  if (myResizeOnExpandItem) {
-    adjustFirstColumnWidth();
-    adjustColumnsWidth();
-  }
+  if ( myResizeOnExpandItem )
+    triggerExpandUpdate();
+}
+
+/*!
+  \brief Set the delayed update for expanding items event.
+  \internal
+*/
+void SUIT_DataBrowser::triggerExpandUpdate()
+{
+  myExpandTimer->stop();
+  myExpandTimer->start( 0 );
 }
 
+/*!
+  \brief Update for expanding items event. Called after the required items were expanded.
+  \internal
+*/
+void SUIT_DataBrowser::onExpandUpdate()
+{
+  adjustFirstColumnWidth();
+  adjustColumnsWidth();
+}
index 5544e7f10bbd89ef92506cf5990880c811ff6f71..37b621035efb789c8aaf01be0ddf36a01e14961d 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <QAbstractItemView>
 
+class QTimer;
 class QShortcut;
 
 class SUIT_EXPORT SUIT_DataBrowser : public OB_Browser, public SUIT_PopupClient
@@ -74,6 +75,7 @@ protected:
   virtual void     contextMenuEvent( QContextMenuEvent* );
 
 private:
+  void             triggerExpandUpdate();
   void             init( SUIT_DataObject* );
 
 signals:
@@ -84,9 +86,11 @@ private slots:
   void             onModelUpdated();
   void             onDblClicked( const QModelIndex& );
   void             onExpanded( const QModelIndex& );
+  void             onExpandUpdate();
 
 private:
   QShortcut*       myShortcut;
+  QTimer*          myExpandTimer;
 
   bool             myAutoSizeFirstColumn;
   bool             myAutoSizeColumns;
index 70f59a390781502dba93426d0ec35569dadce3e5..841ff6dc700173283238017712b6204c75cb3a97 100755 (executable)
@@ -444,6 +444,7 @@ SUIT_TreeModel::~SUIT_TreeModel()
                                 this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) );
     SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                                 this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
+    SUIT_DataObject::disconnect( SIGNAL( changed( SUIT_DataObject* ) ), this, SLOT( onChanged( SUIT_DataObject* ) ) );
     delete myRoot;
   }
 
@@ -475,6 +476,7 @@ void SUIT_TreeModel::setRoot( SUIT_DataObject* r )
                                 this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) );
     SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                                 this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
+    SUIT_DataObject::disconnect( SIGNAL( changed( SUIT_DataObject* ) ), this, SLOT( onChanged( SUIT_DataObject* ) ) );
     delete myRoot;
   }
 
@@ -839,6 +841,8 @@ void SUIT_TreeModel::setAutoUpdate( const bool on, const bool updateImmediately
                               this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) );
   SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                               this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
+  SUIT_DataObject::disconnect( SIGNAL( changed( SUIT_DataObject* ) ), this, SLOT( onChanged( SUIT_DataObject* ) ) );
+
   myAutoUpdate = on;
 
   if ( myAutoUpdate ) {
@@ -846,6 +850,7 @@ void SUIT_TreeModel::setAutoUpdate( const bool on, const bool updateImmediately
                              this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) );
     SUIT_DataObject::connect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                              this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
+    SUIT_DataObject::connect( SIGNAL( changed( SUIT_DataObject* ) ), this, SLOT( onChanged( SUIT_DataObject* ) ) );
 
     if ( updateImmediately )
       updateTree();
@@ -939,11 +944,13 @@ void SUIT_TreeModel::initialize()
                               this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) );
   SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                               this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
+  SUIT_DataObject::disconnect( SIGNAL( changed( SUIT_DataObject* ) ), this, SLOT( onChanged( SUIT_DataObject* ) ) );
   if ( autoUpdate() ) {
     SUIT_DataObject::connect( SIGNAL( inserted( SUIT_DataObject*, SUIT_DataObject* ) ),
                              this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ) ) );
     SUIT_DataObject::connect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                              this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
+    SUIT_DataObject::connect( SIGNAL( changed( SUIT_DataObject* ) ), this, SLOT( onChanged( SUIT_DataObject* ) ) );
   }
 
   myItems.clear(); // ????? is it really necessary