mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Support drag and drop of summary curves
This commit is contained in:
@@ -47,6 +47,7 @@ CAF_PDM_SOURCE_INIT( RimSummaryCurveCollection, "RimSummaryCurveCollection" );
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryCurveCollection::RimSummaryCurveCollection()
|
||||
: curvesAddedOrRemoved( this )
|
||||
{
|
||||
CAF_PDM_InitObject( "Summary Curves", ":/SummaryCurveFilter16x16.png", "", "" );
|
||||
|
||||
@@ -180,16 +181,42 @@ void RimSummaryCurveCollection::addCurve( RimSummaryCurve* curve )
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCurveCollection::insertCurve( RimSummaryCurve* curve, size_t index )
|
||||
{
|
||||
if ( index >= m_curves.size() )
|
||||
{
|
||||
m_curves.push_back( curve );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_curves.insert( index, curve );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCurveCollection::deleteCurve( RimSummaryCurve* curve )
|
||||
{
|
||||
removeCurve( curve );
|
||||
if ( curve )
|
||||
{
|
||||
curve->markCachedDataForPurge();
|
||||
delete curve;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCurveCollection::removeCurve( RimSummaryCurve* curve )
|
||||
{
|
||||
if ( curve )
|
||||
{
|
||||
m_curves.removeChildObject( curve );
|
||||
curve->markCachedDataForPurge();
|
||||
delete curve;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,6 +429,52 @@ RimSummaryPlotSourceStepping*
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCurveCollection::moveCurvesToCollection( RimSummaryCurveCollection* collection,
|
||||
const std::vector<RimSummaryCurve*> curves,
|
||||
RimSummaryCurve* curveToInsertBeforeOrAfter,
|
||||
bool isSwapOperation )
|
||||
{
|
||||
CAF_ASSERT( collection );
|
||||
|
||||
std::set<RimSummaryCurveCollection*> srcCollections;
|
||||
|
||||
for ( auto curve : curves )
|
||||
{
|
||||
RimSummaryCurveCollection* srcCollection = nullptr;
|
||||
curve->firstAncestorOrThisOfTypeAsserted( srcCollection );
|
||||
|
||||
srcCollection->removeCurve( curve );
|
||||
srcCollections.insert( srcCollection );
|
||||
}
|
||||
|
||||
for ( auto collection : srcCollections )
|
||||
{
|
||||
collection->updateConnectedEditors();
|
||||
collection->curvesAddedOrRemoved.send();
|
||||
}
|
||||
|
||||
size_t insertionStartIndex = std::numeric_limits<size_t>::infinity();
|
||||
if ( curveToInsertBeforeOrAfter )
|
||||
{
|
||||
insertionStartIndex = collection->m_curves.index( curveToInsertBeforeOrAfter );
|
||||
}
|
||||
|
||||
if ( insertionStartIndex < collection->m_curves.size() && !isSwapOperation )
|
||||
{
|
||||
insertionStartIndex += 1;
|
||||
}
|
||||
for ( size_t cIdx = 0; cIdx < curves.size(); ++cIdx )
|
||||
{
|
||||
collection->insertCurve( curves[cIdx], insertionStartIndex + cIdx );
|
||||
}
|
||||
|
||||
collection->updateConnectedEditors();
|
||||
collection->curvesAddedOrRemoved.send();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -39,6 +39,9 @@ class RimSummaryCurveCollection : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
caf::Signal<> curvesAddedOrRemoved;
|
||||
|
||||
public:
|
||||
RimSummaryCurveCollection();
|
||||
~RimSummaryCurveCollection() override;
|
||||
@@ -53,7 +56,9 @@ public:
|
||||
RimSummaryCurve* findRimCurveFromQwtCurve( const QwtPlotCurve* qwtCurve ) const;
|
||||
|
||||
void addCurve( RimSummaryCurve* curve );
|
||||
void insertCurve( RimSummaryCurve* curve, size_t index );
|
||||
void deleteCurve( RimSummaryCurve* curve );
|
||||
void removeCurve( RimSummaryCurve* curve );
|
||||
|
||||
std::vector<RimSummaryCurve*> curves() const;
|
||||
std::vector<RimSummaryCurve*>
|
||||
@@ -75,6 +80,11 @@ public:
|
||||
RimSummaryPlotSourceStepping*
|
||||
sourceSteppingObject( RimSummaryPlotSourceStepping::SourceSteppingType sourceSteppingType ) const;
|
||||
|
||||
static void moveCurvesToCollection( RimSummaryCurveCollection* collection,
|
||||
const std::vector<RimSummaryCurve*> curves,
|
||||
RimSummaryCurve* curveToInsertBeforeOrAfter,
|
||||
bool isSwapOperation );
|
||||
|
||||
private:
|
||||
caf::PdmFieldHandle* objectToggleField() override;
|
||||
void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
|
||||
|
||||
@@ -163,6 +163,7 @@ RimSummaryPlot::RimSummaryPlot()
|
||||
CAF_PDM_InitFieldNoDefault( &m_summaryCurveCollection, "SummaryCurveCollection", "", "", "", "" );
|
||||
m_summaryCurveCollection.uiCapability()->setUiTreeHidden( true );
|
||||
m_summaryCurveCollection = new RimSummaryCurveCollection;
|
||||
m_summaryCurveCollection->curvesAddedOrRemoved.connect( this, &RimSummaryPlot::onCurvesAddedOrRemoved );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_ensembleCurveSetCollection, "EnsembleCurveSetCollection", "", "", "", "" );
|
||||
m_ensembleCurveSetCollection.uiCapability()->setUiTreeHidden( true );
|
||||
@@ -2096,6 +2097,15 @@ void RimSummaryPlot::handleKeyPressEvent( QKeyEvent* keyEvent )
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryPlot::onCurvesAddedOrRemoved( const SignalEmitter* emitter )
|
||||
{
|
||||
loadDataAndUpdate();
|
||||
updateStackedCurveData();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -189,6 +189,8 @@ private:
|
||||
void doRemoveFromCollection() override;
|
||||
void handleKeyPressEvent( QKeyEvent* keyEvent ) override;
|
||||
|
||||
void onCurvesAddedOrRemoved( const SignalEmitter* emitter );
|
||||
|
||||
protected:
|
||||
// Overridden PDM methods
|
||||
caf::PdmFieldHandle* userDescriptionField() override;
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryCaseCollection.h"
|
||||
#include "RimSummaryCaseMainCollection.h"
|
||||
#include "RimSummaryCurve.h"
|
||||
#include "RimSummaryCurveCollection.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
#include "RimWellAllocationPlot.h"
|
||||
#include "RimWellLogCurve.h"
|
||||
#include "RimWellLogFileChannel.h"
|
||||
@@ -163,7 +166,7 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
|
||||
|
||||
if ( dynamic_cast<RimEclipseCase*>( uiItem ) || dynamic_cast<RimWellLogCurve*>( uiItem ) ||
|
||||
dynamic_cast<RimWellLogFileChannel*>( uiItem ) || dynamic_cast<RimPlot*>( uiItem ) ||
|
||||
dynamic_cast<RimSummaryCase*>( uiItem ) )
|
||||
dynamic_cast<RimSummaryCase*>( uiItem ) || dynamic_cast<RimSummaryCurve*>( uiItem ) )
|
||||
{
|
||||
// TODO: Remember to handle reservoir holding the main grid
|
||||
itemflags |= Qt::ItemIsDragEnabled;
|
||||
@@ -213,6 +216,13 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
|
||||
itemflags |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
}
|
||||
else if ( dynamic_cast<RimSummaryCurve*>( uiItem ) || dynamic_cast<RimSummaryPlot*>( uiItem ) )
|
||||
{
|
||||
if ( RiuTypedPdmObjects<RimSummaryCurve>::containsTypedObjects( m_dragItems ) )
|
||||
{
|
||||
itemflags |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
}
|
||||
else if ( dynamic_cast<RimPlot*>( uiItem ) )
|
||||
{
|
||||
if ( RiuTypedPdmObjects<RimPlot>::containsTypedObjects( m_dragItems ) )
|
||||
@@ -342,6 +352,23 @@ bool RiuDragDrop::dropMimeData( const QMimeData* data, Qt::DropAction action, in
|
||||
isSwapOperation( myMimeData->indexes(), parent ) );
|
||||
}
|
||||
|
||||
RimSummaryCurve* summaryCurve;
|
||||
dropTarget->firstAncestorOrThisOfType( summaryCurve );
|
||||
if ( summaryCurve )
|
||||
{
|
||||
return handleSummaryCurveDrop( action,
|
||||
draggedObjects,
|
||||
summaryCurve,
|
||||
isSwapOperation( myMimeData->indexes(), parent ) );
|
||||
}
|
||||
|
||||
RimSummaryPlot* summaryPlot;
|
||||
dropTarget->firstAncestorOrThisOfType( summaryPlot );
|
||||
if ( summaryPlot )
|
||||
{
|
||||
return handleSummaryPlotDrop( action, draggedObjects, summaryPlot );
|
||||
}
|
||||
|
||||
RimMultiPlot* multiPlot;
|
||||
dropTarget->firstAncestorOrThisOfType( multiPlot );
|
||||
if ( multiPlot )
|
||||
@@ -519,14 +546,36 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop( Qt::DropAction action,
|
||||
{
|
||||
if ( action == Qt::MoveAction )
|
||||
{
|
||||
RimWellLogCurve* insertAfter = nullptr;
|
||||
if ( insertAtPosition > 0 )
|
||||
RimWellLogCurve* insertAfter = nullptr;
|
||||
auto visibleCurves = trackTarget->visibleCurves();
|
||||
if ( !visibleCurves.empty() )
|
||||
{
|
||||
auto visibleCurves = trackTarget->visibleCurves();
|
||||
if ( !visibleCurves.empty() )
|
||||
if ( insertAtPosition == -1 )
|
||||
{
|
||||
int insertAfterPosition = std::min( insertAtPosition - 1, (int)visibleCurves.size() - 1 );
|
||||
insertAfter = visibleCurves[insertAfterPosition];
|
||||
// If we are moving any curves to a new track, the curves should be appended
|
||||
// but insertAtPosition will be -1.
|
||||
std::set<RimWellLogTrack*> currentParentTracks;
|
||||
for ( auto curve : wellLogPlotCurves )
|
||||
{
|
||||
RimWellLogTrack* track;
|
||||
curve->firstAncestorOrThisOfTypeAsserted( track );
|
||||
currentParentTracks.insert( track );
|
||||
}
|
||||
bool allMovedWithinSameTrack = currentParentTracks.size() > 1 ||
|
||||
!currentParentTracks.count( trackTarget );
|
||||
if ( !allMovedWithinSameTrack )
|
||||
{
|
||||
insertAtPosition = (int)visibleCurves.size() - 1;
|
||||
}
|
||||
}
|
||||
if ( insertAtPosition > 0 )
|
||||
{
|
||||
auto visibleCurves = trackTarget->visibleCurves();
|
||||
if ( !visibleCurves.empty() )
|
||||
{
|
||||
int insertAfterPosition = std::min( insertAtPosition - 1, (int)visibleCurves.size() - 1 );
|
||||
insertAfter = visibleCurves[insertAfterPosition];
|
||||
}
|
||||
}
|
||||
}
|
||||
RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( trackTarget,
|
||||
@@ -545,7 +594,7 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop( Qt::DropAction action,
|
||||
{
|
||||
RimWellLogPlot* wellLogPlot;
|
||||
trackTarget->firstAncestorOrThisOfType( wellLogPlot );
|
||||
return handleWellLogPlotDrop( action, draggedObjects, wellLogPlot, insertAtPosition );
|
||||
return handleWellLogPlotDrop( action, draggedObjects, wellLogPlot, insertAtPosition, isSwapOperation );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,6 +637,52 @@ bool RiuDragDrop::handleWellLogPlotDrop( Qt::DropAction action,
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuDragDrop::handleSummaryCurveDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimSummaryCurve* summaryCurveTarget,
|
||||
bool isSwapOperation )
|
||||
{
|
||||
std::vector<RimSummaryCurve*> summaryCurves = RiuTypedPdmObjects<RimSummaryCurve>::typedObjectsFromGroup( objectGroup );
|
||||
if ( summaryCurves.size() > 0 )
|
||||
{
|
||||
if ( action == Qt::MoveAction )
|
||||
{
|
||||
RimSummaryCurveCollection* summaryCurveCollection;
|
||||
summaryCurveTarget->firstAncestorOrThisOfType( summaryCurveCollection );
|
||||
|
||||
RimSummaryCurveCollection::moveCurvesToCollection( summaryCurveCollection,
|
||||
summaryCurves,
|
||||
summaryCurveTarget,
|
||||
isSwapOperation );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuDragDrop::handleSummaryPlotDrop( Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimSummaryPlot* summaryPlot )
|
||||
{
|
||||
std::vector<RimSummaryCurve*> summaryCurves = RiuTypedPdmObjects<RimSummaryCurve>::typedObjectsFromGroup( objectGroup );
|
||||
if ( summaryCurves.size() > 0 )
|
||||
{
|
||||
if ( action == Qt::MoveAction )
|
||||
{
|
||||
RimSummaryCurveCollection::moveCurvesToCollection( summaryPlot->summaryCurveCollection(),
|
||||
summaryCurves,
|
||||
nullptr,
|
||||
false );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -33,6 +33,8 @@ class RimMultiPlot;
|
||||
class RimIdenticalGridCaseGroup;
|
||||
class RimSummaryCaseCollection;
|
||||
class RimSummaryCaseMainCollection;
|
||||
class RimSummaryCurve;
|
||||
class RimSummaryPlot;
|
||||
class RimWellLogPlot;
|
||||
class RimWellLogTrack;
|
||||
class RimWellLogCurve;
|
||||
@@ -61,6 +63,12 @@ private:
|
||||
bool handleGridCaseGroupDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimIdenticalGridCaseGroup* gridCaseGroup );
|
||||
|
||||
bool handleWellLogPlotCurveDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimWellLogCurve* wellLogPlotCurve,
|
||||
bool isSwapOperation = false );
|
||||
|
||||
bool handleWellLogPlotTrackDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimWellLogTrack* wellLogPlotTrack,
|
||||
@@ -73,14 +81,17 @@ private:
|
||||
int insertAtPosition,
|
||||
bool isSwapOperation = false );
|
||||
|
||||
bool handleSummaryCurveDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimSummaryCurve* summaryCurveTarget,
|
||||
bool isSwapOperation = false );
|
||||
|
||||
bool handleSummaryPlotDrop( Qt::DropAction action, caf::PdmObjectGroup& objectGroup, RimSummaryPlot* summaryPlot );
|
||||
|
||||
bool handleMultiPlotDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimMultiPlot* multiPlot,
|
||||
int insertAtPosition );
|
||||
bool handleWellLogPlotCurveDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimWellLogCurve* wellLogPlotCurve,
|
||||
bool isSwapOperation = false );
|
||||
bool handleSummaryCaseCollectionDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimSummaryCaseCollection* summaryCaseCollection );
|
||||
|
||||
Reference in New Issue
Block a user