mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-27 08:47:00 -06:00
Implemented copy of view using context menu and keyboard shortcuts
p4#: 21377
This commit is contained in:
parent
de5542976c
commit
fc405f0fb8
@ -680,6 +680,45 @@ void RimUiTreeModelPdm::addObjects(const QModelIndex& itemIndex, caf::PdmObjectG
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (caseFromItemIndex(itemIndex))
|
||||
{
|
||||
std::vector<caf::PdmPointer<RimReservoirView> > typedObjects;
|
||||
pdmObjects.createCopyByType(&typedObjects);
|
||||
|
||||
if (typedObjects.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RimCase* rimCase = caseFromItemIndex(itemIndex);
|
||||
QModelIndex collectionIndex = getModelIndexFromPdmObject(rimCase);
|
||||
caf::PdmUiTreeItem* collectionItem = getTreeItemFromIndex(collectionIndex);
|
||||
|
||||
// Add cases to case group
|
||||
for (size_t i = 0; i < typedObjects.size(); i++)
|
||||
{
|
||||
RimReservoirView* rimReservoirView = typedObjects[i];
|
||||
QString nameOfCopy = QString("Copy of ") + rimReservoirView->name;
|
||||
rimReservoirView->name = nameOfCopy;
|
||||
|
||||
rimReservoirView->setEclipseCase(rimCase);
|
||||
|
||||
// Delete all wells to be able to copy/paste between cases, as the wells differ between cases
|
||||
rimReservoirView->wellCollection()->wells().deleteAllChildObjects();
|
||||
|
||||
caf::PdmObjectGroup::initAfterReadTraversal(rimReservoirView);
|
||||
|
||||
rimReservoirView->loadDataAndUpdate();
|
||||
rimCase->reservoirViews().push_back(rimReservoirView);
|
||||
|
||||
int position = static_cast<int>(rimCase->reservoirViews().size());
|
||||
beginInsertRows(collectionIndex, position, position);
|
||||
|
||||
caf::PdmUiTreeItem* childItem = caf::UiTreeItemBuilderPdm::buildViewItems(collectionItem, position, rimReservoirView);
|
||||
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -902,3 +941,27 @@ void RimUiTreeModelPdm::addToParentAndBuildUiItems(caf::PdmUiTreeItem* parentTre
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimCase* RimUiTreeModelPdm::caseFromItemIndex(const QModelIndex& itemIndex)
|
||||
{
|
||||
caf::PdmUiTreeItem* currentItem = getTreeItemFromIndex(itemIndex);
|
||||
|
||||
RimCase* rimCase = NULL;
|
||||
|
||||
if (dynamic_cast<RimCase*>(currentItem->dataObject().p()))
|
||||
{
|
||||
rimCase = dynamic_cast<RimCase*>(currentItem->dataObject().p());
|
||||
}
|
||||
else if (dynamic_cast<RimReservoirView*>(currentItem->dataObject().p()))
|
||||
{
|
||||
RimReservoirView* reservoirView = dynamic_cast<RimReservoirView*>(currentItem->dataObject().p());
|
||||
CVF_ASSERT(reservoirView);
|
||||
|
||||
rimCase = reservoirView->eclipseCase();
|
||||
}
|
||||
|
||||
return rimCase;
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,8 @@ private slots:
|
||||
|
||||
private:
|
||||
void clearClipboard();
|
||||
RimCase* caseFromItemIndex(const QModelIndex& itemIndex);
|
||||
|
||||
private:
|
||||
QFileSystemWatcher* m_scriptChangeDetector;
|
||||
};
|
||||
|
@ -85,6 +85,8 @@ void RimUiTreeView::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
QMenu menu;
|
||||
menu.addAction(QString("New View"), this, SLOT(slotAddView()));
|
||||
menu.addAction(QString("Copy View"), this, SLOT(slotCopyPdmObjectToClipboard()));
|
||||
menu.addAction(m_pasteAction);
|
||||
menu.addAction(QString("Delete"), this, SLOT(slotDeleteView()));
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
@ -941,7 +943,8 @@ void RimUiTreeView::keyPressEvent(QKeyEvent* keyEvent)
|
||||
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex());
|
||||
if (uiItem)
|
||||
{
|
||||
if (dynamic_cast<RimCase*>(uiItem->dataObject().p()))
|
||||
if (dynamic_cast<RimCase*>(uiItem->dataObject().p())
|
||||
|| dynamic_cast<RimReservoirView*>(uiItem->dataObject().p()))
|
||||
{
|
||||
if (keyEvent->matches(QKeySequence::Copy))
|
||||
{
|
||||
@ -954,7 +957,8 @@ void RimUiTreeView::keyPressEvent(QKeyEvent* keyEvent)
|
||||
|
||||
if (dynamic_cast<RimIdenticalGridCaseGroup*>(uiItem->dataObject().p())
|
||||
|| dynamic_cast<RimCaseCollection*>(uiItem->dataObject().p())
|
||||
|| dynamic_cast<RimCase*>(uiItem->dataObject().p()))
|
||||
|| dynamic_cast<RimCase*>(uiItem->dataObject().p())
|
||||
|| dynamic_cast<RimReservoirView*>(uiItem->dataObject().p()))
|
||||
{
|
||||
if (keyEvent->matches(QKeySequence::Paste))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user