From: vsr Date: Tue, 29 Mar 2011 13:41:53 +0000 (+0000) Subject: 0021216: EDF 1483 GEOM,GUI,KERNEL: Degradation of performance of the "publish" and... X-Git-Tag: V6_3_0a1~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=39b24532500fc2e69a07b5ff21420ed29447d46e;p=modules%2Fgui.git 0021216: EDF 1483 GEOM,GUI,KERNEL: Degradation of performance of the "publish" and "display" actions in GEOM --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 4b49152d4..cf4a79140 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -76,7 +76,6 @@ #include #include #include -#include #include #include @@ -1733,6 +1732,7 @@ QWidget* LightApp_Application::createWindow( const int flag ) QString EntryCol = QObject::tr( "ENTRY_COLUMN" ); SUIT_AbstractModel* treeModel = dynamic_cast( ob->model() ); + treeModel->setSearcher( this ); treeModel->registerColumn( 0, EntryCol, LightApp_DataObject::EntryId ); treeModel->setAppropriate( EntryCol, Qtx::Toggled ); @@ -3583,3 +3583,9 @@ QString LightApp_Application::browseObjects( const QStringList& theEntryList, return aResult; } + +SUIT_DataObject* LightApp_Application::findObject( const QString& id ) const +{ + LightApp_Study* study = dynamic_cast( activeStudy() ); + return study ? study->findObjectByEntry( id ) : 0; +} diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index e31c34214..59dba611e 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -32,6 +32,7 @@ #endif // _MSC_VER > 1000 #include "LightApp.h" +#include #include #include @@ -64,7 +65,7 @@ class QTimer; Description : Application containing only LightApp module */ -class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application +class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application, public SUIT_DataSearcher { Q_OBJECT @@ -163,6 +164,8 @@ public: const bool theIsApplyAndClose = true, const bool theIsOptimizedBrowsing = false ); + virtual SUIT_DataObject* findObject( const QString& ) const; + signals: void studyOpened(); void studySaved(); diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index c79713e2d..2583d8a84 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -30,7 +30,7 @@ #include #include -SUIT_AbstractModel::SUIT_AbstractModel() +SUIT_AbstractModel::SUIT_AbstractModel() : mySearcher( 0 ) { } @@ -49,9 +49,15 @@ SUIT_AbstractModel::operator const QObject*() const return dynamic_cast( this ); } +SUIT_DataSearcher* SUIT_AbstractModel::searcher() const +{ + return mySearcher; +} - - +void SUIT_AbstractModel::setSearcher( SUIT_DataSearcher* s ) +{ + mySearcher = s; +} /*! @@ -492,23 +498,22 @@ SUIT_TreeModel::~SUIT_TreeModel() void SUIT_TreeModel::registerColumn( const int group_id, const QString& name, const int custom_id ) { bool found = false; - for( int i=0, n=myColumns.size(); i 0) - needSignal = true; + needSignal = myVisibilityMap.remove( id ) > 0; } - if(needSignal) { - QModelIndexList lst = match(index(0,root()->customData(Qtx::IdType).toInt()), DisplayRole, id, 1, Qt::MatchExactly | Qt::MatchRecursive); - if(!lst.isEmpty()) { - QModelIndex idx = index(lst[0].row(), SUIT_DataObject::VisibilityId ,lst[0].parent()); - emit dataChanged(idx,idx); + if ( needSignal ) { + QModelIndexList lst; + if ( searcher() ) { + SUIT_DataObject* o = searcher()->findObject( id ); + if ( o ) lst << index( o ); + } + else { + lst = match( index( 0, root()->customData( Qtx::IdType ).toInt() ), DisplayRole, id, 1, Qt::MatchExactly | Qt::MatchRecursive ); + } + if ( !lst.isEmpty() ) { + QModelIndex idx = index( lst.first().row(), SUIT_DataObject::VisibilityId, lst.first().parent() ); + emit dataChanged( idx, idx ); } } } @@ -693,23 +706,32 @@ void SUIT_TreeModel::setVisibilityState(const QString& id, Qtx::VisibilityState \param id - column name \param state - visible state */ -void SUIT_TreeModel::setVisibilityStateForAll(Qtx::VisibilityState state) { - if(state != Qtx::UnpresentableState) { +void SUIT_TreeModel::setVisibilityStateForAll( Qtx::VisibilityState state ) +{ + if ( state != Qtx::UnpresentableState ) { VisibilityMap::ConstIterator it = myVisibilityMap.begin(); - while(it != myVisibilityMap.end() ) { - if(it.value() != state) - setVisibilityState(it.key(), state); + while ( it != myVisibilityMap.end() ) { + if ( it.value() != state ) + setVisibilityState( it.key(), state ); it++; } - } else { + } + else { QList anIds = myVisibilityMap.keys(); myVisibilityMap.clear(); QList::ConstIterator it = anIds.begin(); - while(it != anIds.end()){ - QModelIndexList lst = match(index(0,root()->customData(Qtx::IdType).toInt()), DisplayRole, (*it), 1, Qt::MatchExactly | Qt::MatchRecursive); - if(!lst.isEmpty()) { - QModelIndex idx = index(lst[0].row(), SUIT_DataObject::VisibilityId ,lst[0].parent()); - emit dataChanged(idx,idx); + while ( it != anIds.end() ) { + QModelIndexList lst; + if ( searcher() ) { + SUIT_DataObject* o = searcher()->findObject( *it ); + if ( o ) lst << index( o ); + } + else { + lst = match( index( 0, root()->customData( Qtx::IdType ).toInt() ), DisplayRole, (*it), 1, Qt::MatchExactly | Qt::MatchRecursive ); + } + if ( !lst.isEmpty() ) { + QModelIndex idx = index( lst.first().row(), SUIT_DataObject::VisibilityId ,lst.first().parent() ); + emit dataChanged( idx, idx ); } it++; } @@ -722,11 +744,10 @@ void SUIT_TreeModel::setVisibilityStateForAll(Qtx::VisibilityState state) { \param id - column name \return visible state */ -Qtx::VisibilityState SUIT_TreeModel::visibilityState(const QString& id) const { - if(myVisibilityMap.contains(id)) - return myVisibilityMap.value(id); - else - return Qtx::UnpresentableState; +Qtx::VisibilityState SUIT_TreeModel::visibilityState( const QString& id ) const +{ + VisibilityMap::const_iterator it = myVisibilityMap.find( id ); + return it != myVisibilityMap.end() ? it.value() : Qtx::UnpresentableState; } /*! @@ -1761,6 +1782,16 @@ bool SUIT_ProxyModel::isSortingEnabled() const return mySortingEnabled; } +SUIT_DataSearcher* SUIT_ProxyModel::searcher() const +{ + return treeModel() ? treeModel()->searcher() : 0; +} + +void SUIT_ProxyModel::setSearcher( SUIT_DataSearcher* s ) +{ + if ( treeModel() ) treeModel()->setSearcher( s ); +} + /*! \brief Get item delegate for the model. \return new item delegate diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index f47033ff2..b8ad06bf2 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -41,8 +41,16 @@ class SUIT_DataObject; class SUIT_TreeModel; +class SUIT_EXPORT SUIT_DataSearcher +{ +public: + virtual SUIT_DataObject* findObject( const QString& ) const = 0; +}; + class SUIT_EXPORT SUIT_AbstractModel { + SUIT_DataSearcher* mySearcher; + public: SUIT_AbstractModel(); @@ -78,8 +86,10 @@ public: virtual Qtx::VisibilityState visibilityState(const QString& id) const = 0; virtual void setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ) = 0; virtual Qtx::HeaderViewFlags headerFlags( const QString& name ) const = 0; - virtual void emitClicked( SUIT_DataObject* obj, const QModelIndex& index) = 0; + virtual void emitClicked( SUIT_DataObject* obj, const QModelIndex& index) = 0; + virtual SUIT_DataSearcher* searcher() const; + virtual void setSearcher( SUIT_DataSearcher* ); }; @@ -259,6 +269,8 @@ public: virtual Qtx::HeaderViewFlags headerFlags( const QString& name ) const; virtual void emitClicked( SUIT_DataObject* obj, const QModelIndex& index); + virtual SUIT_DataSearcher* searcher() const; + virtual void setSearcher( SUIT_DataSearcher* ); QAbstractItemDelegate* delegate() const; diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index af95c76ee..64f0c4173 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -52,7 +52,7 @@ #include #include CORBA_SERVER_HEADER(SALOME_Exception) -using namespace std; +//#define NOTIFY_BY_EVENT class ObserverEvent : public QEvent { @@ -81,23 +81,33 @@ public: fillEntryMap(); } + SUIT_DataObject* findObject( const char* theID ) const + { + EntryMap::const_iterator it = entry2SuitObject.find( theID ); + return it != entry2SuitObject.end() ? it->second : 0; + } + virtual void notifyObserverID(const char* theID, CORBA::Long event) { +#ifdef NOTIFY_BY_EVENT QCoreApplication::postEvent(this,new ObserverEvent(theID,event)); +#else + notifyObserverID_real(theID,event); +#endif } virtual bool event(QEvent *event) { if (event->type() == QEvent::User ) - { - //START_TIMING(notify); - notifyObserverID_real(static_cast(event)->_anID.c_str(),static_cast(event)->_event); - //END_TIMING(notify,100); - } + { + //START_TIMING(notify); + notifyObserverID_real(static_cast(event)->_anID.c_str(),static_cast(event)->_event); + //END_TIMING(notify,100); + } return true; } - void notifyObserverID_real(const char* theID, CORBA::Long event) + void notifyObserverID_real(const std::string& theID, long event) { SalomeApp_DataObject* suit_obj; @@ -111,16 +121,15 @@ public: return; } _PTR(SObject) obj = myStudyDS->FindObjectID( theID ); - std::string entry_str = theID; - int last2Pnt_pos = entry_str.rfind( ":" ); - std::string parent_id = entry_str.substr( 0, last2Pnt_pos ); - int tag = atoi( entry_str.substr( last2Pnt_pos+1 ).c_str() ); + int last2Pnt_pos = theID.rfind( ":" ); + std::string parent_id = theID.substr( 0, last2Pnt_pos ); + int tag = atoi( theID.substr( last2Pnt_pos+1 ).c_str() ); if ( parent_id.length() == 3 ) // "0:1" - root item? { // It's probably a SComponent _PTR(SComponent) aSComp = obj->GetFatherComponent(); - if ( aSComp && !aSComp->IsNull() && aSComp->GetID() == entry_str ) + if ( aSComp && !aSComp->IsNull() && aSComp->GetID() == theID ) suit_obj = new SalomeApp_ModuleObject( aSComp ); else suit_obj = new SalomeApp_DataObject( obj ); @@ -153,8 +162,8 @@ public: std::string obj_id = parent_id.substr( 4 ); std::string anID; - string::size_type debut = 0; - string::size_type fin; + std::string::size_type debut = 0; + std::string::size_type fin; SalomeApp_DataObject* anObj = dynamic_cast( myStudy->root() ); while ( 1 ) { @@ -226,14 +235,14 @@ public: suit_obj = it->second; /* Define visibility state */ - if( suit_obj ) { + bool isComponent = dynamic_cast( suit_obj ) != 0; + if ( suit_obj && !isComponent ) { QString moduleTitle = ((CAM_Application*)myStudy->application())->moduleTitle(suit_obj->componentDataType()); - if(!moduleTitle.isEmpty()) { + if (!moduleTitle.isEmpty()) { LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(moduleTitle,false); - - if(aDisplayer && !myStudy->isComponent(theID)) { - if(aDisplayer->canBeDisplayed(theID)) { - myStudy->setVisibilityState( theID, Qtx::HiddenState ); + if(aDisplayer) { + if(aDisplayer->canBeDisplayed(theID.c_str())) { + myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState ); //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!"); } else MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!"); @@ -887,6 +896,12 @@ void SalomeApp_Study::markAsSavedIn(QString theFileName) setIsSaved(true); } +LightApp_DataObject* SalomeApp_Study::findObjectByEntry( const QString& theEntry ) +{ + LightApp_DataObject* o = dynamic_cast( myObserver ? myObserver->findObject( theEntry.toLatin1().constData() ) : 0 ); + return o; +} + /*! Deletes all references to object \param obj - object diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index cabef2056..e4436b86b 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -83,6 +83,8 @@ public: virtual void restoreState(int savePoint); void markAsSavedIn(QString theFileName); + virtual LightApp_DataObject* findObjectByEntry( const QString& theEntry ); + protected: virtual void saveModuleData ( QString theModuleName, QStringList theListOfFiles ); virtual void openModuleData ( QString theModuleName, QStringList& theListOfFiles );