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 XGUI_DataModel* aModel = dataModel();
235 ObjectPtr aObj = aModel->object(theIndex);
237 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
238 XGUI_ObjectsBrowser* aObjBrowser = qobject_cast<XGUI_ObjectsBrowser*>(parent());
240 std::set<ObjectPtr> anObjects;
241 anObjects.insert(aResObj);
243 bool hasHiddenState = aModel->hasHiddenState(theIndex);
244 if (aObjBrowser && hasHiddenState && !aObjBrowser->workshop()->prepareForDisplay(anObjects))
246 if (hasHiddenState) { // #issue 2335(hide all faces then show solid problem)
247 if (aResObj->isDisplayed())
248 aResObj->setDisplayed(false);
249 aResObj->setDisplayed(true);
252 aResObj->setDisplayed(!aResObj->isDisplayed());
253 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
258 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
260 // Only one step from a field can be visible at once
261 int aId = aStep->id();
262 ModelAPI_ResultField* aField = aStep->field();
263 aField->setDisplayed(false);
264 for (int i = 0; i < aField->stepsSize(); i++) {
265 aField->step(i)->setDisplayed(i == aId);
266 static Events_Loop* aLoop = Events_Loop::loop();
267 static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
268 static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
269 aECreator->sendUpdated(aField->step(i), EVENT_DISP);
271 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
274 // Update list of selected objects because this event happens after
275 // selection event in object browser
277 aObjBrowser->onSelectionChanged();
282 void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
284 switch (theIndex.column()) {
286 processHistoryChange(theIndex);
292 //********************************************************************
293 //********************************************************************
294 //********************************************************************
295 XGUI_ActiveDocLbl::XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent )
296 : QLabel(theText, theParent),
297 myPreSelectionStyle(""),
299 mySelectionStyle(""),
304 void XGUI_ActiveDocLbl::setTreeView(QTreeView* theView)
306 myTreeView = theView;
307 setFont(myTreeView->font());
309 QPalette aPalet = myTreeView->palette();
310 QColor aHighlight = aPalet.highlight().color();
311 QColor aHighlightText = aPalet.highlightedText().color();
313 myPreSelectionStyle = "QLabel {background-color: ";
314 myPreSelectionStyle += aHighlight.lighter(170).name() + "}";
315 //myPreSelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 white, stop:1 " +
316 // aHighlight.lighter(170).name() + ");";
317 //myPreSelectionStyle += "border: 1px solid lightblue; border-radius: 2px }";
319 QString aName = aPalet.color(QPalette::Base).name();
320 myNeutralStyle = "QLabel { border: 1px solid " + aName + " }";
323 #if (!defined HAVE_SALOME) && (defined WIN32)
324 mySelectionStyle = "QLabel {background-color: ";
325 mySelectionStyle += "rgb(205, 232, 255); ";
326 //mySelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(236, 245, 255)";
327 //mySelectionStyle += ", stop:1 rgb(208, 229, 255));";
328 //mySelectionStyle += "border: 1px solid rgb(132, 172, 221); border-radius: 2px }";
329 mySelectionStyle += "border: 1px solid rgb(153, 209, 255) }";
331 mySelectionStyle = "QLabel {background-color: " + aHighlight.name();
332 mySelectionStyle += "; color : " + aHighlightText.name() + "}";
335 myTreeView->viewport()->installEventFilter(this);
339 #if (!defined HAVE_SALOME) && (defined WIN32)
340 bool XGUI_ActiveDocLbl::event(QEvent* theEvent)
342 switch (theEvent->type()) {
345 setStyleSheet(myPreSelectionStyle);
349 setStyleSheet(myNeutralStyle);
352 return QLabel::event(theEvent);
356 bool XGUI_ActiveDocLbl::eventFilter(QObject* theObj, QEvent* theEvent)
358 if (theObj == myTreeView->viewport()) {
359 if (theEvent->type() == QEvent::MouseButtonRelease)
362 return QLabel::eventFilter(theObj, theEvent);
365 static bool MYClearing = false;
366 void XGUI_ActiveDocLbl::mouseReleaseEvent( QMouseEvent* e)
370 setStyleSheet(mySelectionStyle);
371 // We can not block signals because on
372 // clear selection the View state will not be updated
373 myTreeView->clearSelection();
374 QLabel::mouseReleaseEvent(e);
378 void XGUI_ActiveDocLbl::unselect()
381 myIsSelected = false;
382 setStyleSheet(myNeutralStyle);
387 //********************************************************************
388 //********************************************************************
389 //********************************************************************
390 XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop)
391 : QWidget(theParent), myDocModel(0), myWorkshop(theWorkshop)
393 QVBoxLayout* aLayout = new QVBoxLayout(this);
394 ModuleBase_Tools::zeroMargins(aLayout);
395 aLayout->setSpacing(0);
397 QWidget* aLabelWgt = new QWidget(this);
398 aLabelWgt->setAutoFillBackground(true);
400 aLayout->addWidget(aLabelWgt);
401 QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt);
402 ModuleBase_Tools::zeroMargins(aLabelLay);
403 aLabelLay->setSpacing(0);
405 QLabel* aLbl = new QLabel(aLabelWgt);
406 aLbl->setPixmap(QPixmap(":pictures/assembly.png"));
408 // Do not paint background of the label (in order to show icon)
409 aLbl->setAutoFillBackground(false);
411 aLabelLay->addWidget(aLbl);
413 SessionPtr aMgr = ModelAPI_Session::get();
414 DocumentPtr aDoc = aMgr->moduleDocument();
416 myActiveDocLbl = new XGUI_ActiveDocLbl(tr("Part set"), aLabelWgt);
417 // myActiveDocLbl->setReadOnly(true);
418 // myActiveDocLbl->setFrame(false);
419 myActiveDocLbl->setContextMenuPolicy(Qt::CustomContextMenu);
421 aLabelLay->addWidget(myActiveDocLbl);
422 aLabelLay->setStretch(1, 1);
424 myTreeView = new XGUI_DataTree(this);
425 myTreeView->setFrameShape(QFrame::NoFrame);
426 aLayout->addWidget(myTreeView);
428 QPalette aTreePalet = myTreeView->palette();
429 QColor aTreeBack = aTreePalet.color(QPalette::Base);
432 aPalet.setColor(QPalette::Base, aTreeBack);
433 aPalet.setColor(QPalette::Window, aTreeBack);
434 aLabelWgt->setPalette(aPalet);
436 myDocModel = new XGUI_DataModel(this);
437 connect(myDocModel, SIGNAL(beforeTreeRebuild()), SLOT(onBeforeReset()));
438 connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset()));
440 connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
441 SLOT(onContextMenuRequested(QContextMenuEvent*)));
444 //***************************************************
445 XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
449 void XGUI_ObjectsBrowser::initialize(ModuleBase_ITreeNode* theRoot)
451 //myDocModel->setXMLReader(theReader);
452 myDocModel->setRoot(theRoot);
453 myTreeView->setModel(myDocModel);
455 // It has to be done after setting of model
456 myActiveDocLbl->setTreeView(myTreeView);
458 QItemSelectionModel* aSelMod = myTreeView->selectionModel();
459 connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
460 this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
463 //***************************************************
464 void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
466 QModelIndexList aIndexes;
467 QObjectPtrList aSelectedData = selectedObjects(&aIndexes);
468 bool toEnable = false;
470 if (aSelectedData.size() == 1) {
471 QModelIndex aSelected = myTreeView->indexAt(theEvent->pos());
472 if (!aIndexes.contains(aSelected))
473 return; // menu is called on non selected item
475 Qt::ItemFlags aFlags = dataModel()->flags(aIndexes.first());
476 toEnable = ((aFlags & Qt::ItemIsEditable) != 0);
478 foreach(QAction* aCmd, actions()) {
479 aCmd->setEnabled(toEnable);
481 emit contextMenuRequested(theEvent);
484 //***************************************************
485 void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt)
487 myTreeView->selectionModel()->clearSelection();
488 //Empty feature pointer means that selected root document
489 foreach(QAction* aCmd, actions()) {
490 aCmd->setEnabled(true);
492 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, thePnt, myActiveDocLbl->mapToGlobal(thePnt));
493 emit contextMenuRequested(&aEvent);
496 //***************************************************
497 void XGUI_ObjectsBrowser::onEditItem()
499 QObjectPtrList aSelectedData = selectedObjects();
500 if (aSelectedData.size() > 0) {
501 ObjectPtr anObject = aSelectedData.first();
502 if (anObject.get()) { // Selection happens in TreeView
503 // check whether the object can be renamed. There should not be parts which are not loaded
504 std::set<FeaturePtr> aFeatures;
505 aFeatures.insert(ModelAPI_Feature::feature(anObject));
506 if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aFeatures))
509 // Find index which corresponds the feature
511 foreach(QModelIndex aIdx, selectedIndexes()) {
512 if (aIdx.column() == 1) {
513 ObjectPtr aFea = dataModel()->object(aIdx);
514 if (dataModel()->object(aIdx)->isSame(anObject)) {
520 if (aIndex.isValid()) {
521 myTreeView->setCurrentIndex(aIndex);
522 myTreeView->edit(aIndex);
529 //***************************************************
530 QList<ModuleBase_ITreeNode*> XGUI_ObjectsBrowser::expandedItems(const QModelIndex& theParent) const
532 QList<ModuleBase_ITreeNode*> aIndexes;
534 int aCount = myDocModel->rowCount(theParent);
535 for (int i = 0; i < aCount; i++) {
536 aIndex = myDocModel->index(i, 0, theParent);
537 if (myDocModel->hasChildren(aIndex)) {
538 if (myTreeView->isExpanded(aIndex)) {
539 aIndexes.append((ModuleBase_ITreeNode*)aIndex.internalPointer());
540 QList<ModuleBase_ITreeNode*> aSubIndexes = expandedItems(aIndex);
541 if (!aSubIndexes.isEmpty())
542 aIndexes.append(aSubIndexes);
549 //***************************************************
550 void XGUI_ObjectsBrowser::rebuildDataTree()
552 myDocModel->root()->update();
553 myDocModel->rebuildDataTree();
557 //***************************************************
558 void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects)
560 QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
561 QModelIndexList aIndexes = aSelectModel->selectedIndexes();
562 if (theObjects.size() == 0) {
563 bool aIsBlock = aSelectModel->blockSignals(true);
564 aSelectModel->clear();
565 aSelectModel->blockSignals(aIsBlock);
566 foreach(QModelIndex aIdx, aIndexes) {
567 myTreeView->update(aIdx);
573 QModelIndexList aUnselect;
574 QObjectPtrList aToSelect = theObjects;
575 QHash<qint64, ObjectPtr> aNotChanged;
576 foreach(QModelIndex aIdx, aIndexes) {
577 aObject = myDocModel->object(aIdx);
579 if (aToSelect.contains(aObject)) {
580 aNotChanged.insert((qint64)aObject.get(), aObject);
582 aUnselect.append(aIdx);
586 aUnselect.append(aIdx);
590 foreach(ObjectPtr aObj, aNotChanged)
591 aToSelect.removeAll(aObj);
593 bool aIsBlock = aSelectModel->blockSignals(true);
594 foreach(QModelIndex aIdx, aUnselect) {
595 aSelectModel->select(aIdx, QItemSelectionModel::Deselect);
596 myTreeView->update(aIdx);
599 QModelIndex aIndex0, aIndex1, aIndex2, aCurrent;
600 foreach(ObjectPtr aFeature, aToSelect) {
601 aIndex1 = myDocModel->objectIndex(aFeature, 1);
602 if (aIndex1.isValid()) {
603 if (!aCurrent.isValid())
605 aIndex0 = myDocModel->objectIndex(aFeature, 0);
606 aIndex2 = myDocModel->objectIndex(aFeature, 2);
607 aSelectModel->select(aIndex1, QItemSelectionModel::Select | QItemSelectionModel::Rows);
608 myTreeView->update(aIndex0);
609 myTreeView->update(aIndex1);
610 myTreeView->update(aIndex2);
613 aSelectModel->setCurrentIndex(aCurrent, QItemSelectionModel::NoUpdate);
614 aSelectModel->blockSignals(aIsBlock);
617 //***************************************************
618 void XGUI_ObjectsBrowser::ensureVisible(const ObjectPtr theObject)
620 QModelIndex aIndex = myDocModel->objectIndex(theObject);
621 if (aIndex.isValid()) {
622 QModelIndex aParent = aIndex.parent();
623 while (aParent.isValid()) {
624 myTreeView->expand(aParent);
625 aParent = aParent.parent();
627 myTreeView->scrollTo(aIndex);
631 //***************************************************
632 void XGUI_ObjectsBrowser::clearContent()
637 //***************************************************
638 void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
639 const QItemSelection& theDeselected)
641 onSelectionChanged();
644 //***************************************************
645 void XGUI_ObjectsBrowser::onSelectionChanged()
647 emit selectionChanged();
650 //***************************************************
651 QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) const
653 QObjectPtrList aList;
654 QModelIndexList aIndexes = selectedIndexes();
655 XGUI_DataModel* aModel = dataModel();
657 foreach(QModelIndex aIdx, aIndexes) {
658 if (aIdx.column() == 1) {
659 ObjectPtr aObject = aModel->object(aIdx);
661 aList.append(aObject);
663 theIndexes->append(aIdx);
670 void XGUI_ObjectsBrowser::onBeforeReset()
672 myExpandedItems = expandedItems();
675 void XGUI_ObjectsBrowser::onAfterModelReset()
677 XGUI_DataModel* aModel = myTreeView->dataModel();
679 foreach(ModuleBase_ITreeNode* aNode, myExpandedItems) {
680 if (aModel->hasNode(aNode)) {
681 aIndex = aModel->getIndex(aNode, 0);
682 if (aIndex.isValid() && (myTreeView->dataModel()->hasIndex(aIndex)))
683 myTreeView->setExpanded(aIndex, true);
686 myExpandedItems.clear();
689 std::list<bool> XGUI_ObjectsBrowser::getStateForDoc(DocumentPtr theDoc) const
691 std::list<bool> aStates;
692 XGUI_DataModel* aModel = dataModel();
693 QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
694 int aNbChild = aModel->rowCount(aRootIdx);
695 for (int i = 0; i < aNbChild; i++) {
696 QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
697 aStates.push_back(myTreeView->isExpanded(aIdx));
702 void XGUI_ObjectsBrowser::setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates)
704 if (theStates.size() == 0)
706 XGUI_DataModel* aModel = dataModel();
707 QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
708 int aNbChild = aModel->rowCount(aRootIdx);
710 std::list<bool>::const_iterator aIt;
712 for (aIt = theStates.cbegin(); aIt != theStates.cend(); aIt++, i++) {
715 QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
716 myTreeView->setExpanded(aIdx, (*aIt));
720 void XGUI_ObjectsBrowser::updateAllIndexes(int theColumn, const QModelIndex& theParent)
722 int aNb = myDocModel->rowCount(theParent);
723 for (int i = 0; i < aNb; i++) {
724 QModelIndex aIdx = myDocModel->index(i, theColumn, theParent);
725 if (aIdx.isValid() && myDocModel->hasIndex(aIdx)) {
726 myTreeView->update(aIdx);
727 if (myTreeView->isExpanded(aIdx))
728 updateAllIndexes(theColumn, aIdx);
733 QMap<ObjectPtr, bool> XGUI_ObjectsBrowser::getFoldersState(DocumentPtr theDoc) const
735 QMap<ObjectPtr, bool> aMap;
737 int aNb = theDoc->size(ModelAPI_Folder::group());
739 for (int i = 0; i < aNb; i++) {
740 aObj = theDoc->object(ModelAPI_Folder::group(), i);
741 QModelIndex aIdx = myDocModel->objectIndex(aObj, 0);
742 aMap[aObj] = myTreeView->isExpanded(aIdx);
747 void XGUI_ObjectsBrowser::setFoldersState(const QMap<ObjectPtr, bool>& theStates)
749 QMap<ObjectPtr, bool>::const_iterator aIt;
750 for (aIt = theStates.constBegin(); aIt != theStates.constEnd(); aIt++) {
751 QModelIndex aIdx = myDocModel->objectIndex(aIt.key(), 0);
752 myTreeView->setExpanded(aIdx, aIt.value());
757 void XGUI_ObjectsBrowser::resizeEvent(QResizeEvent* theEvent)
759 QWidget::resizeEvent(theEvent);