From: vsv Date: Fri, 11 Nov 2016 16:20:31 +0000 (+0300) Subject: Issue #1855: Expand a folder on adding of a first object X-Git-Tag: V_2.6.0~91 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=825fc0c15ec31fb813103b3062fa1e51c0a2d10e;p=modules%2Fshaper.git Issue #1855: Expand a folder on adding of a first object --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 4a74d99f3..bda26290a 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -1073,12 +1074,12 @@ void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser) aLabel->installEventFilter(myMenuMgr); connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(onActiveDocPopup(const QPoint&))); - //QPalette aPalet = aLabel->palette(); - //aPalet.setColor(QPalette::Text, QColor(0, 72, 140)); - //aLabel->setPalette(aPalet); aOB->treeView()->setExpandsOnDoubleClick(false); connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)), SLOT(onTreeViewDoubleClick(const QModelIndex&))); + + Events_Loop* aLoop = Events_Loop::loop(); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); } } @@ -1190,6 +1191,16 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const } } +#define EXPAND_PARENT(OBJ) \ +QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \ +if (aObjIndex.isValid()) { \ + QModelIndex aParent = aObjIndex.parent(); \ + int aCount = aDataModel->rowCount(aParent); \ + if (aCount == 1) \ + aTreeView->setExpanded(aParent, true); \ +} + + void PartSet_Module::processEvent(const std::shared_ptr& theMessage) { if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) { @@ -1232,6 +1243,37 @@ void PartSet_Module::processEvent(const std::shared_ptr& theMess aDisplayer->redisplay(aObj, false); } aDisplayer->updateViewer(); + } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { + std::shared_ptr aUpdMsg = + std::dynamic_pointer_cast(theMessage); + std::set aObjects = aUpdMsg->objects(); + + ObjectPtr aConstrObj; + ObjectPtr aResultObj; + std::set::const_iterator aIt; + std::string aObjType; + for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) { + ObjectPtr aObject = (*aIt); + if ((!aResultObj.get()) && aObject->groupName() == ModelAPI_ResultBody::group()) + aResultObj = aObject; + if ((!aConstrObj.get()) && aObject->groupName() == ModelAPI_ResultConstruction::group()) + aConstrObj = aObject; + if (aResultObj.get() && aConstrObj.get()) + break; + } + + if (aResultObj.get() || aConstrObj.get()) { + XGUI_Workshop* aWorkshop = getWorkshop(); + XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView(); + XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel(); + + if (aResultObj.get()) { + EXPAND_PARENT(aResultObj) + } + if (aConstrObj.get()) { + EXPAND_PARENT(aConstrObj) + } + } } }