From 56590a8c55716871178076199002ba3f05b9f3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Wed, 2 Oct 2013 15:51:25 +0200 Subject: [PATCH] New Case groups is now correctly positioned in the tree. The context command was not quite up to speed. --- .../ProjectDataModel/RimUiTreeModelPdm.cpp | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp index 4ffd8b299e..c30250b659 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeModelPdm.cpp @@ -591,38 +591,28 @@ RimIdenticalGridCaseGroup* RimUiTreeModelPdm::addCaseGroup(QModelIndex& inserted RimProject* proj = RiaApplication::instance()->project(); CVF_ASSERT(proj); - QModelIndex scriptModelIndex = getModelIndexFromPdmObject(proj->scriptCollection()); - if (!scriptModelIndex.isValid()) return NULL; - - caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(scriptModelIndex); - if (!currentItem) return NULL; - - QModelIndex rootIndex = scriptModelIndex.parent(); - caf::PdmUiTreeItem* rootTreeItem = currentItem->parent(); - - // New case group is inserted before the last item, the script item - int position = rootTreeItem->childCount() - 1; - - beginInsertRows(rootIndex, position, position); - - RimIdenticalGridCaseGroup* createdObject = new RimIdenticalGridCaseGroup; - proj->assignIdToCaseGroup(createdObject); - - RimCase* createdReservoir = createdObject->createAndAppendStatisticsCase(); - proj->assignCaseIdToCase(createdReservoir); - createdObject->name = QString("Grid Case Group %1").arg(position + 1); RimAnalysisModels* analysisModels = proj->activeOilField() ? proj->activeOilField()->analysisModels() : NULL; + if (analysisModels) { + RimIdenticalGridCaseGroup* createdObject = new RimIdenticalGridCaseGroup; + proj->assignIdToCaseGroup(createdObject); + + RimCase* createdReservoir = createdObject->createAndAppendStatisticsCase(); + proj->assignCaseIdToCase(createdReservoir); + createdObject->name = QString("Grid Case Group %1").arg(analysisModels->caseGroups().size() + 1); + analysisModels->caseGroups().push_back(createdObject); + + this->updateUiSubTree(analysisModels); + insertedModelIndex = getModelIndexFromPdmObject(createdObject); + + return createdObject; + } + else + { + return NULL; } - - caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(rootTreeItem, position, createdObject); - endInsertRows(); - - insertedModelIndex = index(position, 0, rootIndex); - - return createdObject; } //--------------------------------------------------------------------------------------------------