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(); RimProject* proj = RiaApplication::instance()->project();
CVF_ASSERT(proj); CVF_ASSERT(proj);
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex); QModelIndex scriptModelIndex = getModelIndexFromPdmObject(proj->scriptCollection());
if (currentItem) if (!scriptModelIndex.isValid()) return NULL;
{
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()) ||
dynamic_cast<RimCase*>(currentItem->dataObject().p()))
{
QModelIndex rootIndex = itemIndex.parent();
caf::PdmUiTreeItem* rootTreeItem = currentItem->parent();
// New case group is inserted before the last item, the script item caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(scriptModelIndex);
int position = rootTreeItem->childCount() - 1; if (!currentItem) return NULL;
beginInsertRows(rootIndex, position, position); QModelIndex rootIndex = scriptModelIndex.parent();
caf::PdmUiTreeItem* rootTreeItem = currentItem->parent();
RimIdenticalGridCaseGroup* createdObject = new RimIdenticalGridCaseGroup; // New case group is inserted before the last item, the script item
proj->caseGroups().push_back(createdObject); int position = rootTreeItem->childCount() - 1;
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(rootTreeItem, position, createdObject); beginInsertRows(rootIndex, position, position);
endInsertRows();
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;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -116,7 +116,7 @@ public:
void moveObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects); void moveObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects);
RimStatisticsCase* addStatisticalCalculation(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex); RimStatisticsCase* addStatisticalCalculation(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
RimIdenticalGridCaseGroup* addCaseGroup(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex); RimIdenticalGridCaseGroup* addCaseGroup(QModelIndex& insertedModelIndex);
bool deleteObjectFromPdmPointersField(const QModelIndex& itemIndex); bool deleteObjectFromPdmPointersField(const QModelIndex& itemIndex);

View File

@ -878,7 +878,7 @@ void RimUiTreeView::slotAddCaseGroup()
if (myModel) if (myModel)
{ {
QModelIndex insertedIndex; QModelIndex insertedIndex;
myModel->addCaseGroup(currentIndex(), insertedIndex); myModel->addCaseGroup(insertedIndex);
setCurrentIndex(insertedIndex); setCurrentIndex(insertedIndex);
setExpanded(insertedIndex, true); setExpanded(insertedIndex, true);