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);
249 // TODO: Sending events has to be removed when step will be defined as Object
250 aECreator->sendUpdated(aField->step(i), EVENT_DISP);
253 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
257 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
259 // Only one step from a field can be visible at once
260 bool toDisplay = !aStep->isDisplayed();
262 int aId = aStep->id();
263 ModelAPI_ResultField* aField = aStep->field();
264 aField->setDisplayed(false);
265 for (int i = 0; i < aField->stepsSize(); i++) {
266 aField->step(i)->setDisplayed(i == aId);
267 // TODO: Sending events has to be removed when step will be defined as Object
268 aECreator->sendUpdated(aField->step(i), EVENT_DISP);
272 aStep->setDisplayed(false);
273 aECreator->sendUpdated(aStep, EVENT_DISP);
275 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
278 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
280 std::set<ObjectPtr> anObjects;
281 anObjects.insert(aResObj);
283 bool hasHiddenState = aModel->hasHiddenState(theIndex);
284 if (aObjBrowser && hasHiddenState && !aObjBrowser->workshop()->prepareForDisplay(anObjects))
286 if (hasHiddenState) { // #issue 2335(hide all faces then show solid problem)
287 if (aResObj->isDisplayed())
288 aResObj->setDisplayed(false);
289 aResObj->setDisplayed(true);
292 aResObj->setDisplayed(!aResObj->isDisplayed());
293 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
297 // Update list of selected objects because this event happens after
298 // selection event in object browser
300 aObjBrowser->onSelectionChanged();
306 void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
308 switch (theIndex.column()) {
310 processHistoryChange(theIndex);
316 //********************************************************************
317 //********************************************************************
318 //********************************************************************
319 XGUI_ActiveDocLbl::XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent )
320 : QLabel(theText, theParent),
321 myPreSelectionStyle(""),
323 mySelectionStyle(""),
328 void XGUI_ActiveDocLbl::setTreeView(QTreeView* theView)
330 myTreeView = theView;
331 setFont(myTreeView->font());
333 QPalette aPalet = myTreeView->palette();
334 QColor aHighlight = aPalet.highlight().color();
335 QColor aHighlightText = aPalet.highlightedText().color();
337 myPreSelectionStyle = "QLabel {background-color: ";
338 myPreSelectionStyle += aHighlight.lighter(170).name() + "}";
339 //myPreSelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 white, stop:1 " +
340 // aHighlight.lighter(170).name() + ");";
341 //myPreSelectionStyle += "border: 1px solid lightblue; border-radius: 2px }";
343 QString aName = aPalet.color(QPalette::Base).name();
344 myNeutralStyle = "QLabel { border: 1px solid " + aName + " }";
347 #if (!defined HAVE_SALOME) && (defined WIN32)
348 mySelectionStyle = "QLabel {background-color: ";
349 mySelectionStyle += "rgb(205, 232, 255); ";
350 //mySelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(236, 245, 255)";
351 //mySelectionStyle += ", stop:1 rgb(208, 229, 255));";
352 //mySelectionStyle += "border: 1px solid rgb(132, 172, 221); border-radius: 2px }";
353 mySelectionStyle += "border: 1px solid rgb(153, 209, 255) }";
355 mySelectionStyle = "QLabel {background-color: " + aHighlight.name();
356 mySelectionStyle += "; color : " + aHighlightText.name() + "}";
359 myTreeView->viewport()->installEventFilter(this);
363 #if (!defined HAVE_SALOME) && (defined WIN32)
364 bool XGUI_ActiveDocLbl::event(QEvent* theEvent)
366 switch (theEvent->type()) {
369 setStyleSheet(myPreSelectionStyle);
373 setStyleSheet(myNeutralStyle);
376 return QLabel::event(theEvent);
380 bool XGUI_ActiveDocLbl::eventFilter(QObject* theObj, QEvent* theEvent)
382 if (theObj == myTreeView->viewport()) {
383 if (theEvent->type() == QEvent::MouseButtonRelease)
386 return QLabel::eventFilter(theObj, theEvent);
389 static bool MYClearing = false;
390 void XGUI_ActiveDocLbl::mouseReleaseEvent( QMouseEvent* e)
394 setStyleSheet(mySelectionStyle);
395 // We can not block signals because on
396 // clear selection the View state will not be updated
397 myTreeView->clearSelection();
398 QLabel::mouseReleaseEvent(e);
402 void XGUI_ActiveDocLbl::unselect()
405 myIsSelected = false;
406 setStyleSheet(myNeutralStyle);
411 //********************************************************************
412 //********************************************************************
413 //********************************************************************
414 XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop)
415 : QWidget(theParent), myDocModel(0), myWorkshop(theWorkshop)
417 QVBoxLayout* aLayout = new QVBoxLayout(this);
418 ModuleBase_Tools::zeroMargins(aLayout);
419 aLayout->setSpacing(0);
421 QWidget* aLabelWgt = new QWidget(this);
422 aLabelWgt->setAutoFillBackground(true);
424 aLayout->addWidget(aLabelWgt);
425 QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt);
426 ModuleBase_Tools::zeroMargins(aLabelLay);
427 aLabelLay->setSpacing(0);
429 QLabel* aLbl = new QLabel(aLabelWgt);
430 aLbl->setPixmap(QPixmap(":pictures/assembly.png"));
432 // Do not paint background of the label (in order to show icon)
433 aLbl->setAutoFillBackground(false);
435 aLabelLay->addWidget(aLbl);
437 SessionPtr aMgr = ModelAPI_Session::get();
438 DocumentPtr aDoc = aMgr->moduleDocument();
440 myActiveDocLbl = new XGUI_ActiveDocLbl(tr("Part set"), aLabelWgt);
441 // myActiveDocLbl->setReadOnly(true);
442 // myActiveDocLbl->setFrame(false);
443 myActiveDocLbl->setContextMenuPolicy(Qt::CustomContextMenu);
445 aLabelLay->addWidget(myActiveDocLbl);
446 aLabelLay->setStretch(1, 1);
448 myTreeView = new XGUI_DataTree(this);
449 myTreeView->setFrameShape(QFrame::NoFrame);
450 aLayout->addWidget(myTreeView);
452 QPalette aTreePalet = myTreeView->palette();
453 QColor aTreeBack = aTreePalet.color(QPalette::Base);
456 aPalet.setColor(QPalette::Base, aTreeBack);
457 aPalet.setColor(QPalette::Window, aTreeBack);
458 aLabelWgt->setPalette(aPalet);
460 myDocModel = new XGUI_DataModel(this);
461 connect(myDocModel, SIGNAL(beforeTreeRebuild()), SLOT(onBeforeReset()));
462 connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset()));
464 connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
465 SLOT(onContextMenuRequested(QContextMenuEvent*)));
468 //***************************************************
469 XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
473 void XGUI_ObjectsBrowser::initialize(ModuleBase_ITreeNode* theRoot)
475 //myDocModel->setXMLReader(theReader);
476 myDocModel->setRoot(theRoot);
477 myTreeView->setModel(myDocModel);
479 // It has to be done after setting of model
480 myActiveDocLbl->setTreeView(myTreeView);
482 QItemSelectionModel* aSelMod = myTreeView->selectionModel();
483 connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
484 this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
487 //***************************************************
488 void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
490 QModelIndexList aIndexes;
491 QObjectPtrList aSelectedData = selectedObjects(&aIndexes);
492 bool toEnable = false;
494 if (aSelectedData.size() == 1) {
495 QModelIndex aSelected = myTreeView->indexAt(theEvent->pos());
496 if (!aIndexes.contains(aSelected))
497 return; // menu is called on non selected item
499 Qt::ItemFlags aFlags = dataModel()->flags(aIndexes.first());
500 toEnable = ((aFlags & Qt::ItemIsEditable) != 0);
502 foreach(QAction* aCmd, actions()) {
503 aCmd->setEnabled(toEnable);
505 emit contextMenuRequested(theEvent);
508 //***************************************************
509 void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt)
511 myTreeView->selectionModel()->clearSelection();
512 //Empty feature pointer means that selected root document
513 foreach(QAction* aCmd, actions()) {
514 aCmd->setEnabled(true);
516 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, thePnt, myActiveDocLbl->mapToGlobal(thePnt));
517 emit contextMenuRequested(&aEvent);
520 //***************************************************
521 void XGUI_ObjectsBrowser::onEditItem()
523 QObjectPtrList aSelectedData = selectedObjects();
524 if (aSelectedData.size() > 0) {
525 ObjectPtr anObject = aSelectedData.first();
526 if (anObject.get()) { // Selection happens in TreeView
527 // check whether the object can be renamed. There should not be parts which are not loaded
528 std::set<FeaturePtr> aFeatures;
529 aFeatures.insert(ModelAPI_Feature::feature(anObject));
530 if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aFeatures))
533 // Find index which corresponds the feature
535 foreach(QModelIndex aIdx, selectedIndexes()) {
536 if (aIdx.column() == 1) {
537 ObjectPtr aFea = dataModel()->object(aIdx);
538 if (dataModel()->object(aIdx)->isSame(anObject)) {
544 if (aIndex.isValid()) {
545 myTreeView->setCurrentIndex(aIndex);
546 myTreeView->edit(aIndex);
553 //***************************************************
554 QList<ModuleBase_ITreeNode*> XGUI_ObjectsBrowser::expandedItems(const QModelIndex& theParent) const
556 QList<ModuleBase_ITreeNode*> aIndexes;
558 int aCount = myDocModel->rowCount(theParent);
559 for (int i = 0; i < aCount; i++) {
560 aIndex = myDocModel->index(i, 0, theParent);
561 if (myDocModel->hasChildren(aIndex)) {
562 if (myTreeView->isExpanded(aIndex)) {
563 aIndexes.append((ModuleBase_ITreeNode*)aIndex.internalPointer());
564 QList<ModuleBase_ITreeNode*> aSubIndexes = expandedItems(aIndex);
565 if (!aSubIndexes.isEmpty())
566 aIndexes.append(aSubIndexes);
573 //***************************************************
574 void XGUI_ObjectsBrowser::rebuildDataTree()
576 myDocModel->root()->update();
577 myDocModel->rebuildDataTree();
581 //***************************************************
582 void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects)
584 QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
585 QModelIndexList aIndexes = aSelectModel->selectedIndexes();
586 if (theObjects.size() == 0) {
587 bool aIsBlock = aSelectModel->blockSignals(true);
588 aSelectModel->clear();
589 aSelectModel->blockSignals(aIsBlock);
590 foreach(QModelIndex aIdx, aIndexes) {
591 myTreeView->update(aIdx);
597 QModelIndexList aUnselect;
598 QObjectPtrList aToSelect = theObjects;
599 QHash<qint64, ObjectPtr> aNotChanged;
600 foreach(QModelIndex aIdx, aIndexes) {
601 aObject = myDocModel->object(aIdx);
603 if (aToSelect.contains(aObject)) {
604 aNotChanged.insert((qint64)aObject.get(), aObject);
606 aUnselect.append(aIdx);
610 aUnselect.append(aIdx);
614 foreach(ObjectPtr aObj, aNotChanged)
615 aToSelect.removeAll(aObj);
617 bool aIsBlock = aSelectModel->blockSignals(true);
618 foreach(QModelIndex aIdx, aUnselect) {
619 aSelectModel->select(aIdx, QItemSelectionModel::Deselect);
620 myTreeView->update(aIdx);
623 QModelIndex aIndex0, aIndex1, aIndex2, aCurrent;
624 foreach(ObjectPtr aFeature, aToSelect) {
625 aIndex1 = myDocModel->objectIndex(aFeature, 1);
626 if (aIndex1.isValid()) {
627 if (!aCurrent.isValid())
629 aIndex0 = myDocModel->objectIndex(aFeature, 0);
630 aIndex2 = myDocModel->objectIndex(aFeature, 2);
631 aSelectModel->select(aIndex1, QItemSelectionModel::Select | QItemSelectionModel::Rows);
632 myTreeView->update(aIndex0);
633 myTreeView->update(aIndex1);
634 myTreeView->update(aIndex2);
637 aSelectModel->setCurrentIndex(aCurrent, QItemSelectionModel::NoUpdate);
638 aSelectModel->blockSignals(aIsBlock);
641 //***************************************************
642 void XGUI_ObjectsBrowser::ensureVisible(const ObjectPtr theObject)
644 QModelIndex aIndex = myDocModel->objectIndex(theObject);
645 if (aIndex.isValid()) {
646 QModelIndex aParent = aIndex.parent();
647 while (aParent.isValid()) {
648 myTreeView->expand(aParent);
649 aParent = aParent.parent();
651 myTreeView->scrollTo(aIndex);
655 //***************************************************
656 void XGUI_ObjectsBrowser::clearContent()
661 //***************************************************
662 void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
663 const QItemSelection& theDeselected)
665 onSelectionChanged();
668 //***************************************************
669 void XGUI_ObjectsBrowser::onSelectionChanged()
671 emit selectionChanged();
674 //***************************************************
675 QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) const
677 QObjectPtrList aList;
678 QModelIndexList aIndexes = selectedIndexes();
679 XGUI_DataModel* aModel = dataModel();
681 foreach(QModelIndex aIdx, aIndexes) {
682 if (aIdx.column() == 1) {
683 ObjectPtr aObject = aModel->object(aIdx);
685 aList.append(aObject);
687 theIndexes->append(aIdx);
694 void XGUI_ObjectsBrowser::onBeforeReset()
696 myExpandedItems = expandedItems();
699 void XGUI_ObjectsBrowser::onAfterModelReset()
701 XGUI_DataModel* aModel = myTreeView->dataModel();
703 foreach(ModuleBase_ITreeNode* aNode, myExpandedItems) {
704 if (aModel->hasNode(aNode)) {
705 aIndex = aModel->getIndex(aNode, 0);
706 if (aIndex.isValid() && (myTreeView->dataModel()->hasIndex(aIndex)))
707 myTreeView->setExpanded(aIndex, true);
710 myExpandedItems.clear();
713 std::list<bool> XGUI_ObjectsBrowser::getStateForDoc(DocumentPtr theDoc) const
715 std::list<bool> aStates;
716 XGUI_DataModel* aModel = dataModel();
717 QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
718 int aNbChild = aModel->rowCount(aRootIdx);
719 for (int i = 0; i < aNbChild; i++) {
720 QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
721 aStates.push_back(myTreeView->isExpanded(aIdx));
726 void XGUI_ObjectsBrowser::setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates)
728 if (theStates.size() == 0)
730 XGUI_DataModel* aModel = dataModel();
731 QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
732 int aNbChild = aModel->rowCount(aRootIdx);
734 std::list<bool>::const_iterator aIt;
736 for (aIt = theStates.cbegin(); aIt != theStates.cend(); aIt++, i++) {
739 QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
740 myTreeView->setExpanded(aIdx, (*aIt));
744 void XGUI_ObjectsBrowser::updateAllIndexes(int theColumn, const QModelIndex& theParent)
746 int aNb = myDocModel->rowCount(theParent);
747 for (int i = 0; i < aNb; i++) {
748 QModelIndex aIdx = myDocModel->index(i, theColumn, theParent);
749 if (aIdx.isValid() && myDocModel->hasIndex(aIdx)) {
750 myTreeView->update(aIdx);
751 if (myTreeView->isExpanded(aIdx))
752 updateAllIndexes(theColumn, aIdx);
757 QMap<ObjectPtr, bool> XGUI_ObjectsBrowser::getFoldersState(DocumentPtr theDoc) const
759 QMap<ObjectPtr, bool> aMap;
761 int aNb = theDoc->size(ModelAPI_Folder::group());
763 for (int i = 0; i < aNb; i++) {
764 aObj = theDoc->object(ModelAPI_Folder::group(), i);
765 QModelIndex aIdx = myDocModel->objectIndex(aObj, 0);
766 aMap[aObj] = myTreeView->isExpanded(aIdx);
771 void XGUI_ObjectsBrowser::setFoldersState(const QMap<ObjectPtr, bool>& theStates)
773 QMap<ObjectPtr, bool>::const_iterator aIt;
774 for (aIt = theStates.constBegin(); aIt != theStates.constEnd(); aIt++) {
775 QModelIndex aIdx = myDocModel->objectIndex(aIt.key(), 0);
776 myTreeView->setExpanded(aIdx, aIt.value());
781 void XGUI_ObjectsBrowser::resizeEvent(QResizeEvent* theEvent)
783 QWidget::resizeEvent(theEvent);