From: vsv Date: Fri, 18 May 2018 13:19:59 +0000 (+0300) Subject: Task 2.4: Automatic scroll of the Object Browser X-Git-Tag: EDF_2018-1~33^2~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3a51db14ef8fff30570f340ce10ad500611de48c;p=modules%2Fshaper.git Task 2.4: Automatic scroll of the Object Browser --- diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 883d3f2f3..d256e56db 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -545,6 +545,20 @@ void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects) } } +//*************************************************** +void XGUI_ObjectsBrowser::ensureVisible(const ObjectPtr theObject) +{ + QModelIndex aIndex = myDocModel->objectIndex(theObject); + if (aIndex.isValid()) { + QModelIndex aParent = aIndex.parent(); + while (aParent.isValid()) { + myTreeView->expand(aParent); + aParent = aParent.parent(); + } + myTreeView->scrollTo(aIndex); + } +} + //*************************************************** void XGUI_ObjectsBrowser::clearContent() { diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index c5eb366de..f83ddfcad 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -168,6 +168,10 @@ Q_OBJECT /// \param theObjects list of objects to select void setObjectsSelected(const QObjectPtrList& theObjects); + //! Scroll TreeView to make given object visible + //! \param theObject object to make it visible + void ensureVisible(const ObjectPtr theObject); + //! Returns currently selected indexes QModelIndexList selectedIndexes() const { diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 34cbc8b5f..9ca33837f 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -2601,6 +2601,7 @@ void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects) { FeaturePtr aFeature; QObjectPtrList aSelList = theObjects; + QObjectPtrList aNewSel; bool aHasHidden = false; foreach(ObjectPtr aObj, theObjects) { aFeature = std::dynamic_pointer_cast(aObj); @@ -2611,6 +2612,7 @@ void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects) for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) { aHasHidden |= (*aIt)->isConcealed(); aSelList.append(*aIt); + aNewSel.append(*aIt); } } } @@ -2619,6 +2621,7 @@ void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects) bool aBlocked = objectBrowser()->blockSignals(true); objectBrowser()->setObjectsSelected(aSelList); objectBrowser()->blockSignals(aBlocked); + objectBrowser()->ensureVisible(aNewSel.first()); } if (aHasHidden) QMessageBox::information(desktop(), tr("Find results"), @@ -2630,6 +2633,7 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects) { ResultPtr aResult; QObjectPtrList aSelList = theObjects; + QObjectPtrList aNewSel; FeaturePtr aFeature; foreach(ObjectPtr aObj, theObjects) { aResult = std::dynamic_pointer_cast(aObj); @@ -2637,6 +2641,7 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects) aFeature = ModelAPI_Feature::feature(aResult); if (aFeature.get()) { aSelList.append(aFeature); + aNewSel.append(aFeature); } } } @@ -2645,6 +2650,7 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects) bool aBlocked = objectBrowser()->blockSignals(true); objectBrowser()->setObjectsSelected(aSelList); objectBrowser()->blockSignals(aBlocked); + objectBrowser()->ensureVisible(aNewSel.first()); } }