Salome HOME
Fix for crash with data tree
authorvsv <vsv@opencascade.com>
Thu, 30 May 2019 09:25:50 +0000 (12:25 +0300)
committervsv <vsv@opencascade.com>
Mon, 3 Jun 2019 10:32:11 +0000 (13:32 +0300)
src/XGUI/XGUI_DataModel.cpp
src/XGUI/XGUI_DataModel.h
src/XGUI/XGUI_ObjectsBrowser.cpp

index 6594e26ef8491a73eb3440da589695ef0fbc8c38..32548038ce2b4ab3cb3be13906c04d5f89a73e8c 100644 (file)
@@ -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);
+}
index 54181442184d8f54ec59b3a3adcd3eaf808a76b7..df3984e58e6bf49acb238e5f22ec504b147d7068 100644 (file)
@@ -154,14 +154,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();
 
index 0253ec56dfe0d4039312e1eda85fdb33734905ac..82f6e74e434f22212eaf1d9bc54833910d107d69 100644 (file)
@@ -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<bool> XGUI_ObjectsBrowser::getStateForDoc(DocumentPtr theDoc) const