From: vsv Date: Thu, 30 May 2019 09:25:50 +0000 (+0300) Subject: Fix for crash with data tree X-Git-Tag: VEDF2019Lot4~118 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=59a8b86f22d27f572a84ed942b3d130eb776a4c0;p=modules%2Fshaper.git Fix for crash with data tree --- diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 6594e26ef..32548038c 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -446,3 +446,10 @@ DocumentPtr XGUI_DataModel::document(const QModelIndex& theIndex) const ModuleBase_ITreeNode* aNode = (ModuleBase_ITreeNode*)theIndex.internalPointer(); return aNode->document(); } + + +//****************************************************** +bool XGUI_DataModel::hasNode(ModuleBase_ITreeNode* theNode) const +{ + return myRoot->hasSubNode(theNode); +} diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index 6ca86ce55..305877371 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -155,14 +155,23 @@ public: /// \param theIndex an index to check bool hasIndex(const QModelIndex& theIndex) const; + /// Returns true if the given node is a parto of the data tree + /// \param theNode a node to check + bool hasNode(ModuleBase_ITreeNode* theNode) const; + + /// Returns document of the given index + /// \param theIndex an index to check DocumentPtr document(const QModelIndex& theIndex) const; + /// Returns index for the node and column + /// \param theNode a node + /// \param thCol a column QModelIndex getIndex(ModuleBase_ITreeNode* theNode, int thCol) const; signals: + /// Signal send before tree rebuild void beforeTreeRebuild(); - /// Signal about tree had been rebuilt void treeRebuilt(); diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 0253ec56d..82f6e74e4 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -658,10 +658,13 @@ void XGUI_ObjectsBrowser::onAfterModelReset() XGUI_DataModel* aModel = myTreeView->dataModel(); QModelIndex aIndex; foreach(ModuleBase_ITreeNode* aNode, myExpandedItems) { - aIndex = aModel->getIndex(aNode, 0); - if (aIndex.isValid() && (myTreeView->dataModel()->hasIndex(aIndex)) ) - myTreeView->setExpanded(aIndex, true); + if (aModel->hasNode(aNode)) { + aIndex = aModel->getIndex(aNode, 0); + if (aIndex.isValid() && (myTreeView->dataModel()->hasIndex(aIndex))) + myTreeView->setExpanded(aIndex, true); + } } + myExpandedItems.clear(); } std::list XGUI_ObjectsBrowser::getStateForDoc(DocumentPtr theDoc) const