From 8c28e8ff6c7ed46d01bfefa4820b74ca33c149c2 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 22 Apr 2013 11:54:41 +0200 Subject: [PATCH] Create UI tree items and insert in parent when opening new cases from file. Avoid building the complete tree using onProjectOpenedOrClosed() p4#: 21357 --- .../Application/RiaApplication.cpp | 16 ++++++++++++++-- .../ProjectDataModel/RimUiTreeModelPdm.cpp | 19 +++++++++++++++++++ .../ProjectDataModel/RimUiTreeModelPdm.h | 3 ++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index d4be740458..7f9dbb9f79 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -518,7 +518,13 @@ bool RiaApplication::openEclipseCase(const QString& caseName, const QString& cas riv->cellResult()->resultVariable = RimDefines::undefinedResultName(); } - onProjectOpenedOrClosed(); + RimUiTreeModelPdm* uiModel = RiuMainWindow::instance()->uiPdmModel(); + caf::PdmUiTreeItem* projectTreeItem = uiModel->treeItemRoot(); + + // New case is inserted before the last item, the script item + int position = projectTreeItem->childCount() - 1; + + uiModel->addToParentAndBuildUiItems(projectTreeItem, position, rimResultReservoir); return true; } @@ -547,7 +553,13 @@ bool RiaApplication::openInputEclipseCase(const QString& caseName, const QString riv->cellResult()->resultVariable = RimDefines::undefinedResultName(); } - onProjectOpenedOrClosed(); + RimUiTreeModelPdm* uiModel = RiuMainWindow::instance()->uiPdmModel(); + caf::PdmUiTreeItem* projectTreeItem = uiModel->treeItemRoot(); + + // New case is inserted before the last item, the script item + int position = projectTreeItem->childCount() - 1; + + uiModel->addToParentAndBuildUiItems(projectTreeItem, position, rimInputReservoir); return true; } diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp index 1e5224ea79..0a4ee4b6c3 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp @@ -883,3 +883,22 @@ RimIdenticalGridCaseGroup* RimUiTreeModelPdm::gridCaseGroupFromItemIndex(const Q return gridCaseGroup; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimUiTreeModelPdm::addToParentAndBuildUiItems(caf::PdmUiTreeItem* parentTreeItem, int position, caf::PdmObject* pdmObject) +{ + QModelIndex parentModelIndex; + + if (parentTreeItem && parentTreeItem->dataObject()) + { + parentModelIndex = getModelIndexFromPdmObject(parentTreeItem->dataObject()); + } + + beginInsertRows(parentModelIndex, position, position); + + caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(parentTreeItem, position, pdmObject); + + endInsertRows(); +} + diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h index 81ba4f43c9..7a5e30722e 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.h @@ -61,6 +61,8 @@ public: RimReservoirView* addReservoirView(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex); void addInputProperty(const QModelIndex& itemIndex, const QStringList& fileNames); + void addToParentAndBuildUiItems(caf::PdmUiTreeItem* parentTreeItem, int position, caf::PdmObject* pdmObject); + void addObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects); void moveObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects); @@ -84,7 +86,6 @@ private slots: private: void clearClipboard(); - private: QFileSystemWatcher* m_scriptChangeDetector; };