From: vsv Date: Thu, 30 Oct 2014 17:00:54 +0000 (+0300) Subject: Issue #189: Clear GUI state on module closing X-Git-Tag: V_0.5~58^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=17796c2c2b379ae176a3b81cc867f0da7f894707;p=modules%2Fshaper.git Issue #189: Clear GUI state on module closing --- diff --git a/src/NewGeom/NewGeom_DataModel.cpp b/src/NewGeom/NewGeom_DataModel.cpp index 76d848046..8593ab632 100644 --- a/src/NewGeom/NewGeom_DataModel.cpp +++ b/src/NewGeom/NewGeom_DataModel.cpp @@ -65,8 +65,7 @@ bool NewGeom_DataModel::saveAs(const QString& thePath, CAM_Study* theStudy, QStr bool NewGeom_DataModel::close() { - SessionPtr aMgr = ModelAPI_Session::get(); - aMgr->moduleDocument()->close(); + myModule->workshop()->closeDocument(); return LightApp_DataModel::close(); } diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index 2744d196d..14a8735b1 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -42,6 +42,7 @@ XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) XGUI_DocumentDataModel::~XGUI_DocumentDataModel() { clearModelIndexes(); + clearSubModels(); } void XGUI_DocumentDataModel::processEvent(const boost::shared_ptr& theMessage) @@ -80,10 +81,9 @@ void XGUI_DocumentDataModel::processEvent(const boost::shared_ptr::const_iterator aIt; - for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) { - if ((*aIt)->hasDocument(aDoc)) { - aPartModel = (*aIt); + foreach (XGUI_PartModel* aPart, myPartModels) { + if (aPart->hasDocument(aDoc)) { + aPartModel = aPart; break; } } @@ -123,10 +123,9 @@ void XGUI_DocumentDataModel::processEvent(const boost::shared_ptr::const_iterator aIt; - for (aIt = myPartModels.constBegin(); aIt != myPartModels.constEnd(); ++aIt) { - if ((*aIt)->hasDocument(aDoc)) { - aPartModel = (*aIt); + foreach (XGUI_PartModel* aPart, myPartModels) { + if (aPart->hasDocument(aDoc)) { + aPartModel = aPart; break; } } @@ -361,12 +360,18 @@ QModelIndex* XGUI_DocumentDataModel::getModelIndex(const QModelIndex& theIndex) void XGUI_DocumentDataModel::clearModelIndexes() { - QList::const_iterator aIt; - for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt) - delete (*aIt); + foreach (QModelIndex* aIndex, myIndexes) + delete aIndex; myIndexes.clear(); } +void XGUI_DocumentDataModel::clearSubModels() +{ + foreach (XGUI_PartModel* aPart, myPartModels) + delete aPart; + myPartModels.clear(); +} + ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const { if (theIndex.internalId() == PartsFolder) @@ -570,3 +575,13 @@ QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const } return QModelIndex(); } + + +void XGUI_DocumentDataModel::clear() +{ + clearModelIndexes(); + clearSubModels(); + myActivePart = 0; + myActivePartIndex = QModelIndex(); + myModel->setItemsColor(ACTIVE_COLOR); +} diff --git a/src/XGUI/XGUI_DocumentDataModel.h b/src/XGUI/XGUI_DocumentDataModel.h index c24360827..a7e9fc944 100644 --- a/src/XGUI/XGUI_DocumentDataModel.h +++ b/src/XGUI/XGUI_DocumentDataModel.h @@ -78,6 +78,10 @@ Q_OBJECT void rebuildDataTree(); + //! Clear internal data + void clear(); + + private: enum @@ -98,6 +102,9 @@ Q_OBJECT //! Deletes all saved pointers on QModelIndex objects. void clearModelIndexes(); + //! Deletes all saved pointers on QModelIndex objects. + void clearSubModels(); + //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model void removeSubModel(int theModelId); diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 4268115fd..699d6e518 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -84,6 +84,14 @@ void XGUI_DataTree::commitData(QWidget* theEditor) } } +void XGUI_DataTree::clear() +{ + mySelectedData.clear(); + XGUI_DocumentDataModel* aModel = dataModel(); + aModel->clear(); + reset(); +} + //******************************************************************** //******************************************************************** //******************************************************************** @@ -348,3 +356,11 @@ void XGUI_ObjectsBrowser::processEvent(const boost::shared_ptr& { myDocModel->processEvent(theMessage); } + + +//*************************************************** +void XGUI_ObjectsBrowser::clearContent() +{ + myObjectsList.clear(); + myTreeView->clear(); +} diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index ebcaffe08..9e7f901d7 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -36,6 +36,9 @@ signals: //! Emited on context menu request void contextMenuRequested(QContextMenuEvent* theEvent); +public slots: + virtual void clear(); + protected slots: virtual void commitData(QWidget* theEditor); @@ -96,6 +99,9 @@ Q_OBJECT void processEvent(const boost::shared_ptr& theMessage); + // Resets the object browser into initial state + void clearContent(); + signals: //! Emited when selection is changed void selectionChanged(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 22358aab9..1d72cff78 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1306,3 +1306,15 @@ void XGUI_Workshop::setDisplayMode(const QList& theList, int theMode) if (theList.size() > 0) myDisplayer->updateViewer(); } + +//************************************************************** +void XGUI_Workshop::closeDocument() +{ + myDisplayer->closeLocalContexts(); + myDisplayer->eraseAll(); + objectBrowser()->clearContent(); + + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->moduleDocument()->close(); + objectBrowser()->clearContent(); +} diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index d5159189a..764e19f2d 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -214,6 +214,8 @@ signals: void activateLastPart(); + void closeDocument(); + protected: bool event(QEvent * theEvent); //Event-loop processing methods: