Salome HOME
Merge branch 'master' of salome:modules/shaper
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.cpp
index 0d9750e0804022017534d738fe6bd1a19879ecfb..7d6410a49eed6162e1e89f6cb7a3aaa89ab905e3 100644 (file)
@@ -361,14 +361,8 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   aLabelWgt->setPalette(aPalet);
 
   myDocModel = new XGUI_DataModel(this);
-  myTreeView->setModel(myDocModel);
-
-  // It has to be done after setting of model
-  myActiveDocLbl->setTreeView(myTreeView);
-
-  QItemSelectionModel* aSelMod = myTreeView->selectionModel();
-  connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
-          this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+  connect(myDocModel, SIGNAL(modelAboutToBeReset()), SLOT(onBeforeReset()));
+  connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset()));
 
   connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
           SLOT(onContextMenuRequested(QContextMenuEvent*)));
@@ -379,6 +373,18 @@ XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
 {
 }
 
+void XGUI_ObjectsBrowser::setXMLReader(Config_DataModelReader* theReader)
+{ 
+  myDocModel->setXMLReader(theReader); 
+  myTreeView->setModel(myDocModel);
+
+  // It has to be done after setting of model
+  myActiveDocLbl->setTreeView(myTreeView);
+
+  QItemSelectionModel* aSelMod = myTreeView->selectionModel();
+  connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+          this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+}
 
 //***************************************************
 void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
@@ -444,6 +450,25 @@ void XGUI_ObjectsBrowser::onEditItem()
   }
 }
 
+//***************************************************
+QModelIndexList XGUI_ObjectsBrowser::expandedItems(const QModelIndex& theParent) const
+{
+  QModelIndexList aIndexes;
+  QModelIndex aIndex;
+  for (int i = 0; i < myDocModel->rowCount(theParent); i++) {
+    aIndex = myDocModel->index(i, 0, theParent);
+    if (myDocModel->hasChildren(aIndex)) {
+      if (myTreeView->isExpanded(aIndex)) {
+        aIndexes.append(aIndex);
+        QModelIndexList aSubIndexes = expandedItems(aIndex);
+        if (!aSubIndexes.isEmpty())
+          aIndexes.append(aSubIndexes);
+      }
+    }
+  }
+  return aIndexes;
+}
+
 //***************************************************
 void XGUI_ObjectsBrowser::rebuildDataTree()
 {
@@ -496,4 +521,16 @@ QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes)
     }
   }
   return aList;
-}
\ No newline at end of file
+}
+
+void XGUI_ObjectsBrowser::onBeforeReset()
+{
+  myExpandedItems = expandedItems();
+}
+
+void XGUI_ObjectsBrowser::onAfterModelReset()
+{
+  foreach(QModelIndex aIndex, myExpandedItems) {
+    myTreeView->setExpanded(aIndex, true);
+  }
+}