From 79e7d3604cb260ec0661abccdb223708e03ed741 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 22 Apr 2013 10:04:37 +0200 Subject: [PATCH] Expand up to root when creating a view. Removed use of expandAll() p4#: 21353 --- .../ProjectDataModel/RimUiTreeModelPdm.cpp | 10 ++++++--- .../ProjectDataModel/RimUiTreeView.cpp | 22 ++++++++++++++++++- .../ProjectDataModel/RimUiTreeView.h | 1 + .../UserInterface/RiuMainWindow.cpp | 4 ---- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp index 5357ee7e82..1e5224ea79 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp @@ -372,15 +372,18 @@ RimReservoirView* RimUiTreeModelPdm::addReservoirView(const QModelIndex& itemInd bool itemIndexIsCollection = false; QModelIndex collectionIndex; + int position = 0; if (dynamic_cast(currentItem->dataObject().p())) { collectionItem = currentItem->parent(); collectionIndex = itemIndex.parent(); + position = itemIndex.row(); } else if (dynamic_cast(currentItem->dataObject().p())) { collectionItem = currentItem; collectionIndex = itemIndex; + position = collectionItem->childCount(); } if (collectionItem) @@ -393,14 +396,15 @@ RimReservoirView* RimUiTreeModelPdm::addReservoirView(const QModelIndex& itemInd // Must be run before buildViewItems, as wells are created in this function insertedView->loadDataAndUpdate(); - int viewCount = rowCount(collectionIndex); - beginInsertRows(collectionIndex, viewCount, viewCount); + beginInsertRows(collectionIndex, position, position); // NOTE: -1 as second argument indicates append - caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(collectionItem, -1, insertedView); + caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(collectionItem, position, insertedView); endInsertRows(); + insertedModelIndex = index(position, 0, collectionIndex); + return insertedView; } diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp index 56a4bc9d19..df3140762c 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp @@ -543,7 +543,11 @@ void RimUiTreeView::slotAddView() QModelIndex insertedIndex; myModel->addReservoirView(index, insertedIndex); - + + // Expand parent collection and inserted view item + setExpandedUpToRoot(insertedIndex); + + setCurrentIndex(insertedIndex); } //-------------------------------------------------------------------------------------------------- @@ -827,6 +831,8 @@ void RimUiTreeView::slotNewStatisticsCase() QModelIndex insertedIndex; RimStatisticsCase* newObject = myModel->addStatisticalCalculation(currentIndex(), insertedIndex); setCurrentIndex(insertedIndex); + + setExpanded(insertedIndex, true); } } @@ -1275,3 +1281,17 @@ void RimUiTreeView::storeTreeViewStateToString(QString& treeViewState) } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeView::setExpandedUpToRoot(const QModelIndex& itemIndex) +{ + QModelIndex mi = itemIndex; + + while (mi.isValid()) + { + this->setExpanded(mi, true); + mi = mi.parent(); + } +} + diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeView.h b/ApplicationCode/ProjectDataModel/RimUiTreeView.h index e8a2617b9c..72afbbcfb6 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeView.h +++ b/ApplicationCode/ProjectDataModel/RimUiTreeView.h @@ -106,6 +106,7 @@ private: bool checkAndHandleToggleOfMultipleSelection(); + void setExpandedUpToRoot(const QModelIndex& itemIndex); private: QAction* m_pasteAction; }; diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index c9c1114137..b3560218f3 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -921,8 +921,6 @@ void RiuMainWindow::setPdmRoot(caf::PdmObject* pdmRoot) caf::PdmUiTreeItem* treeItemRoot = caf::UiTreeItemBuilderPdm::buildViewItems(NULL, -1, m_pdmRoot); m_treeModelPdm->setRoot(treeItemRoot); - m_treeView->expandAll(); - if (treeItemRoot && m_treeView->selectionModel()) { connect(m_treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex & , const QModelIndex & )), SLOT(slotCurrentChanged( const QModelIndex & , const QModelIndex & ))); @@ -1074,7 +1072,6 @@ void RiuMainWindow::slotSubWindowActivated(QMdiSubWindow* subWindow) } m_treeView->setCurrentIndex(newSelectionIndex); - //m_treeView->setExpanded(previousViewModelIndex, false); if (newSelectionIndex != newViewModelIndex) { m_treeView->setExpanded(newViewModelIndex, true); @@ -1260,7 +1257,6 @@ void RiuMainWindow::slotNewObjectPropertyView() } treeView->setModel(m_treeModelPdm); - treeView->expandAll(); {