]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/XGUI/XGUI_DataModel.cpp
Salome HOME
[GITHUB #2] problem in export dialog - difference in STEP vs BREP
[modules/shaper.git] / src / XGUI / XGUI_DataModel.cpp
index e1a9ba2933eebb4c1faae09b7ad9b689a8e9426b..7f110ccd2c98e27c8ef5721551a0c883540ab243 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2022  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #pragma warning(disable: 4100)
 #endif
 
+static bool isValidNode(const ModuleBase_ITreeNode* theNode)
+{
+  ModuleBase_ITreeNode* aParent = 0;
+  try {
+    aParent = theNode->parent();
+  }
+  catch (...) {
+    return false;
+  }
+  if (aParent)
+    return isValidNode(aParent);
+  return true;
+}
+
 // Constructor *************************************************
 XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent)//,
   //myIsEventsProcessingBlocked(false)
@@ -352,6 +366,16 @@ bool XGUI_DataModel::insertRows(int theRow, int theCount, const QModelIndex& the
 {
   beginInsertRows(theParent, theRow, theRow + theCount - 1);
   endInsertRows();
+  
+  //bos #40645 [CEA] Automatically expand tree in Object Browser
+  if (myWorkshop->objectBrowser()) 
+  {
+    XGUI_DataTree* aTreeView = myWorkshop->objectBrowser()->treeView();
+    if(!aTreeView->isExpanded(theParent))
+    {
+      aTreeView->setExpanded(theParent, true);
+    }
+  }
   return true;
 }
 
@@ -367,7 +391,10 @@ bool XGUI_DataModel::removeRows(int theRow, int theCount, const QModelIndex& the
 Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const
 {
   if (theIndex.isValid()) {
-    ModuleBase_ITreeNode* aNode = (ModuleBase_ITreeNode*)theIndex.internalPointer();
+    ModuleBase_ITreeNode* aNode = static_cast<ModuleBase_ITreeNode*>(theIndex.internalPointer());
+    // Check that the pointer is Valid
+    if (!isValidNode(aNode))
+      return Qt::NoItemFlags;
     Qt::ItemFlags aResultFlags = aNode->flags(theIndex.column());
     // Drag and drop of Part features only if:
     // - PartSet is active