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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    clearClipboard();
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -178,6 +181,8 @@ bool RimUiTreeModelPdm::deleteRangeFilter(const QModelIndex& itemIndex)
 | 
			
		||||
        rangeFilterCollection->reservoirView()->createDisplayModelAndRedraw();
 | 
			
		||||
    }    
 | 
			
		||||
 | 
			
		||||
    clearClipboard();
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -200,29 +205,36 @@ bool RimUiTreeModelPdm::deleteReservoirView(const QModelIndex& itemIndex)
 | 
			
		||||
    reservoirView->eclipseCase()->removeReservoirView(reservoirView);
 | 
			
		||||
    delete reservoirView;
 | 
			
		||||
 | 
			
		||||
    clearClipboard();
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
    CVF_ASSERT(uiItem);
 | 
			
		||||
    QModelIndex mi = getModelIndexFromPdmObjectRecursive(caseCollectionModelIndex, reservoir);
 | 
			
		||||
    if (mi.isValid())
 | 
			
		||||
    {
 | 
			
		||||
        caf::PdmUiTreeItem* uiItem = getTreeItemFromIndex(mi);
 | 
			
		||||
        CVF_ASSERT(uiItem);
 | 
			
		||||
 | 
			
		||||
    RimReservoir* reservoir = dynamic_cast<RimReservoir*>(uiItem->dataObject().p());
 | 
			
		||||
    CVF_ASSERT(reservoir);
 | 
			
		||||
 | 
			
		||||
    // Remove Ui items pointing at the pdm object to delete
 | 
			
		||||
    removeRow(itemIndex.row(), itemIndex.parent());
 | 
			
		||||
        // Remove Ui items pointing at the pdm object to delete
 | 
			
		||||
        removeRow(mi.row(), mi.parent());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    RimProject* proj = RIApplication::instance()->project();
 | 
			
		||||
    proj->removeCaseFromAllGroups(reservoir);
 | 
			
		||||
 | 
			
		||||
    delete reservoir;
 | 
			
		||||
 | 
			
		||||
    clearClipboard();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -456,6 +468,8 @@ void RimUiTreeModelPdm::deleteInputProperty(const QModelIndex& itemIndex)
 | 
			
		||||
    inputReservoir->removeProperty(inputProperty);
 | 
			
		||||
 | 
			
		||||
    delete inputProperty;
 | 
			
		||||
 | 
			
		||||
    clearClipboard();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -658,6 +672,26 @@ bool RimUiTreeModelPdm::deleteObjectFromPdmPointersField(const QModelIndex& item
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    clearClipboard();
 | 
			
		||||
 | 
			
		||||
    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 RimCellRangeFilter;
 | 
			
		||||
class RimReservoir;
 | 
			
		||||
class RimReservoirView;
 | 
			
		||||
class RimInputProperty;
 | 
			
		||||
class RimStatisticalCalculation;
 | 
			
		||||
@@ -103,7 +104,7 @@ public:
 | 
			
		||||
    bool            deletePropertyFilter(const QModelIndex& itemIndex);
 | 
			
		||||
    bool            deleteReservoirView(const QModelIndex& itemIndex);
 | 
			
		||||
    void            deleteInputProperty(const QModelIndex& itemIndex);
 | 
			
		||||
    void            deleteReservoir(const QModelIndex& itemIndex);
 | 
			
		||||
    void            deleteReservoir(RimReservoir* reservoir);
 | 
			
		||||
 | 
			
		||||
    RimCellPropertyFilter*  addPropertyFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
 | 
			
		||||
    RimCellRangeFilter*     addRangeFilter(const QModelIndex& itemIndex, QModelIndex& insertedModelIndex);
 | 
			
		||||
@@ -120,6 +121,7 @@ public:
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void            slotRefreshScriptTree(QString path);
 | 
			
		||||
    void            clearClipboard();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QFileSystemWatcher* m_scriptChangeDetector;
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,7 @@
 | 
			
		||||
#include "RimBinaryExportSettings.h"
 | 
			
		||||
#include "RigReservoirCellResults.h"
 | 
			
		||||
#include "RimStatisticalCalculation.h"
 | 
			
		||||
#include "RimResultReservoir.h"
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------------------------------------
 | 
			
		||||
/// 
 | 
			
		||||
@@ -783,7 +784,26 @@ void RimUiTreeView::slotCloseCase()
 | 
			
		||||
    RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
 | 
			
		||||
    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            removeRows(int position, int rows, const QModelIndex &parent = QModelIndex());
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
protected:
 | 
			
		||||
    QModelIndex getModelIndexFromPdmObjectRecursive(const QModelIndex& root, const PdmObject * object) const;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user