]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
CCAR: optimisation of qt tree update (noautoupdate and overall update with emit layou...
authorcaremoli <caremoli>
Tue, 29 Jun 2010 16:29:52 +0000 (16:29 +0000)
committercaremoli <caremoli>
Tue, 29 Jun 2010 16:29:52 +0000 (16:29 +0000)
src/SUIT/SUIT_DataObject.cxx
src/SUIT/SUIT_TreeModel.cxx
src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/SalomeApp_Study.cxx

index 8ca7fe141bf8abf00bfa0bceeb388e255dd70489..89d899a6096088a64edc5445a2562de956950e34 100755 (executable)
 #include <cstdio>
 #include <iostream>
 
+#include <sys/time.h>
+static long tcount=0;
+static long cumul;
+static timeval tv;
+#define START_TIMING gettimeofday(&tv,0);long tt0=tv.tv_usec+tv.tv_sec*1000000;
+#define END_TIMING(NUMBER) \
+  tcount=tcount+1;gettimeofday(&tv,0);cumul=cumul+tv.tv_usec+tv.tv_sec*1000000 -tt0; \
+  if(tcount==NUMBER){ std::cerr <<pthread_self()<<":"<<__FILE__<<":"<<__LINE__<<" temps CPU(mus): "<<cumul<< std::endl; tcount=0 ;cumul=0; }
+
 SUIT_DataObject::Signal* SUIT_DataObject::mySignal = 0;
 
 /*!
@@ -274,16 +283,20 @@ void SUIT_DataObject::appendChild( SUIT_DataObject* obj )
 */
 void SUIT_DataObject::insertChild( SUIT_DataObject* obj, int position )
 {
+  START_TIMING;
   if ( !obj || myChildren.contains( obj ) )
     return;
 
   int pos = position < 0 ? myChildren.count() : position;
   myChildren.insert( qMin( pos, (int)myChildren.count() ), obj );
   obj->setParent( this );
+  /*
   if(pos == 0)
     signal()->emitInserted( obj, this ,0);
   else
     signal()->emitInserted( obj, this ,myChildren.at(pos-1));
+    */
+  END_TIMING(100);
 }
 
 /*!
index 8eab45e8c4acfafa46f2100b8b77033595887bff..f1222c2a705086a724370cff25d23c6a0672f136 100755 (executable)
@@ -35,7 +35,7 @@ static long cumul;
 static timeval tv;
 #define START_TIMING gettimeofday(&tv,0);tt0=tv.tv_usec+tv.tv_sec*1000000;
 #define END_TIMING(NUMBER) \
-      tcount=tcount+1;gettimeofday(&tv,0);cumul=cumul+tv.tv_usec+tv.tv_sec*1000000 -tt0; \
+  tcount=tcount+1;gettimeofday(&tv,0);cumul=cumul+tv.tv_usec+tv.tv_sec*1000000 -tt0; \
   if(tcount==NUMBER){ std::cerr <<pthread_self()<<":"<<__FILE__<<":"<<__LINE__<<" temps CPU(mus): "<<cumul<< std::endl; tcount=0;cumul=0; }
 
 
@@ -334,8 +334,10 @@ void SUIT_TreeModel::TreeSync::updateItem( const ObjPtr& obj, const ItemPtr& ite
 {
   if( obj )
     obj->update();
+  /*
   if ( item && needUpdate( item ) ) 
     myModel->updateItem( item );
+    */
 }
 
 /*!
@@ -482,7 +484,7 @@ SUIT_TreeModel::~SUIT_TreeModel()
                                  this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject*,SUIT_DataObject* ) ) );
     SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                                  this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
-    SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
+    //SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
     delete myRoot;
   }
 
@@ -648,7 +650,7 @@ void SUIT_TreeModel::setRoot( SUIT_DataObject* r )
                                  this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject*,SUIT_DataObject* ) ) );
     SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                                  this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
-    SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
+    //SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
     delete myRoot;
   }
 
@@ -673,7 +675,7 @@ QVariant SUIT_TreeModel::data( const QModelIndex& index, int role ) const
     return QVariant();
 
   SUIT_DataObject* obj = object( index );
-  obj->setModified(false);
+  //obj->setModified(false);
 
   QColor c;
   QVariant val;
@@ -1024,7 +1026,7 @@ void SUIT_TreeModel::setAutoUpdate( const bool on )
                                this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject*,SUIT_DataObject* ) ) );
   SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                                this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
-  SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
+  //SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
   myAutoUpdate = on;
 
   if ( myAutoUpdate ) {
@@ -1032,7 +1034,7 @@ void SUIT_TreeModel::setAutoUpdate( const bool on )
                               this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject* ,SUIT_DataObject*) ) );
     SUIT_DataObject::connect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                               this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
-    SUIT_DataObject::connect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
+    //SUIT_DataObject::connect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
 
     updateTree();
   }
@@ -1105,7 +1107,12 @@ void SUIT_TreeModel::updateTree( const QModelIndex& index )
 void SUIT_TreeModel::updateTree( SUIT_DataObject* obj )
 {
   if(myAutoUpdate)
-    return;
+    {
+      emit layoutAboutToBeChanged();
+      emit layoutChanged();
+      emit modelUpdated();
+      return;
+    }
 
   if ( !obj )
     obj = root();
@@ -1113,9 +1120,12 @@ void SUIT_TreeModel::updateTree( SUIT_DataObject* obj )
   else if ( obj->root() != root() )
     return;
 
+  emit layoutAboutToBeChanged();
+
   synchronize<ObjPtr,ItemPtr,SUIT_TreeModel::TreeSync>( obj, 
                                                         treeItem( obj ), 
                                                         SUIT_TreeModel::TreeSync( this ) );
+  emit layoutChanged();
   emit modelUpdated();
 }
 
@@ -1128,13 +1138,13 @@ void SUIT_TreeModel::initialize()
                                this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject*,SUIT_DataObject* ) ) );
   SUIT_DataObject::disconnect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                                this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
-  SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
+  //SUIT_DataObject::disconnect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
   if ( autoUpdate() ) {
     SUIT_DataObject::connect( SIGNAL( inserted( SUIT_DataObject*, SUIT_DataObject*,SUIT_DataObject* ) ),
                               this, SLOT( onInserted( SUIT_DataObject*, SUIT_DataObject*,SUIT_DataObject* ) ) );
     SUIT_DataObject::connect( SIGNAL( removed( SUIT_DataObject*, SUIT_DataObject* ) ),
                               this, SLOT( onRemoved( SUIT_DataObject*, SUIT_DataObject* ) ) );
-    SUIT_DataObject::connect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
+    //SUIT_DataObject::connect( SIGNAL( updated( SUIT_DataObject* ) ), this, SLOT( onUpdated( SUIT_DataObject* ) ) );
   }
 
   myItems.clear(); // ????? is it really necessary
@@ -1216,12 +1226,13 @@ SUIT_TreeModel::TreeItem* SUIT_TreeModel::createItem( SUIT_DataObject* obj,
 
   SUIT_DataObject* afterObj = after ? object( after ) : 0;
   int row = afterObj ? afterObj->position() + 1 : 0;
+  //std::cerr << " SUIT_TreeModel::createItem " << row << ":" << afterObj << std::endl;
 
-  beginInsertRows( parentIdx, row, row );
+  //beginInsertRows( parentIdx, row, row );
 
   myItems[ obj ] = new TreeItem( obj, parent, after );
 
-  endInsertRows();
+  //endInsertRows();
 
   //obj->setModified(false);
 
@@ -1230,6 +1241,7 @@ SUIT_TreeModel::TreeItem* SUIT_TreeModel::createItem( SUIT_DataObject* obj,
 
 void SUIT_TreeModel::createItem( SUIT_DataObject* obj, SUIT_DataObject* parent, SUIT_DataObject* after )
 {
+  //std::cerr << " SUIT_TreeModel::createItem " << obj << ":" << parent << ":" << after << std::endl;
   if ( !treeItem(parent))
     return;
   createItem(obj,treeItem(parent),treeItem(after));
index 63c1df391d89ef55ec37b6f5c1c984863b02b36c..215abb3448fc30cf3cebabdc86e4d67c95896b83 100644 (file)
@@ -832,7 +832,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag )
       // temporary commented
       //ob->setUpdater( new SalomeApp_Updater() );
 
-      ob->setAutoUpdate(true);
+      ob->setAutoUpdate(false);
 
       connect( ob, SIGNAL( doubleClicked( SUIT_DataObject* ) ), this, SLOT( onDblClick( SUIT_DataObject* ) ) );
 
index 9fc945d6157ab15ebb0fe5eff9f982f9ec0b2b14..3a00942748022035a5905f0ce24594b63b3b8a69 100644 (file)
@@ -51,8 +51,8 @@ static long tcount=0;
 static long cumul;
 #define START_TIMING timeval tv; gettimeofday(&tv,0);tt0=tv.tv_usec+tv.tv_sec*1000000;
 #define END_TIMING(NUMBER) \
-    tcount=tcount+1;gettimeofday(&tv,0);cumul=cumul+tv.tv_usec+tv.tv_sec*1000000 -tt0; \
-  if(tcount==NUMBER){ std::cerr << __FILE__ << __LINE__ << " temps CPU(mus): " << cumul << std::endl; tcount=0;cumul=0; }
+  tcount=tcount+1;gettimeofday(&tv,0);cumul=cumul+tv.tv_usec+tv.tv_sec*1000000 -tt0; \
+  if(tcount==NUMBER){ std::cerr << pthread_self()<<":"<<__FILE__ << __LINE__ << " temps CPU(mus): " << cumul << std::endl; tcount=0;cumul=0; }
 
 using namespace std;
 
@@ -69,7 +69,7 @@ class Observer_i : public virtual POA_SALOME::Observer
 
     virtual void notifyObserver(const char* theID, const char* event)
     {
-      //START_TIMING;
+      START_TIMING;
 
       //MESSAGE("I'm notified of " << event << " of ID =  " << theID);
       _PTR(SObject) obj = myStudyDS->FindObjectID( theID );
@@ -123,12 +123,22 @@ class Observer_i : public virtual POA_SALOME::Observer
           }
           int pos = after ? father->childPos( after ) : 0;
           father->insertChild(suit_obj,pos+1);
+          /*
+          if (LightApp_Application* myApp=dynamic_cast<LightApp_Application*>(myStudy->application()))
+            if (SUIT_ProxyModel* myModel=dynamic_cast<SUIT_ProxyModel*>(myApp->objectBrowser()->model()))
+              myModel->createItem(suit_obj,father,after);
+              */
         }
         else
         {
           //MESSAGE("This should be for a module");
           SUIT_DataObject* father=myStudy->root();
           father->appendChild(suit_obj);
+          /*
+          if (LightApp_Application* myApp=dynamic_cast<LightApp_Application*>(myStudy->application()))
+            if (SUIT_ProxyModel* myModel=dynamic_cast<SUIT_ProxyModel*>(myApp->objectBrowser()->model()))
+              myModel->createItem(suit_obj,father,father->lastChild());
+              */
         }
         entry2SuitObject[theID]=suit_obj;
       }
@@ -169,7 +179,7 @@ class Observer_i : public virtual POA_SALOME::Observer
             MESSAGE("Want to modify an unknown object"  << theID);
           }
       }
-      //END_TIMING(10);
+      END_TIMING(100);
     }
 
   private: