1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "XGUI_ObjectsBrowser.h"
21 #include "XGUI_Tools.h"
22 #include "XGUI_DataModel.h"
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_Document.h>
27 #include <ModelAPI_Tools.h>
28 #include <ModelAPI_ResultField.h>
30 #include <ModuleBase_Tools.h>
31 #include <ModuleBase_ITreeNode.h>
33 #include <XGUI_Workshop.h>
39 #include <QMouseEvent>
41 #include <QStyledItemDelegate>
42 #include <QMessageBox>
43 #include <QApplication>
49 /// Width of second column (minimum acceptable = 27)
50 #define FIRST_COL_WIDTH 20
51 #define SECOND_COL_WIDTH 30
55 * Tree item delegate for definition of data in column items editor
57 class XGUI_TreeViewItemDelegate: public QStyledItemDelegate
61 /// \param theParent a parent of the delegate
62 XGUI_TreeViewItemDelegate(XGUI_DataTree* theParent):QStyledItemDelegate(theParent),
63 myTreedView(theParent) {}
65 /// Set data for item editor (name of the item)
66 /// \param editor a widget of editor
67 /// \param index the tree item index
68 virtual void setEditorData ( QWidget* editor, const QModelIndex& index ) const
70 QLineEdit* aEditor = dynamic_cast<QLineEdit*>(editor);
72 XGUI_DataModel* aModel = myTreedView->dataModel();
73 ObjectPtr aObj = aModel->object(index);
74 if (aObj.get() != NULL) {
75 aEditor->setText(aObj->data()->name().c_str());
79 QStyledItemDelegate::setEditorData(editor, index);
83 XGUI_DataTree* myTreedView;
87 XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
88 : QTreeView(theParent)
90 setHeaderHidden(true);
92 setEditTriggers(QAbstractItemView::NoEditTriggers);
93 setSelectionBehavior(QAbstractItemView::SelectRows);
94 setSelectionMode(QAbstractItemView::ExtendedSelection);
96 setItemDelegateForColumn(1, new XGUI_TreeViewItemDelegate(this));
98 connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
99 SLOT(onDoubleClick(const QModelIndex&)));
102 XGUI_DataTree::~XGUI_DataTree()
106 XGUI_DataModel* XGUI_DataTree::dataModel() const
108 return static_cast<XGUI_DataModel*>(model());
111 void XGUI_DataTree::contextMenuEvent(QContextMenuEvent* theEvent)
113 emit contextMenuRequested(theEvent);
116 void XGUI_DataTree::commitData(QWidget* theEditor)
118 static int aEntrance = 0;
119 if (aEntrance == 0) {
120 // We have to check number of enter and exit of this function because it can be called
121 // recursively by Qt in order to avoid double modifying of a data
123 QLineEdit* aEditor = dynamic_cast<QLineEdit*>(theEditor);
125 QString aName = aEditor->text();
126 QModelIndexList aIndexList = selectionModel()->selectedIndexes();
127 XGUI_DataModel* aModel = dataModel();
128 ObjectPtr aObj = aModel->object(aIndexList.first());
130 if (XGUI_Tools::canRename(aObj, aName)) {
131 SessionPtr aMgr = ModelAPI_Session::get();
132 aMgr->startOperation("Rename");
133 aObj->data()->setName(qPrintable(aName));
134 aMgr->finishOperation();
141 void XGUI_DataTree::clear()
143 dataModel()->clear();
147 void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent)
149 QTreeView::resizeEvent(theEvent);
150 QSize aSize = theEvent->size();
151 if (aSize.isValid()) {
152 setColumnWidth(0, FIRST_COL_WIDTH);
153 setColumnWidth(1, aSize.width() - SECOND_COL_WIDTH - FIRST_COL_WIDTH - 10);
154 setColumnWidth(2, SECOND_COL_WIDTH);
159 void XGUI_DataTree::mousePressEvent(QMouseEvent* theEvent)
161 QTreeView::mousePressEvent(theEvent);
162 if (theEvent->button() != Qt::MidButton)
164 QModelIndex aInd = indexAt(theEvent->pos());
166 QString("r=%1 c=%2 p=%3").arg(aInd.row()).arg(aInd.column()).arg((long)aInd.internalPointer());
168 QModelIndex aPar = aInd.parent();
170 QString("r=%1 c=%2 p=%3").arg(aPar.row()).arg(aPar.column()).arg((long)aPar.internalPointer());
171 QToolTip::showText(theEvent->globalPos(), aTxt + '\n' + aTxt1);
175 void XGUI_DataTree::mouseReleaseEvent(QMouseEvent* theEvent)
177 QTreeView::mouseReleaseEvent(theEvent);
179 if (theEvent->button() != Qt::MidButton)
181 QToolTip::hideText();
183 if (theEvent->button() == Qt::LeftButton) {
184 QModelIndex aInd = indexAt(theEvent->pos());
185 if (aInd.column() == 0)
186 processEyeClick(aInd);
190 void XGUI_DataTree::processHistoryChange(const QModelIndex& theIndex)
192 SessionPtr aMgr = ModelAPI_Session::get();
193 // When operation is opened then we can not change history
194 if (aMgr->isOperation())
196 XGUI_DataModel* aModel = dataModel();
197 if (aModel->flags(theIndex) == 0)
199 ObjectPtr aObj = aModel->object(theIndex);
201 DocumentPtr aDoc = aMgr->activeDocument();
203 std::string aOpName = tr("History change").toStdString();
205 if (aObj->document() != aDoc)
207 aMgr->startOperation(aOpName);
208 aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObj), true);
209 aMgr->finishOperation();
211 // Ignore clicks on folders outside current document
212 if ((theIndex.internalId() == 0) && (aDoc != aMgr->moduleDocument()))
213 // Clicked folder under root but active document is another
215 if ((theIndex.internalId() != 0) && (aDoc != aModel->document(theIndex)))
216 // Cliced not on active document folder
219 aMgr->startOperation(aOpName);
220 aDoc->setCurrentFeature(FeaturePtr(), true);
221 aMgr->finishOperation();
223 QModelIndex aParent = theIndex.parent();
224 int aSize = aModel->rowCount(aParent);
225 for (int i = 0; i < aSize; i++) {
226 update(aModel->index(i, 0, aParent));
227 update(aModel->index(i, 1, aParent));
228 update(aModel->index(i, 2, aParent));
232 void XGUI_DataTree::processEyeClick(const QModelIndex& theIndex)
234 static Events_Loop* aLoop = Events_Loop::loop();
235 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
236 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
238 XGUI_DataModel* aModel = dataModel();
239 ObjectPtr aObj = aModel->object(theIndex);
241 XGUI_ObjectsBrowser* aObjBrowser = qobject_cast<XGUI_ObjectsBrowser*>(parent());
242 ResultFieldPtr aField = std::dynamic_pointer_cast<ModelAPI_ResultField>(aObj);
244 bool toDisplay = !aField->isDisplayed();
245 aField->setDisplayed(toDisplay);
247 for (int i = 0; i < aField->stepsSize(); i++) {
248 aField->step(i)->setDisplayed(false);
251 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
255 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
257 // Only one step from a field can be visible at once
258 bool toDisplay = !aStep->isDisplayed();
260 int aId = aStep->id();
261 ModelAPI_ResultField* aField = aStep->field();
262 aField->setDisplayed(false);
263 for (int i = 0; i < aField->stepsSize(); i++) {
264 aField->step(i)->setDisplayed(i == aId);
268 aStep->setDisplayed(false);
269 aECreator->sendUpdated(aStep, EVENT_DISP);
271 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
274 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
276 std::set<ObjectPtr> anObjects;
277 anObjects.insert(aResObj);
279 bool hasHiddenState = aModel->hasHiddenState(theIndex);
280 if (aObjBrowser && hasHiddenState && !aObjBrowser->workshop()->prepareForDisplay(anObjects))
282 if (hasHiddenState) { // #issue 2335(hide all faces then show solid problem)
283 if (aResObj->isDisplayed())
284 aResObj->setDisplayed(false);
285 aResObj->setDisplayed(true);
288 aResObj->setDisplayed(!aResObj->isDisplayed());
289 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
293 // Update list of selected objects because this event happens after
294 // selection event in object browser
296 aObjBrowser->onSelectionChanged();
302 void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
304 switch (theIndex.column()) {
306 processHistoryChange(theIndex);
312 //********************************************************************
313 //********************************************************************
314 //********************************************************************
315 XGUI_ActiveDocLbl::XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent )
316 : QLabel(theText, theParent),
317 myPreSelectionStyle(""),
319 mySelectionStyle(""),
324 void XGUI_ActiveDocLbl::setTreeView(QTreeView* theView)
326 myTreeView = theView;
327 setFont(myTreeView->font());
329 QPalette aPalet = myTreeView->palette();
330 QColor aHighlight = aPalet.highlight().color();
331 QColor aHighlightText = aPalet.highlightedText().color();
333 myPreSelectionStyle = "QLabel {background-color: ";
334 myPreSelectionStyle += aHighlight.lighter(170).name() + "}";
335 //myPreSelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 white, stop:1 " +
336 // aHighlight.lighter(170).name() + ");";
337 //myPreSelectionStyle += "border: 1px solid lightblue; border-radius: 2px }";
339 QString aName = aPalet.color(QPalette::Base).name();
340 myNeutralStyle = "QLabel { border: 1px solid " + aName + " }";
343 #if (!defined HAVE_SALOME) && (defined WIN32)
344 mySelectionStyle = "QLabel {background-color: ";
345 mySelectionStyle += "rgb(205, 232, 255); ";
346 //mySelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(236, 245, 255)";
347 //mySelectionStyle += ", stop:1 rgb(208, 229, 255));";
348 //mySelectionStyle += "border: 1px solid rgb(132, 172, 221); border-radius: 2px }";
349 mySelectionStyle += "border: 1px solid rgb(153, 209, 255) }";
351 mySelectionStyle = "QLabel {background-color: " + aHighlight.name();
352 mySelectionStyle += "; color : " + aHighlightText.name() + "}";
355 myTreeView->viewport()->installEventFilter(this);
359 #if (!defined HAVE_SALOME) && (defined WIN32)
360 bool XGUI_ActiveDocLbl::event(QEvent* theEvent)
362 switch (theEvent->type()) {
365 setStyleSheet(myPreSelectionStyle);
369 setStyleSheet(myNeutralStyle);
372 return QLabel::event(theEvent);
376 bool XGUI_ActiveDocLbl::eventFilter(QObject* theObj, QEvent* theEvent)
378 if (theObj == myTreeView->viewport()) {
379 if (theEvent->type() == QEvent::MouseButtonRelease)
382 return QLabel::eventFilter(theObj, theEvent);
385 static bool MYClearing = false;
386 void XGUI_ActiveDocLbl::mouseReleaseEvent( QMouseEvent* e)
390 setStyleSheet(mySelectionStyle);
391 // We can not block signals because on
392 // clear selection the View state will not be updated
393 myTreeView->clearSelection();
394 QLabel::mouseReleaseEvent(e);
398 void XGUI_ActiveDocLbl::unselect()
401 myIsSelected = false;
402 setStyleSheet(myNeutralStyle);
407 //********************************************************************
408 //********************************************************************
409 //********************************************************************
410 XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop)
411 : QWidget(theParent), myDocModel(0), myWorkshop(theWorkshop)
413 QVBoxLayout* aLayout = new QVBoxLayout(this);
414 ModuleBase_Tools::zeroMargins(aLayout);
415 aLayout->setSpacing(0);
417 QWidget* aLabelWgt = new QWidget(this);
418 aLabelWgt->setAutoFillBackground(true);
420 aLayout->addWidget(aLabelWgt);
421 QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt);
422 ModuleBase_Tools::zeroMargins(aLabelLay);
423 aLabelLay->setSpacing(0);
425 QLabel* aLbl = new QLabel(aLabelWgt);
426 aLbl->setPixmap(QPixmap(":pictures/assembly.png"));
428 // Do not paint background of the label (in order to show icon)
429 aLbl->setAutoFillBackground(false);
431 aLabelLay->addWidget(aLbl);
433 SessionPtr aMgr = ModelAPI_Session::get();
434 DocumentPtr aDoc = aMgr->moduleDocument();
436 myActiveDocLbl = new XGUI_ActiveDocLbl(tr("Part set"), aLabelWgt);
437 // myActiveDocLbl->setReadOnly(true);
438 // myActiveDocLbl->setFrame(false);
439 myActiveDocLbl->setContextMenuPolicy(Qt::CustomContextMenu);
441 aLabelLay->addWidget(myActiveDocLbl);
442 aLabelLay->setStretch(1, 1);
444 myTreeView = new XGUI_DataTree(this);
445 myTreeView->setFrameShape(QFrame::NoFrame);
446 aLayout->addWidget(myTreeView);
448 QPalette aTreePalet = myTreeView->palette();
449 QColor aTreeBack = aTreePalet.color(QPalette::Base);
452 aPalet.setColor(QPalette::Base, aTreeBack);
453 aPalet.setColor(QPalette::Window, aTreeBack);
454 aLabelWgt->setPalette(aPalet);
456 myDocModel = new XGUI_DataModel(this);
457 connect(myDocModel, SIGNAL(beforeTreeRebuild()), SLOT(onBeforeReset()));
458 connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset()));
460 connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
461 SLOT(onContextMenuRequested(QContextMenuEvent*)));
464 //***************************************************
465 XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
469 void XGUI_ObjectsBrowser::initialize(ModuleBase_ITreeNode* theRoot)
471 //myDocModel->setXMLReader(theReader);
472 myDocModel->setRoot(theRoot);
473 myTreeView->setModel(myDocModel);
475 // It has to be done after setting of model
476 myActiveDocLbl->setTreeView(myTreeView);
478 QItemSelectionModel* aSelMod = myTreeView->selectionModel();
479 connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
480 this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
483 //***************************************************
484 void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
486 QModelIndexList aIndexes;
487 QObjectPtrList aSelectedData = selectedObjects(&aIndexes);
488 bool toEnable = false;
490 if (aSelectedData.size() == 1) {
491 QModelIndex aSelected = myTreeView->indexAt(theEvent->pos());
492 if (!aIndexes.contains(aSelected))
493 return; // menu is called on non selected item
495 Qt::ItemFlags aFlags = dataModel()->flags(aIndexes.first());
496 toEnable = ((aFlags & Qt::ItemIsEditable) != 0);
498 foreach(QAction* aCmd, actions()) {
499 aCmd->setEnabled(toEnable);
501 emit contextMenuRequested(theEvent);
504 //***************************************************
505 void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt)
507 myTreeView->selectionModel()->clearSelection();
508 //Empty feature pointer means that selected root document
509 foreach(QAction* aCmd, actions()) {
510 aCmd->setEnabled(true);
512 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, thePnt, myActiveDocLbl->mapToGlobal(thePnt));
513 emit contextMenuRequested(&aEvent);
516 //***************************************************
517 void XGUI_ObjectsBrowser::onEditItem()
519 QObjectPtrList aSelectedData = selectedObjects();
520 if (aSelectedData.size() > 0) {
521 ObjectPtr anObject = aSelectedData.first();
522 if (anObject.get()) { // Selection happens in TreeView
523 // check whether the object can be renamed. There should not be parts which are not loaded
524 std::set<FeaturePtr> aFeatures;
525 aFeatures.insert(ModelAPI_Feature::feature(anObject));
526 if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aFeatures))
529 // Find index which corresponds the feature
531 foreach(QModelIndex aIdx, selectedIndexes()) {
532 if (aIdx.column() == 1) {
533 ObjectPtr aFea = dataModel()->object(aIdx);
534 if (dataModel()->object(aIdx)->isSame(anObject)) {
540 if (aIndex.isValid()) {
541 myTreeView->setCurrentIndex(aIndex);
542 myTreeView->edit(aIndex);
549 //***************************************************
550 QList<ModuleBase_ITreeNode*> XGUI_ObjectsBrowser::expandedItems(const QModelIndex& theParent) const
552 QList<ModuleBase_ITreeNode*> aIndexes;
554 int aCount = myDocModel->rowCount(theParent);
555 for (int i = 0; i < aCount; i++) {
556 aIndex = myDocModel->index(i, 0, theParent);
557 if (myDocModel->hasChildren(aIndex)) {
558 if (myTreeView->isExpanded(aIndex)) {
559 aIndexes.append((ModuleBase_ITreeNode*)aIndex.internalPointer());
560 QList<ModuleBase_ITreeNode*> aSubIndexes = expandedItems(aIndex);
561 if (!aSubIndexes.isEmpty())
562 aIndexes.append(aSubIndexes);
569 //***************************************************
570 void XGUI_ObjectsBrowser::rebuildDataTree()
572 myDocModel->root()->update();
573 myDocModel->rebuildDataTree();
577 //***************************************************
578 void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects)
580 QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
581 QModelIndexList aIndexes = aSelectModel->selectedIndexes();
582 if (theObjects.size() == 0) {
583 bool aIsBlock = aSelectModel->blockSignals(true);
584 aSelectModel->clear();
585 aSelectModel->blockSignals(aIsBlock);
586 foreach(QModelIndex aIdx, aIndexes) {
587 myTreeView->update(aIdx);
593 QModelIndexList aUnselect;
594 QObjectPtrList aToSelect = theObjects;
595 QHash<qint64, ObjectPtr> aNotChanged;
596 foreach(QModelIndex aIdx, aIndexes) {
597 aObject = myDocModel->object(aIdx);
599 if (aToSelect.contains(aObject)) {
600 aNotChanged.insert((qint64)aObject.get(), aObject);
602 aUnselect.append(aIdx);
606 aUnselect.append(aIdx);
610 foreach(ObjectPtr aObj, aNotChanged)
611 aToSelect.removeAll(aObj);
613 bool aIsBlock = aSelectModel->blockSignals(true);
614 foreach(QModelIndex aIdx, aUnselect) {
615 aSelectModel->select(aIdx, QItemSelectionModel::Deselect);
616 myTreeView->update(aIdx);
619 QModelIndex aIndex0, aIndex1, aIndex2, aCurrent;
620 foreach(ObjectPtr aFeature, aToSelect) {
621 aIndex1 = myDocModel->objectIndex(aFeature, 1);
622 if (aIndex1.isValid()) {
623 if (!aCurrent.isValid())
625 aIndex0 = myDocModel->objectIndex(aFeature, 0);
626 aIndex2 = myDocModel->objectIndex(aFeature, 2);
627 aSelectModel->select(aIndex1, QItemSelectionModel::Select | QItemSelectionModel::Rows);
628 myTreeView->update(aIndex0);
629 myTreeView->update(aIndex1);
630 myTreeView->update(aIndex2);
633 aSelectModel->setCurrentIndex(aCurrent, QItemSelectionModel::NoUpdate);
634 aSelectModel->blockSignals(aIsBlock);
637 //***************************************************
638 void XGUI_ObjectsBrowser::ensureVisible(const ObjectPtr theObject)
640 QModelIndex aIndex = myDocModel->objectIndex(theObject);
641 if (aIndex.isValid()) {
642 QModelIndex aParent = aIndex.parent();
643 while (aParent.isValid()) {
644 myTreeView->expand(aParent);
645 aParent = aParent.parent();
647 myTreeView->scrollTo(aIndex);
651 //***************************************************
652 void XGUI_ObjectsBrowser::clearContent()
657 //***************************************************
658 void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
659 const QItemSelection& theDeselected)
661 onSelectionChanged();
664 //***************************************************
665 void XGUI_ObjectsBrowser::onSelectionChanged()
667 emit selectionChanged();
670 //***************************************************
671 QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) const
673 QObjectPtrList aList;
674 QModelIndexList aIndexes = selectedIndexes();
675 XGUI_DataModel* aModel = dataModel();
677 foreach(QModelIndex aIdx, aIndexes) {
678 if (aIdx.column() == 1) {
679 ObjectPtr aObject = aModel->object(aIdx);
681 aList.append(aObject);
683 theIndexes->append(aIdx);
690 void XGUI_ObjectsBrowser::onBeforeReset()
692 myExpandedItems = expandedItems();
695 void XGUI_ObjectsBrowser::onAfterModelReset()
697 XGUI_DataModel* aModel = myTreeView->dataModel();
699 foreach(ModuleBase_ITreeNode* aNode, myExpandedItems) {
700 if (aModel->hasNode(aNode)) {
701 aIndex = aModel->getIndex(aNode, 0);
702 if (aIndex.isValid() && (myTreeView->dataModel()->hasIndex(aIndex)))
703 myTreeView->setExpanded(aIndex, true);
706 myExpandedItems.clear();
709 std::list<bool> XGUI_ObjectsBrowser::getStateForDoc(DocumentPtr theDoc) const
711 std::list<bool> aStates;
712 XGUI_DataModel* aModel = dataModel();
713 QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
714 int aNbChild = aModel->rowCount(aRootIdx);
715 for (int i = 0; i < aNbChild; i++) {
716 QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
717 aStates.push_back(myTreeView->isExpanded(aIdx));
722 void XGUI_ObjectsBrowser::setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates)
724 if (theStates.size() == 0)
726 XGUI_DataModel* aModel = dataModel();
727 QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
728 int aNbChild = aModel->rowCount(aRootIdx);
730 std::list<bool>::const_iterator aIt;
732 for (aIt = theStates.cbegin(); aIt != theStates.cend(); aIt++, i++) {
735 QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
736 myTreeView->setExpanded(aIdx, (*aIt));
740 void XGUI_ObjectsBrowser::updateAllIndexes(int theColumn, const QModelIndex& theParent)
742 int aNb = myDocModel->rowCount(theParent);
743 for (int i = 0; i < aNb; i++) {
744 QModelIndex aIdx = myDocModel->index(i, theColumn, theParent);
745 if (aIdx.isValid() && myDocModel->hasIndex(aIdx)) {
746 myTreeView->update(aIdx);
747 if (myTreeView->isExpanded(aIdx))
748 updateAllIndexes(theColumn, aIdx);
753 QMap<ObjectPtr, bool> XGUI_ObjectsBrowser::getFoldersState(DocumentPtr theDoc) const
755 QMap<ObjectPtr, bool> aMap;
757 int aNb = theDoc->size(ModelAPI_Folder::group());
759 for (int i = 0; i < aNb; i++) {
760 aObj = theDoc->object(ModelAPI_Folder::group(), i);
761 QModelIndex aIdx = myDocModel->objectIndex(aObj, 0);
762 aMap[aObj] = myTreeView->isExpanded(aIdx);
767 void XGUI_ObjectsBrowser::setFoldersState(const QMap<ObjectPtr, bool>& theStates)
769 QMap<ObjectPtr, bool>::const_iterator aIt;
770 for (aIt = theStates.constBegin(); aIt != theStates.constEnd(); aIt++) {
771 QModelIndex aIdx = myDocModel->objectIndex(aIt.key(), 0);
772 myTreeView->setExpanded(aIdx, aIt.value());
777 void XGUI_ObjectsBrowser::resizeEvent(QResizeEvent* theEvent)
779 QWidget::resizeEvent(theEvent);