From: vsv Date: Tue, 16 Jan 2018 14:40:34 +0000 (+0300) Subject: Issue #2358: Preserve state of folders on move in/out objects to a folder X-Git-Tag: V_3.0.0RC1~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cb7115539ed8b9dd4a7ebfa0ae828fd26e1860cd;p=modules%2Fshaper.git Issue #2358: Preserve state of folders on move in/out objects to a folder --- diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index e89546161..d7178aa43 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -64,7 +64,7 @@ public: //! Returns index of the object //! \param theObject object to find - virtual QModelIndex objectIndex(const ObjectPtr theObject, int theColumn = 1) const; + virtual QModelIndex objectIndex(const ObjectPtr theObject, int theColumn = 0) const; //! Clear internal data virtual void clear(); @@ -131,7 +131,7 @@ public: /// Returns an index which is root of the given document /// \param theDoc a document - QModelIndex documentRootIndex(DocumentPtr theDoc, int theColumn = 1) const; + QModelIndex documentRootIndex(DocumentPtr theDoc, int theColumn = 0) const; /// Returns last history object index virtual QModelIndex lastHistoryIndex() const; diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index f3f539626..6c2e61ffa 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -603,7 +603,7 @@ std::list XGUI_ObjectsBrowser::getStateForDoc(DocumentPtr theDoc) const QModelIndex aRootIdx = aModel->documentRootIndex(theDoc); int aNbChild = aModel->rowCount(aRootIdx); for (int i = 0; i < aNbChild; i++) { - QModelIndex aIdx = aModel->index(i, 1, aRootIdx); + QModelIndex aIdx = aModel->index(i, 0, aRootIdx); aStates.push_back(myTreeView->isExpanded(aIdx)); } return aStates; @@ -638,3 +638,26 @@ void XGUI_ObjectsBrowser::updateAllIndexes(int theColumn, const QModelIndex& the } } } + +QMap XGUI_ObjectsBrowser::getFoldersState(DocumentPtr theDoc) const +{ + QMap aMap; + + int aNb = theDoc->size(ModelAPI_Folder::group()); + ObjectPtr aObj; + for (int i = 0; i < aNb; i++) { + aObj = theDoc->object(ModelAPI_Folder::group(), i); + QModelIndex aIdx = myDocModel->objectIndex(aObj); + aMap[aObj] = myTreeView->isExpanded(aIdx); + } + return aMap; +} + +void XGUI_ObjectsBrowser::setFoldersState(const QMap& theStates) +{ + QMap::const_iterator aIt; + for (aIt = theStates.constBegin(); aIt != theStates.constEnd(); aIt++) { + QModelIndex aIdx = myDocModel->objectIndex(aIt.key()); + myTreeView->setExpanded(aIdx, aIt.value()); + } +} diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index 372d4bb76..c5eb366de 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -26,10 +26,12 @@ #include #include #include +#include #include #include #include +#include class ModuleBase_IDocumentDataModel; class XGUI_DataModel; @@ -211,6 +213,10 @@ Q_OBJECT /// \param theParent - a parent item (by default from root) void updateAllIndexes(int theColumn = 0, const QModelIndex& theParent = QModelIndex()); + QMap getFoldersState(DocumentPtr theDoc) const; + + void setFoldersState(const QMap& 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 e55494d77..5969a96fc 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -2675,10 +2675,14 @@ void XGUI_Workshop::insertToFolder(bool isBefore) QString aDescription = contextMenuMgr()->action( isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text(); + QMap aStates = myObjectBrowser->getFoldersState(aDoc); + aMgr->startOperation(aDescription.toStdString()); aDoc->moveToFolder(aFeatures, aFolder); aMgr->finishOperation(); + myObjectBrowser->setFoldersState(aStates); + updateCommandStatus(); } @@ -2691,13 +2695,16 @@ void XGUI_Workshop::moveOutFolder(bool isBefore) SessionPtr aMgr = ModelAPI_Session::get(); DocumentPtr aDoc = aMgr->activeDocument(); - QString aDescription = contextMenuMgr()->action( isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text(); + QMap aStates = myObjectBrowser->getFoldersState(aDoc); + aMgr->startOperation(aDescription.toStdString()); aDoc->removeFromFolder(aFeatures, isBefore); aMgr->finishOperation(); + myObjectBrowser->setFoldersState(aStates); + updateCommandStatus(); }