From: caremoli Date: Tue, 29 Jun 2010 16:29:52 +0000 (+0000) Subject: CCAR: optimisation of qt tree update (noautoupdate and overall update with emit layou... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=170d56b8da0acfc1f8d4e8bdc919f199b77c4ab6;p=modules%2Fgui.git CCAR: optimisation of qt tree update (noautoupdate and overall update with emit layoutChanged() ) --- diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index 8ca7fe141..89d899a60 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -28,6 +28,15 @@ #include #include +#include +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 <setParent( this ); + /* if(pos == 0) signal()->emitInserted( obj, this ,0); else signal()->emitInserted( obj, this ,myChildren.at(pos-1)); + */ + END_TIMING(100); } /*! diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 8eab45e8c..f1222c2a7 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -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 <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( 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)); diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 63c1df391..215abb344 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -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* ) ) ); diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 9fc945d61..3a0094274 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -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(myStudy->application())) + if (SUIT_ProxyModel* myModel=dynamic_cast(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(myStudy->application())) + if (SUIT_ProxyModel* myModel=dynamic_cast(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: