mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added general function used to remove(and delete) pdmObject from pdmPointersField
Used when closing a grid group p4#: 20992
This commit is contained in:
parent
9abe7a3b13
commit
06a2f7e17f
@ -615,3 +615,43 @@ void RimUiTreeModelPdm::addObjects(const QModelIndex& itemIndex, caf::PdmObjectG
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimUiTreeModelPdm::deleteObjectFromPdmPointersField(const QModelIndex& itemIndex)
|
||||
{
|
||||
if (!itemIndex.isValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
||||
CVF_ASSERT(currentItem);
|
||||
|
||||
caf::PdmObject* currentPdmObject = currentItem->dataObject().p();
|
||||
CVF_ASSERT(currentPdmObject);
|
||||
|
||||
std::vector<caf::PdmFieldHandle*> parentFields;
|
||||
currentPdmObject->parentFields(parentFields);
|
||||
|
||||
if (parentFields.size() == 1)
|
||||
{
|
||||
beginRemoveRows(itemIndex.parent(), itemIndex.row(), itemIndex.row());
|
||||
if (currentItem->parent())
|
||||
{
|
||||
currentItem->parent()->removeChildren(itemIndex.row(), 1);
|
||||
}
|
||||
endRemoveRows();
|
||||
|
||||
caf::PdmPointersField<RimIdenticalGridCaseGroup*>* caseGroup = dynamic_cast<caf::PdmPointersField<RimIdenticalGridCaseGroup*> *>(parentFields[0]);
|
||||
if (caseGroup)
|
||||
{
|
||||
caseGroup->removeChildObject(currentPdmObject);
|
||||
|
||||
delete currentPdmObject;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,8 @@ public:
|
||||
RimStatisticalCalculation* addStatisticalCalculation(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
||||
RimIdenticalGridCaseGroup* addCaseGroup(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
||||
|
||||
bool deleteObjectFromPdmPointersField(const QModelIndex& itemIndex);
|
||||
|
||||
void updateScriptPaths();
|
||||
|
||||
private slots:
|
||||
|
@ -181,6 +181,7 @@ void RimUiTreeView::contextMenuEvent(QContextMenuEvent* event)
|
||||
QMenu menu;
|
||||
menu.addAction(QString("New Case Group"), this, SLOT(slotAddCaseGroup()));
|
||||
menu.addAction(QString("Paste"), this, SLOT(slotPastePdmObjects()));
|
||||
menu.addAction(QString("Close"), this, SLOT(slotDeleteObjectFromPdmPointersField()));
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
else if (dynamic_cast<RimCaseCollection*>(uiItem->dataObject().p()))
|
||||
@ -836,6 +837,18 @@ void RimUiTreeView::slotAddCaseGroup()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeView::slotDeleteObjectFromPdmPointersField()
|
||||
{
|
||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||
if (myModel)
|
||||
{
|
||||
myModel->deleteObjectFromPdmPointersField(currentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -76,7 +76,9 @@ private slots:
|
||||
|
||||
void slotNewStatisticalCase();
|
||||
void slotComputeStatisticalCases();
|
||||
|
||||
void slotAddCaseGroup();
|
||||
void slotDeleteObjectFromPdmPointersField();
|
||||
|
||||
void slotCopyPdmObjectToClipboard();
|
||||
void slotPastePdmObjects();
|
||||
|
Loading…
Reference in New Issue
Block a user