From acfb7413a39dd03b70cd8d2847264e083eac2a25 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 18 Sep 2015 14:48:39 +0300 Subject: [PATCH] Avoid crash on using of wrong folder as a model for opening --- src/Model/Model_Document.cpp | 10 +++------- src/XGUI/XGUI_DataModel.cpp | 14 +++++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 4ff65b48c..6c7ea7a3c 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -168,12 +168,12 @@ bool Model_Document::load(const char* theFileName, DocumentPtr theThis) break; } } + std::shared_ptr aSession = + std::dynamic_pointer_cast(Model_Session::get()); if (!isError) { myDoc = aLoaded; myDoc->SetUndoLimit(UNDO_LIMIT); // to avoid the problem that feature is created in the current, not this, document - std::shared_ptr aSession = - std::dynamic_pointer_cast(Model_Session::get()); aSession->setActiveDocument(anApp->getDocument(myID), false); aSession->setCheckTransactions(false); if (myObjs) @@ -187,11 +187,7 @@ bool Model_Document::load(const char* theFileName, DocumentPtr theThis) // this is done in Part result "activate", so no needed here. Causes not-blue active part. // aSession->setActiveDocument(anApp->getDocument(myID), true); } else { // open failed, but new documnet was created to work with it: inform the model - static std::shared_ptr aMsg( - new Events_Message(Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED))); - Events_Loop::loop()->send(aMsg); - TDF_LabelList anEmpty; - myObjs->synchronizeFeatures(anEmpty, true, true); + aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false); } return !isError; } diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 704fd0738..2485d367c 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -266,10 +266,13 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get()); if (aDocRoot.isValid()) emit dataChanged(aDocRoot, aDocRoot); -#ifdef _DEBUG - else - Events_Error::send("Problem with Data Model definition of sub-document"); -#endif + else + // We have got a new document + rebuildDataTree(); +//#ifdef _DEBUG +// else +// Events_Error::send("Problem with Data Model definition of sub-document"); +//#endif } } } @@ -283,7 +286,8 @@ void XGUI_DataModel::clear() //****************************************************** void XGUI_DataModel::rebuildDataTree() { - + beginResetModel(); + endResetModel(); } //****************************************************** -- 2.39.2