mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added GUI for asking user to confirm change for grid case group
p4#: 21142
This commit is contained in:
parent
0fed66deb2
commit
700f18391b
@ -573,38 +573,7 @@ void RimUiTreeModelPdm::addObjects(const QModelIndex& itemIndex, caf::PdmObjectG
|
||||
RimProject* proj = RiaApplication::instance()->project();
|
||||
CVF_ASSERT(proj);
|
||||
|
||||
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
||||
|
||||
RimIdenticalGridCaseGroup* gridCaseGroup = NULL;
|
||||
RimCaseCollection* caseCollection = NULL;
|
||||
|
||||
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()))
|
||||
{
|
||||
gridCaseGroup = dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p());
|
||||
caseCollection = gridCaseGroup->caseCollection();
|
||||
}
|
||||
else if (dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p()))
|
||||
{
|
||||
caseCollection = dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p());
|
||||
CVF_ASSERT(caseCollection);
|
||||
|
||||
gridCaseGroup = caseCollection->parentCaseGroup();
|
||||
}
|
||||
else if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
|
||||
{
|
||||
RimCase* rimReservoir = dynamic_cast<RimCase*>(currentItem->dataObject().p());
|
||||
CVF_ASSERT(rimReservoir);
|
||||
|
||||
caseCollection = rimReservoir->parentCaseCollection();
|
||||
if (caseCollection)
|
||||
{
|
||||
gridCaseGroup = caseCollection->parentCaseGroup();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
RimIdenticalGridCaseGroup* gridCaseGroup = gridCaseGroupFromItemIndex(itemIndex);
|
||||
|
||||
if (gridCaseGroup)
|
||||
{
|
||||
@ -614,7 +583,7 @@ void RimUiTreeModelPdm::addObjects(const QModelIndex& itemIndex, caf::PdmObjectG
|
||||
RigCaseData* mainEclipseCase = NULL;
|
||||
if (gridCaseGroup->caseCollection()->reservoirs().size() > 0)
|
||||
{
|
||||
RimCase* mainReservoir = gridCaseGroup->caseCollection()->reservoirs()[0];;
|
||||
RimCase* mainReservoir = gridCaseGroup->caseCollection()->reservoirs()[0];
|
||||
mainEclipseCase = mainReservoir->reservoirData();
|
||||
}
|
||||
|
||||
@ -645,7 +614,7 @@ void RimUiTreeModelPdm::addObjects(const QModelIndex& itemIndex, caf::PdmObjectG
|
||||
caf::PdmObjectGroup::initAfterReadTraversal(rimResultReservoir);
|
||||
|
||||
{
|
||||
QModelIndex rootIndex = getModelIndexFromPdmObject(caseCollection);
|
||||
QModelIndex rootIndex = getModelIndexFromPdmObject(gridCaseGroup->caseCollection());
|
||||
caf::PdmUiTreeItem* caseCollectionUiItem = getTreeItemFromIndex(rootIndex);
|
||||
|
||||
int position = rowCount(rootIndex);
|
||||
@ -663,6 +632,24 @@ void RimUiTreeModelPdm::addObjects(const QModelIndex& itemIndex, caf::PdmObjectG
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeModelPdm::moveObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects)
|
||||
{
|
||||
addObjects(itemIndex, pdmObjects);
|
||||
|
||||
// Delete objects from original container
|
||||
std::vector<caf::PdmPointer<RimResultCase> > typedObjects;
|
||||
pdmObjects.objectsByType(&typedObjects);
|
||||
|
||||
for (size_t i = 0; i < typedObjects.size(); i++)
|
||||
{
|
||||
RimCase* rimReservoir = typedObjects[i];
|
||||
deleteReservoir(rimReservoir);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -777,18 +764,13 @@ bool RimUiTreeModelPdm::dropMimeData(const QMimeData *data, Qt::DropAction actio
|
||||
pog.objects().push_back(pdmObj);
|
||||
}
|
||||
|
||||
addObjects(parent, pog);
|
||||
|
||||
if (action == Qt::MoveAction)
|
||||
if (action == Qt::CopyAction)
|
||||
{
|
||||
std::vector<caf::PdmPointer<RimResultCase> > typedObjects;
|
||||
pog.objectsByType(&typedObjects);
|
||||
|
||||
for (size_t i = 0; i < typedObjects.size(); i++)
|
||||
{
|
||||
RimCase* rimReservoir = typedObjects[i];
|
||||
deleteReservoir(rimReservoir);
|
||||
}
|
||||
addObjects(parent, pog);
|
||||
}
|
||||
else if (action == Qt::MoveAction)
|
||||
{
|
||||
moveObjects(parent, pog);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -817,3 +799,38 @@ QStringList RimUiTreeModelPdm::mimeTypes() const
|
||||
return types;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Return grid case group when QModelIndex points to grid case group, case collection or case in a grid case group
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimIdenticalGridCaseGroup* RimUiTreeModelPdm::gridCaseGroupFromItemIndex(const QModelIndex& itemIndex)
|
||||
{
|
||||
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
||||
|
||||
RimIdenticalGridCaseGroup* gridCaseGroup = NULL;
|
||||
|
||||
if (dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p()))
|
||||
{
|
||||
gridCaseGroup = dynamic_cast<RimIdenticalGridCaseGroup*>(currentItem->dataObject().p());
|
||||
}
|
||||
else if (dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p()))
|
||||
{
|
||||
RimCaseCollection* caseCollection = dynamic_cast<RimCaseCollection*>(currentItem->dataObject().p());
|
||||
CVF_ASSERT(caseCollection);
|
||||
|
||||
gridCaseGroup = caseCollection->parentCaseGroup();
|
||||
}
|
||||
else if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
|
||||
{
|
||||
RimCase* rimReservoir = dynamic_cast<RimCase*>(currentItem->dataObject().p());
|
||||
CVF_ASSERT(rimReservoir);
|
||||
|
||||
RimCaseCollection* caseCollection = rimReservoir->parentCaseCollection();
|
||||
if (caseCollection)
|
||||
{
|
||||
gridCaseGroup = caseCollection->parentCaseGroup();
|
||||
}
|
||||
}
|
||||
|
||||
return gridCaseGroup;
|
||||
}
|
||||
|
||||
|
@ -111,9 +111,11 @@ public:
|
||||
RimCellRangeFilter* addRangeFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
||||
RimReservoirView* addReservoirView(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
||||
void addInputProperty(const QModelIndex& itemIndex, const QStringList& fileNames);
|
||||
void addObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects);
|
||||
|
||||
RimStatisticsCase* addStatisticalCalculation(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
||||
void addObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects);
|
||||
void moveObjects(const QModelIndex& itemIndex, caf::PdmObjectGroup& pdmObjects);
|
||||
|
||||
RimStatisticsCase* addStatisticalCalculation(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
||||
RimIdenticalGridCaseGroup* addCaseGroup(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
||||
|
||||
bool deleteObjectFromPdmPointersField(const QModelIndex& itemIndex);
|
||||
@ -126,6 +128,8 @@ public:
|
||||
virtual QMimeData* mimeData(const QModelIndexList &indexes) const;
|
||||
virtual QStringList mimeTypes() const;
|
||||
|
||||
RimIdenticalGridCaseGroup* gridCaseGroupFromItemIndex(const QModelIndex& itemIndex);
|
||||
|
||||
private slots:
|
||||
void slotRefreshScriptTree(QString path);
|
||||
|
||||
|
@ -796,28 +796,31 @@ void RimUiTreeView::slotWriteBinaryResultAsInputProperty()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeView::slotCloseCase()
|
||||
{
|
||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||
if (myModel)
|
||||
if (userConfirmedGridCaseGroupChange(currentIndex()))
|
||||
{
|
||||
QItemSelectionModel* m = selectionModel();
|
||||
CVF_ASSERT(m);
|
||||
|
||||
caf::PdmObjectGroup group;
|
||||
|
||||
QModelIndexList mil = m->selectedRows();
|
||||
for (int i = 0; i < mil.size(); i++)
|
||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||
if (myModel)
|
||||
{
|
||||
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(mil.at(i));
|
||||
group.addObject(uiItem->dataObject().p());
|
||||
}
|
||||
QItemSelectionModel* m = selectionModel();
|
||||
CVF_ASSERT(m);
|
||||
|
||||
std::vector<caf::PdmPointer<RimCase> > typedObjects;
|
||||
group.objectsByType(&typedObjects);
|
||||
caf::PdmObjectGroup group;
|
||||
|
||||
for (size_t i = 0; i < typedObjects.size(); i++)
|
||||
{
|
||||
RimCase* rimReservoir = typedObjects[i];
|
||||
myModel->deleteReservoir(rimReservoir);
|
||||
QModelIndexList mil = m->selectedRows();
|
||||
for (int i = 0; i < mil.size(); i++)
|
||||
{
|
||||
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(mil.at(i));
|
||||
group.addObject(uiItem->dataObject().p());
|
||||
}
|
||||
|
||||
std::vector<caf::PdmPointer<RimCase> > typedObjects;
|
||||
group.objectsByType(&typedObjects);
|
||||
|
||||
for (size_t i = 0; i < typedObjects.size(); i++)
|
||||
{
|
||||
RimCase* rimReservoir = typedObjects[i];
|
||||
myModel->deleteReservoir(rimReservoir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -918,11 +921,14 @@ void RimUiTreeView::slotPastePdmObjects()
|
||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||
if (!myModel) return;
|
||||
|
||||
caf::PdmObjectGroup objectGroup;
|
||||
createPdmObjectsFromClipboard(&objectGroup);
|
||||
if (objectGroup.objects().size() == 0) return;
|
||||
if (userConfirmedGridCaseGroupChange(currentIndex()))
|
||||
{
|
||||
caf::PdmObjectGroup objectGroup;
|
||||
createPdmObjectsFromClipboard(&objectGroup);
|
||||
if (objectGroup.objects().size() == 0) return;
|
||||
|
||||
myModel->addObjects(currentIndex(), objectGroup);
|
||||
myModel->addObjects(currentIndex(), objectGroup);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -999,3 +1005,50 @@ bool RimUiTreeView::hasClipboardValidData()
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeView::dropEvent(QDropEvent* dropEvent)
|
||||
{
|
||||
if (userConfirmedGridCaseGroupChange(currentIndex()))
|
||||
{
|
||||
QTreeView::dropEvent(dropEvent);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Displays a question to the user when a grid case group with statistical results is about to change
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimUiTreeView::userConfirmedGridCaseGroupChange(const QModelIndex & itemIndex)
|
||||
{
|
||||
if (!itemIndex.isValid()) return true;
|
||||
|
||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||
if (myModel)
|
||||
{
|
||||
RimIdenticalGridCaseGroup* gridCaseGroup = myModel->gridCaseGroupFromItemIndex(itemIndex);
|
||||
if (gridCaseGroup)
|
||||
{
|
||||
// TODO: This test has to check if any of the statistical cases has result values
|
||||
if (gridCaseGroup->statisticsCaseCollection()->reservoirs.size() > 0)
|
||||
{
|
||||
RiuMainWindow* mainWnd = RiuMainWindow::instance();
|
||||
|
||||
QMessageBox msgBox(mainWnd);
|
||||
msgBox.setIcon(QMessageBox::Question);
|
||||
msgBox.setText("The destination case group has existing statistic results, and these results will be deleted if you continue");
|
||||
msgBox.setInformativeText("Do you want to continue?");
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
int ret = msgBox.exec();
|
||||
if (ret == QMessageBox::No)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -89,10 +89,13 @@ signals:
|
||||
void selectedObjectChanged( caf::PdmObject* pdmObject );
|
||||
|
||||
private:
|
||||
bool userConfirmedGridCaseGroupChange(const QModelIndex & itemIndex);
|
||||
|
||||
void createPdmObjectsFromClipboard(caf::PdmObjectGroup* objectGroup);
|
||||
bool hasClipboardValidData();
|
||||
|
||||
virtual void keyPressEvent(QKeyEvent* keyEvent);
|
||||
virtual void dropEvent(QDropEvent* dropEvent);
|
||||
|
||||
private:
|
||||
QAction* m_pasteAction;
|
||||
|
Loading…
Reference in New Issue
Block a user