From 61ce7909f1050cef50340e15f3f5ca39d8dbd39e Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 24 Nov 2016 17:45:12 +0300 Subject: [PATCH] Issue #1856: Save state of tree nodes --- src/PartSet/PartSet_MenuMgr.cpp | 24 ++++++++++++++++++++---- src/PartSet/PartSet_MenuMgr.h | 4 ++++ src/PartSet/PartSet_Module.cpp | 2 +- src/PartSet/PartSet_Module.h | 6 +++--- src/XGUI/XGUI_ObjectsBrowser.cpp | 31 +++++++++++++++++++++++++++++++ src/XGUI/XGUI_ObjectsBrowser.h | 10 ++++++++++ src/XGUI/XGUI_Workshop.cpp | 16 ++++++++++++++++ 7 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index ce600a203..54ada4890 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -32,11 +32,11 @@ #include #include #include +#include #include #include #include -#include #include #include @@ -457,9 +457,24 @@ void PartSet_MenuMgr::onActivatePart(bool) aPart = std::dynamic_pointer_cast(aPartFeature->firstResult()); } } - if (aPart.get()) - aPart->activate(); + if (aPart.get()) { + activatePart(aPart); myModule->workshop()->updateCommandStatus(); + } + } +} + +void PartSet_MenuMgr::activatePart(ResultPartPtr thePart) const +{ + bool isFirstLoad = !thePart->partDoc().get(); + thePart->activate(); + if (isFirstLoad) { + XGUI_Workshop* aWorkshop = myModule->getWorkshop(); + XGUI_ObjectsBrowser* aObjBrowser = aWorkshop->objectBrowser(); + DocumentPtr aDoc = thePart->partDoc(); + std::list aStates; + aDoc->restoreNodesState(aStates); + aObjBrowser->setStateForDoc(aDoc, aStates); } } @@ -475,7 +490,8 @@ void PartSet_MenuMgr::activatePartSet() const SessionPtr aMgr = ModelAPI_Session::get(); bool isNewTransaction = !aMgr->isOperation(); // activation may cause changes in current features in document, so it must be in transaction - if (isNewTransaction) aMgr->startOperation("Activation"); + if (isNewTransaction) + aMgr->startOperation("Activation"); aMgr->setActiveDocument(aMgr->moduleDocument()); if (isNewTransaction) aMgr->finishOperation(); diff --git a/src/PartSet/PartSet_MenuMgr.h b/src/PartSet/PartSet_MenuMgr.h index 5061b1fec..454c0acf8 100644 --- a/src/PartSet/PartSet_MenuMgr.h +++ b/src/PartSet/PartSet_MenuMgr.h @@ -8,6 +8,7 @@ #define PartSet_MenuMgr_H #include +#include #include #include @@ -56,6 +57,9 @@ public: /// Returns list of granted operation indices virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const; + /// Activates a Part document + void activatePart(ResultPartPtr thePart) const; + public slots: /// Processes the context menu action click /// \param isChecked a state of toggle if the action is checkable diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 921205e73..8d004cded 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1308,7 +1308,7 @@ void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex) if (aPart->partDoc() == aMgr->activeDocument()) { myMenuMgr->activatePartSet(); } else { - aPart->activate(); + myMenuMgr->activatePart(aPart); } } } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index aeae34146..06fdf458c 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -324,6 +324,9 @@ public: /// \return theAttribute virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape); + /// Returns the workshop + XGUI_Workshop* getWorkshop() const; + public slots: /// Redefines the parent method in order to customize the next case: /// If the sketch nested operation is active and the presentation is not visualized in the viewer, @@ -404,9 +407,6 @@ protected: //! Delete features virtual bool deleteObjects(); - /// Returns the workshop - XGUI_Workshop* getWorkshop() const; - void setDefaultConstraintShown(); private: diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 4512cf1fe..eb40a0a9c 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -536,3 +536,34 @@ void XGUI_ObjectsBrowser::onAfterModelReset() myTreeView->setExpanded(aIndex, true); } } + +std::list XGUI_ObjectsBrowser::getStateForDoc(DocumentPtr theDoc) const +{ + std::list aStates; + XGUI_DataModel* aModel = dataModel(); + QModelIndex aRootIdx = aModel->documentRootIndex(theDoc); + int aNbChild = aModel->rowCount(aRootIdx); + for (int i = 0; i < aNbChild; i++) { + QModelIndex aIdx = aModel->index(i, 0, aRootIdx); + aStates.push_back(myTreeView->isExpanded(aIdx)); + } + return aStates; +} + +void XGUI_ObjectsBrowser::setStateForDoc(DocumentPtr theDoc, const std::list& theStates) +{ + if (theStates.size() == 0) + return; + XGUI_DataModel* aModel = dataModel(); + QModelIndex aRootIdx = aModel->documentRootIndex(theDoc); + int aNbChild = aModel->rowCount(aRootIdx); + + std::list::const_iterator aIt; + int i = 0; + for (aIt = theStates.cbegin(); aIt != theStates.cend(); aIt++, i++) { + if (i >= aNbChild ) + break; + QModelIndex aIdx = aModel->index(i, 0, aRootIdx); + myTreeView->setExpanded(aIdx, (*aIt)); + } +} diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index 2b9ab1803..416088e32 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -185,6 +185,16 @@ Q_OBJECT /// \param theReader the reader object void setXMLReader(Config_DataModelReader* theReader); + /// Returns list of folders opened state for the given document + /// \param theDoc the document + /// \return list of booleans with state expanded or not + std::list getStateForDoc(DocumentPtr theDoc) const; + + /// Set folders opened state for the given document + /// \param theDoc the document + /// \param theStates list of booleans with state expanded or not + void setStateForDoc(DocumentPtr theDoc, const std::list& theStates); + public slots: //! Called on Edit command request void onEditItem(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 64954b4ec..f569608b9 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -698,7 +698,16 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list& { QApplication::restoreOverrideCursor(); SessionPtr aMgr = ModelAPI_Session::get(); + + std::list aDocList = aMgr->allOpenedDocuments(); + std::list::const_iterator aIt; + for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) { + std::list aState = myObjectBrowser->getStateForDoc(*aIt); + (*aIt)->storeNodesState(aState); + } + aMgr->save(theName.toLatin1().constData(), theFileNames); + QApplication::restoreOverrideCursor(); } @@ -765,6 +774,13 @@ void XGUI_Workshop::openDirectory(const QString& theDirectory) aSession->closeAll(); aSession->load(myCurrentDir.toLatin1().constData()); myObjectBrowser->rebuildDataTree(); + + // Open first level of data tree + DocumentPtr aRootDoc = aSession->moduleDocument(); + std::list aStates; + aRootDoc->restoreNodesState(aStates); + myObjectBrowser->setStateForDoc(aRootDoc, aStates); + updateCommandStatus(); #ifndef HAVE_SALOME myMainWindow->setCurrentDir(myCurrentDir, true); -- 2.39.2