+void XGUI_ObjectsBrowser::clearContent()
+{
+ myTreeView->clear();
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
+ const QItemSelection& theDeselected)
+{
+ onSelectionChanged();
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::onSelectionChanged()
+{
+ emit selectionChanged();
+}
+
+//***************************************************
+QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) const
+{
+ QObjectPtrList aList;
+ QModelIndexList aIndexes = selectedIndexes();
+ XGUI_DataModel* aModel = dataModel();
+
+ foreach(QModelIndex aIdx, aIndexes) {
+ if (aIdx.column() == 1) {
+ ObjectPtr aObject = aModel->object(aIdx);
+ if (aObject) {
+ aList.append(aObject);
+ if (theIndexes)
+ theIndexes->append(aIdx);
+ }
+ }
+ }
+ return aList;
+}
+
+void XGUI_ObjectsBrowser::onBeforeReset()
+{
+ myExpandedItems = expandedItems();
+}
+
+void XGUI_ObjectsBrowser::onAfterModelReset()
+{
+ XGUI_DataModel* aModel = myTreeView->dataModel();
+ QModelIndex aIndex;
+ foreach(ModuleBase_ITreeNode* aNode, myExpandedItems) {
+ 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
+{
+ std::list<bool> aStates;
+ XGUI_DataModel* aModel = dataModel();
+ QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
+ int aNbChild = aModel->rowCount(aRootIdx);
+ for (int i = 0; i < aNbChild; i++) {
+ QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
+ aStates.push_back(myTreeView->isExpanded(aIdx));
+ }
+ return aStates;
+}
+
+void XGUI_ObjectsBrowser::setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates)
+{
+ if (theStates.size() == 0)
+ return;
+ XGUI_DataModel* aModel = dataModel();
+ QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
+ int aNbChild = aModel->rowCount(aRootIdx);
+
+ std::list<bool>::const_iterator aIt;
+ int i = 0;
+ for (aIt = theStates.cbegin(); aIt != theStates.cend(); aIt++, i++) {
+ if (i >= aNbChild )
+ break;
+ QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
+ myTreeView->setExpanded(aIdx, (*aIt));
+ }
+}
+
+void XGUI_ObjectsBrowser::updateAllIndexes(int theColumn, const QModelIndex& theParent)
+{
+ int aNb = myDocModel->rowCount(theParent);
+ for (int i = 0; i < aNb; i++) {
+ QModelIndex aIdx = myDocModel->index(i, theColumn, theParent);
+ if (aIdx.isValid() && myDocModel->hasIndex(aIdx)) {
+ myTreeView->update(aIdx);
+ if (myTreeView->isExpanded(aIdx))
+ updateAllIndexes(theColumn, aIdx);
+ }
+ }
+}
+
+QMap<ObjectPtr, bool> XGUI_ObjectsBrowser::getFoldersState(DocumentPtr theDoc) const
+{
+ QMap<ObjectPtr, bool> aMap;
+
+ int aNb = theDoc->size(ModelAPI_Folder::group());
+ ObjectPtr aObj;
+ for (int i = 0; i < aNb; i++) {
+ aObj = theDoc->object(ModelAPI_Folder::group(), i);
+ QModelIndex aIdx = myDocModel->objectIndex(aObj, 0);
+ aMap[aObj] = myTreeView->isExpanded(aIdx);
+ }
+ return aMap;
+}
+
+void XGUI_ObjectsBrowser::setFoldersState(const QMap<ObjectPtr, bool>& theStates)
+{
+ QMap<ObjectPtr, bool>::const_iterator aIt;
+ for (aIt = theStates.constBegin(); aIt != theStates.constEnd(); aIt++) {
+ QModelIndex aIdx = myDocModel->objectIndex(aIt.key(), 0);
+ myTreeView->setExpanded(aIdx, aIt.value());
+ }
+}
+
+
+void XGUI_ObjectsBrowser::resizeEvent(QResizeEvent* theEvent)
+{
+ QWidget::resizeEvent(theEvent);
+ emit sizeChanged();