From 8649dfc739a33e0b03b027583608ccbb4f96350b Mon Sep 17 00:00:00 2001 From: asv Date: Fri, 10 Mar 2006 09:28:44 +0000 Subject: [PATCH] Improvements related with creation of "Gui states" object. Now it will always be the last one in the tree. --- src/SalomeApp/SalomeApp_Application.cxx | 43 ++++++++++++++++++------- src/SalomeApp/SalomeApp_Application.h | 2 +- src/SalomeApp/SalomeApp_Study.cxx | 12 +++++++ src/SalomeApp/SalomeApp_Study.h | 3 ++ 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index a1502a093..9d17c32e6 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -582,11 +582,12 @@ void SalomeApp_Application::onLoadScript( ) /*!Private SLOT. On save GUI state.*/ void SalomeApp_Application::onSaveGUIState() { - SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); - if ( !appStudy ) return; - - SalomeApp_VisualState( this ).storeState(); - updateObjectBrowser( false ); + SalomeApp_Study* study = dynamic_cast( activeStudy() ); + if ( study ) { + SalomeApp_VisualState( this ).storeState(); + updateSavePointDataObjects( study ); + objectBrowser()->updateTree( study->root() ); + } } /*!Gets file filter. @@ -1000,6 +1001,23 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* study ) } } +/*! utility function. returns true if list view item that correspond to given SUIT_DataObject is open. + only first level items are traversed */ +bool isListViewItemOpen( QListView* lv, const SUIT_DataObject* dobj ) +{ + if ( !lv || !dobj ) + return false; + + QListViewItem* item = lv->firstChild(); + while ( item ) { + OB_ListItem* ob_item = dynamic_cast( item ); + if ( ob_item && ob_item->dataObject() == dobj ) + return ob_item->isOpen(); + item = item->nextSibling(); + } + return false; +} + /*! updateSavePointDataObjects: syncronize data objects that correspond to save points (gui states)*/ void SalomeApp_Application::updateSavePointDataObjects( SalomeApp_Study* study ) { @@ -1034,12 +1052,12 @@ void SalomeApp_Application::updateSavePointDataObjects( SalomeApp_Study* study ) // case 4: everything already exists.. here may be a problem: we want "GUI states" root object // to be always the last one in the tree. Here we check - if it is not the last one - remove and // re-create it. - // if ( guiRootObj->nextBrother() ) { - // bool isOpen = guiRootObj->isOpen(); - // delete guiRootObj; - // guiRootObj = new SalomeApp_SavePointRootObject( study->root() ); - // guiRootObj->setOpen( isOpen ); - // } + bool isOpen( false ); + if ( guiRootObj->nextBrother() ) { + isOpen = isListViewItemOpen( ob->listView(), guiRootObj ); + delete guiRootObj; + guiRootObj = new SalomeApp_SavePointRootObject( study->root() ); + } // store data objects in a map id-to-DataObject QMap mapDO; @@ -1063,5 +1081,8 @@ void SalomeApp_Application::updateSavePointDataObjects( SalomeApp_Study* study ) // delete DataObjects that are still in the map -- their IDs were not found in data model for ( QMap::Iterator it = mapDO.begin(); it != mapDO.end(); ++it ) delete it.data(); + + if ( isOpen ) // set open if we recreated guiRootObj and it was previously open.. + guiRootObj->setOpen( true ); } diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 36960f249..e8ba1d4b4 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -69,6 +69,7 @@ public: static QString defaultEngineIOR(); SUIT_ViewManager* newViewManager(const QString&); + void updateSavePointDataObjects( SalomeApp_Study* ); public slots: virtual bool onOpenDoc( const QString& ); @@ -91,7 +92,6 @@ protected: virtual void createPreferences( LightApp_Preferences* ); virtual void updateDesktopTitle(); - void updateSavePointDataObjects( SalomeApp_Study* ); private slots: void onDeleteInvalidReferences(); diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 3a41ac01a..be3e37d11 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -736,3 +736,15 @@ std::string SalomeApp_Study::getVisualComponentName() return "Interface Applicative"; } +//================================================================ +// Function : updateModelRoot +/*! Purpose : slot called on change of a root of a data model. redefined from CAM_Study*/ +//================================================================ +void SalomeApp_Study::updateModelRoot( const CAM_DataModel* dm ) +{ + LightApp_Study::updateModelRoot( dm ); + + // calling updateSavePointDataObjects in order to set correct order of "Gui states" object + // it must always be the last one. + ((SalomeApp_Application*)application())->updateSavePointDataObjects( this ); +} diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index b3edd2564..9034b1333 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -89,6 +89,9 @@ protected: virtual bool openDataModel( const QString&, CAM_DataModel* ); void setStudyDS(const _PTR(Study)& s ); +protected slots: + virtual void updateModelRoot( const CAM_DataModel* ); + private: QString newStudyName() const; -- 2.39.2