Made adding of grid group more robust

p4#: 21236
This commit is contained in:
Magne Sjaastad
2013-04-11 11:03:52 +02:00
parent e70615d02a
commit 94a4d83885
3 changed files with 19 additions and 23 deletions

View File

@@ -572,38 +572,34 @@ RimStatisticsCase* RimUiTreeModelPdm::addStatisticalCalculation(const QModelInde
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimIdenticalGridCaseGroup* RimUiTreeModelPdm::addCaseGroup(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex)
RimIdenticalGridCaseGroup* RimUiTreeModelPdm::addCaseGroup(QModelIndex& insertedModelIndex)
{
RimProject* proj = RiaApplication::instance()->project();
CVF_ASSERT(proj);
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
if (currentItem)
{
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()) ||
dynamic_cast<RimCase*>(currentItem->dataObject().p()))
{
QModelIndex rootIndex = itemIndex.parent();
caf::PdmUiTreeItem* rootTreeItem = currentItem->parent();
QModelIndex scriptModelIndex = getModelIndexFromPdmObject(proj->scriptCollection());
if (!scriptModelIndex.isValid()) return NULL;
// New case group is inserted before the last item, the script item
int position = rootTreeItem->childCount() - 1;
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(scriptModelIndex);
if (!currentItem) return NULL;
beginInsertRows(rootIndex, position, position);
QModelIndex rootIndex = scriptModelIndex.parent();
caf::PdmUiTreeItem* rootTreeItem = currentItem->parent();
RimIdenticalGridCaseGroup* createdObject = new RimIdenticalGridCaseGroup;
proj->caseGroups().push_back(createdObject);
// New case group is inserted before the last item, the script item
int position = rootTreeItem->childCount() - 1;
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(rootTreeItem, position, createdObject);
endInsertRows();
beginInsertRows(rootIndex, position, position);
insertedModelIndex = index(position, 0, rootIndex);
RimIdenticalGridCaseGroup* createdObject = new RimIdenticalGridCaseGroup;
proj->caseGroups().push_back(createdObject);
return createdObject;
}
}
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(rootTreeItem, position, createdObject);
endInsertRows();
return NULL;
insertedModelIndex = index(position, 0, rootIndex);
return createdObject;
}
//--------------------------------------------------------------------------------------------------