mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
As QModelIndex is stored on clipboard, clear after move/delete operations
Added support for multiple delete of reservoir cases p4#: 21007
This commit is contained in:
@@ -140,6 +140,9 @@ bool RimUiTreeModelPdm::deletePropertyFilter(const QModelIndex& itemIndex)
|
|||||||
{
|
{
|
||||||
propertyFilterCollection->reservoirView()->createDisplayModelAndRedraw();
|
propertyFilterCollection->reservoirView()->createDisplayModelAndRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearClipboard();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +181,8 @@ bool RimUiTreeModelPdm::deleteRangeFilter(const QModelIndex& itemIndex)
|
|||||||
rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw();
|
rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearClipboard();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,29 +205,36 @@ bool RimUiTreeModelPdm::deleteReservoirView(const QModelIndex& itemIndex)
|
|||||||
reservoirView->eclipseCase()->removeReservoirView(reservoirView);
|
reservoirView->eclipseCase()->removeReservoirView(reservoirView);
|
||||||
delete reservoirView;
|
delete reservoirView;
|
||||||
|
|
||||||
|
clearClipboard();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimUiTreeModelPdm::deleteReservoir(const QModelIndex& itemIndex)
|
void RimUiTreeModelPdm::deleteReservoir(RimReservoir* reservoir)
|
||||||
{
|
{
|
||||||
CVF_ASSERT(itemIndex.isValid());
|
RimCaseCollection* caseCollection = reservoir->parentCaseCollection();
|
||||||
|
QModelIndex caseCollectionModelIndex = getModelIndexFromPdmObject(caseCollection);
|
||||||
|
if (!caseCollectionModelIndex.isValid()) return;
|
||||||
|
|
||||||
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(itemIndex);
|
QModelIndex mi = getModelIndexFromPdmObjectRecursive(caseCollectionModelIndex, reservoir);
|
||||||
CVF_ASSERT(uiItem);
|
if (mi.isValid())
|
||||||
|
{
|
||||||
|
caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(mi);
|
||||||
|
CVF_ASSERT(uiItem);
|
||||||
|
|
||||||
RimReservoir* reservoir = dynamic_cast<RimReservoir*>(uiItem->dataObject().p());
|
// Remove Ui items pointing at the pdm object to delete
|
||||||
CVF_ASSERT(reservoir);
|
removeRow(mi.row(), mi.parent());
|
||||||
|
}
|
||||||
// Remove Ui items pointing at the pdm object to delete
|
|
||||||
removeRow(itemIndex.row(), itemIndex.parent());
|
|
||||||
|
|
||||||
RimProject* proj = RIApplication::instance()->project();
|
RimProject* proj = RIApplication::instance()->project();
|
||||||
proj->removeCaseFromAllGroups(reservoir);
|
proj->removeCaseFromAllGroups(reservoir);
|
||||||
|
|
||||||
delete reservoir;
|
delete reservoir;
|
||||||
|
|
||||||
|
clearClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -456,6 +468,8 @@ void RimUiTreeModelPdm::deleteInputProperty(const QModelIndex& itemIndex)
|
|||||||
inputReservoir->removeProperty(inputProperty);
|
inputReservoir->removeProperty(inputProperty);
|
||||||
|
|
||||||
delete inputProperty;
|
delete inputProperty;
|
||||||
|
|
||||||
|
clearClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -658,6 +672,26 @@ bool RimUiTreeModelPdm::deleteObjectFromPdmPointersField(const QModelIndex& item
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearClipboard();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimUiTreeModelPdm::clearClipboard()
|
||||||
|
{
|
||||||
|
// We use QModelIndex to identify a selection on the clipboard
|
||||||
|
// When we delete or move an entity, the clipboard data might be invalid
|
||||||
|
|
||||||
|
QClipboard* clipboard = QApplication::clipboard();
|
||||||
|
if (clipboard)
|
||||||
|
{
|
||||||
|
if (dynamic_cast<const MimeDataWithIndexes*>(clipboard->mimeData()))
|
||||||
|
{
|
||||||
|
clipboard->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class QFileSystemWatcher;
|
|||||||
|
|
||||||
class RimCellPropertyFilter;
|
class RimCellPropertyFilter;
|
||||||
class RimCellRangeFilter;
|
class RimCellRangeFilter;
|
||||||
|
class RimReservoir;
|
||||||
class RimReservoirView;
|
class RimReservoirView;
|
||||||
class RimInputProperty;
|
class RimInputProperty;
|
||||||
class RimStatisticalCalculation;
|
class RimStatisticalCalculation;
|
||||||
@@ -103,7 +104,7 @@ public:
|
|||||||
bool deletePropertyFilter(const QModelIndex& itemIndex);
|
bool deletePropertyFilter(const QModelIndex& itemIndex);
|
||||||
bool deleteReservoirView(const QModelIndex& itemIndex);
|
bool deleteReservoirView(const QModelIndex& itemIndex);
|
||||||
void deleteInputProperty(const QModelIndex& itemIndex);
|
void deleteInputProperty(const QModelIndex& itemIndex);
|
||||||
void deleteReservoir(const QModelIndex& itemIndex);
|
void deleteReservoir(RimReservoir* reservoir);
|
||||||
|
|
||||||
RimCellPropertyFilter* addPropertyFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
RimCellPropertyFilter* addPropertyFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
||||||
RimCellRangeFilter* addRangeFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
RimCellRangeFilter* addRangeFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
|
||||||
@@ -120,6 +121,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotRefreshScriptTree(QString path);
|
void slotRefreshScriptTree(QString path);
|
||||||
|
void clearClipboard();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFileSystemWatcher* m_scriptChangeDetector;
|
QFileSystemWatcher* m_scriptChangeDetector;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include "RimBinaryExportSettings.h"
|
#include "RimBinaryExportSettings.h"
|
||||||
#include "RigReservoirCellResults.h"
|
#include "RigReservoirCellResults.h"
|
||||||
#include "RimStatisticalCalculation.h"
|
#include "RimStatisticalCalculation.h"
|
||||||
|
#include "RimResultReservoir.h"
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
@@ -783,7 +784,26 @@ void RimUiTreeView::slotCloseCase()
|
|||||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||||
if (myModel)
|
if (myModel)
|
||||||
{
|
{
|
||||||
myModel->deleteReservoir(currentIndex());
|
QItemSelectionModel* m = selectionModel();
|
||||||
|
CVF_ASSERT(m);
|
||||||
|
|
||||||
|
caf::PdmObjectGroup group;
|
||||||
|
|
||||||
|
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<RimResultReservoir> > typedObjects;
|
||||||
|
group.objectsByType(&typedObjects);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < typedObjects.size(); i++)
|
||||||
|
{
|
||||||
|
RimReservoir* rimReservoir = typedObjects[i];
|
||||||
|
myModel->deleteReservoir(rimReservoir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
virtual bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex());
|
virtual bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex());
|
||||||
virtual bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex());
|
virtual bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex());
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
QModelIndex getModelIndexFromPdmObjectRecursive(const QModelIndex& root, const PdmObject * object) const;
|
QModelIndex getModelIndexFromPdmObjectRecursive(const QModelIndex& root, const PdmObject * object) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user