mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Swap well log curves with drag and drop if the target is just above the single drag item.
* Currently nothing happens in this case, because we insert the dragged item after the target. * On balance it seems more intuitive to swap the items in this particular case even if it is slightly against the regular drag operations.
This commit is contained in:
parent
1ceee51a7d
commit
5b126c3b98
@ -35,7 +35,8 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( RimWellLogTrack* destTrack,
|
||||
const std::vector<RimWellLogCurve*>& curves,
|
||||
RimWellLogCurve* curveToInsertAfter )
|
||||
RimWellLogCurve* curveToInsertBeforeOrAfter,
|
||||
bool isSwapOperation )
|
||||
{
|
||||
CVF_ASSERT( destTrack );
|
||||
|
||||
@ -52,6 +53,7 @@ void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( RimWellLogTra
|
||||
{
|
||||
wellLogPlotTrack->removeCurve( curve );
|
||||
wellLogPlotTrack->updateConnectedEditors();
|
||||
wellLogPlotTrack->updateStackedCurveData();
|
||||
srcTracks.insert( wellLogPlotTrack );
|
||||
RimWellLogPlot* plot;
|
||||
wellLogPlotTrack->firstAncestorOrThisOfType( plot );
|
||||
@ -60,7 +62,11 @@ void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( RimWellLogTra
|
||||
}
|
||||
|
||||
size_t insertionStartIndex = 0;
|
||||
if ( curveToInsertAfter ) insertionStartIndex = destTrack->curveIndex( curveToInsertAfter ) + 1;
|
||||
if ( curveToInsertBeforeOrAfter )
|
||||
{
|
||||
insertionStartIndex = destTrack->curveIndex( curveToInsertBeforeOrAfter );
|
||||
if ( !isSwapOperation ) insertionStartIndex += 1;
|
||||
}
|
||||
|
||||
for ( size_t cIdx = 0; cIdx < curves.size(); cIdx++ )
|
||||
{
|
||||
@ -79,6 +85,7 @@ void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( RimWellLogTra
|
||||
}
|
||||
|
||||
destTrack->loadDataAndUpdate();
|
||||
destTrack->updateStackedCurveData();
|
||||
destTrack->setAutoScaleXEnabled( true );
|
||||
destTrack->updateParentPlotZoom();
|
||||
destTrack->updateConnectedEditors();
|
||||
@ -89,7 +96,8 @@ void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( RimWellLogTra
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot( RimWellLogPlot* wellLogPlot,
|
||||
const std::vector<RimWellLogTrack*>& tracksToMove,
|
||||
RimWellLogTrack* insertAfterTrack )
|
||||
RimWellLogTrack* trackToInsertBeforeOrAfter,
|
||||
bool isSwapOperation )
|
||||
{
|
||||
CVF_ASSERT( wellLogPlot );
|
||||
|
||||
@ -106,7 +114,11 @@ void RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot( RimWellLogPlot*
|
||||
}
|
||||
|
||||
size_t insertionStartIndex = 0;
|
||||
if ( insertAfterTrack ) insertionStartIndex = wellLogPlot->plotIndex( insertAfterTrack ) + 1;
|
||||
if ( trackToInsertBeforeOrAfter )
|
||||
{
|
||||
insertionStartIndex = wellLogPlot->plotIndex( trackToInsertBeforeOrAfter );
|
||||
if ( !isSwapOperation ) insertionStartIndex += 1;
|
||||
}
|
||||
|
||||
for ( size_t tIdx = 0; tIdx < tracksToMove.size(); tIdx++ )
|
||||
{
|
||||
|
@ -33,8 +33,10 @@ class RicWellLogPlotTrackFeatureImpl
|
||||
public:
|
||||
static void moveCurvesToWellLogPlotTrack( RimWellLogTrack* dstTrack,
|
||||
const std::vector<RimWellLogCurve*>& curves,
|
||||
RimWellLogCurve* insertAfterCurve );
|
||||
RimWellLogCurve* curveToInsertBeforeOrAfter,
|
||||
bool isSwapOperation );
|
||||
static void moveTracksToWellLogPlot( RimWellLogPlot* wellLogPlot,
|
||||
const std::vector<RimWellLogTrack*>& tracks,
|
||||
RimWellLogTrack* trackToInsertAfter );
|
||||
RimWellLogTrack* trackToInsertBeforeOrAfter,
|
||||
bool isSwapOperation );
|
||||
};
|
||||
|
@ -169,6 +169,8 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
|
||||
itemflags |= Qt::ItemIsDragEnabled;
|
||||
}
|
||||
|
||||
if ( m_dragItems.empty() ) return itemflags;
|
||||
|
||||
if ( dynamic_cast<RimEclipseCase*>( uiItem ) || dynamic_cast<RimCaseCollection*>( uiItem ) )
|
||||
{
|
||||
if ( RiuTypedPdmObjects<RimEclipseCase>::containsTypedObjects( m_dragItems ) )
|
||||
@ -193,13 +195,6 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
|
||||
itemflags |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
}
|
||||
else if ( dynamic_cast<RimPlot*>( uiItem ) )
|
||||
{
|
||||
if ( RiuTypedPdmObjects<RimPlot>::containsTypedObjects( m_dragItems ) )
|
||||
{
|
||||
itemflags |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
}
|
||||
else if ( dynamic_cast<RimWellLogTrack*>( uiItem ) )
|
||||
{
|
||||
if ( RiuTypedPdmObjects<RimWellLogCurve>::containsTypedObjects( m_dragItems ) )
|
||||
@ -218,6 +213,13 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
|
||||
itemflags |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
}
|
||||
else if ( dynamic_cast<RimPlot*>( uiItem ) )
|
||||
{
|
||||
if ( RiuTypedPdmObjects<RimPlot>::containsTypedObjects( m_dragItems ) )
|
||||
{
|
||||
itemflags |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
}
|
||||
else if ( dynamic_cast<RimSummaryCase*>( uiItem ) )
|
||||
{
|
||||
if ( RiuTypedPdmObjects<RimSummaryCase>::containsTypedObjects( m_dragItems ) )
|
||||
@ -262,6 +264,22 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
|
||||
return itemflags;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuDragDrop::isSwapOperation( const QModelIndexList& dragIndices, const QModelIndex& dropTargetIndex )
|
||||
{
|
||||
if ( dragIndices.size() == 1u )
|
||||
{
|
||||
QModelIndex dragIndex = dragIndices.front();
|
||||
bool sharesParent = dropTargetIndex.parent() == dragIndex.parent();
|
||||
bool targetIsJustAbove = dropTargetIndex.row() >= 0 && dragIndex.row() >= 0 &&
|
||||
( dragIndex.row() - dropTargetIndex.row() ) == 1;
|
||||
return sharesParent && targetIsJustAbove;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -274,9 +292,11 @@ bool RiuDragDrop::dropMimeData( const QMimeData* data, Qt::DropAction action, in
|
||||
{
|
||||
caf::PdmObjectGroup draggedObjects;
|
||||
const MimeDataWithIndexes* myMimeData = qobject_cast<const MimeDataWithIndexes*>( data );
|
||||
|
||||
if ( myMimeData && parent.isValid() )
|
||||
{
|
||||
objectGroupFromModelIndexes( &draggedObjects, myMimeData->indexes() );
|
||||
QModelIndexList indices = myMimeData->indexes();
|
||||
objectGroupFromModelIndexes( &draggedObjects, indices );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -294,21 +314,32 @@ bool RiuDragDrop::dropMimeData( const QMimeData* data, Qt::DropAction action, in
|
||||
dropTarget->firstAncestorOrThisOfType( wellLogPlotCurve );
|
||||
if ( wellLogPlotCurve )
|
||||
{
|
||||
return handleWellLogPlotCurveDrop( action, draggedObjects, wellLogPlotCurve );
|
||||
return handleWellLogPlotCurveDrop( action,
|
||||
draggedObjects,
|
||||
wellLogPlotCurve,
|
||||
isSwapOperation( myMimeData->indexes(), parent ) );
|
||||
}
|
||||
|
||||
RimWellLogTrack* wellLogPlotTrack;
|
||||
dropTarget->firstAncestorOrThisOfType( wellLogPlotTrack );
|
||||
if ( wellLogPlotTrack )
|
||||
{
|
||||
return handleWellLogPlotTrackDrop( action, draggedObjects, wellLogPlotTrack, row );
|
||||
return handleWellLogPlotTrackDrop( action,
|
||||
draggedObjects,
|
||||
wellLogPlotTrack,
|
||||
row,
|
||||
isSwapOperation( myMimeData->indexes(), parent ) );
|
||||
}
|
||||
|
||||
RimWellLogPlot* wellLogPlot;
|
||||
dropTarget->firstAncestorOrThisOfType( wellLogPlot );
|
||||
if ( wellLogPlot )
|
||||
{
|
||||
return handleWellLogPlotDrop( action, draggedObjects, wellLogPlot, row );
|
||||
return handleWellLogPlotDrop( action,
|
||||
draggedObjects,
|
||||
wellLogPlot,
|
||||
row,
|
||||
isSwapOperation( myMimeData->indexes(), parent ) );
|
||||
}
|
||||
|
||||
RimMultiPlot* multiPlot;
|
||||
@ -439,7 +470,8 @@ bool RiuDragDrop::handleMultiPlotDrop( Qt::DropAction action,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuDragDrop::handleWellLogPlotCurveDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& draggedObjects,
|
||||
RimWellLogCurve* curveDropTarget )
|
||||
RimWellLogCurve* curveDropTarget,
|
||||
bool isSwapOperation )
|
||||
{
|
||||
std::vector<RimWellLogCurve*> wellLogPlotCurves =
|
||||
RiuTypedPdmObjects<RimWellLogCurve>::typedObjectsFromGroup( draggedObjects );
|
||||
@ -452,7 +484,8 @@ bool RiuDragDrop::handleWellLogPlotCurveDrop( Qt::DropAction action,
|
||||
|
||||
RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( wellLogPlotTrack,
|
||||
wellLogPlotCurves,
|
||||
curveDropTarget );
|
||||
curveDropTarget,
|
||||
isSwapOperation );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -466,7 +499,8 @@ bool RiuDragDrop::handleWellLogPlotCurveDrop( Qt::DropAction action,
|
||||
bool RiuDragDrop::handleWellLogPlotTrackDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& draggedObjects,
|
||||
RimWellLogTrack* trackTarget,
|
||||
int insertAtPosition )
|
||||
int insertAtPosition,
|
||||
bool isSwapOperation )
|
||||
{
|
||||
std::vector<RimWellLogFileChannel*> wellLogFileChannels =
|
||||
RiuTypedPdmObjects<RimWellLogFileChannel>::typedObjectsFromGroup( draggedObjects );
|
||||
@ -495,7 +529,10 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop( Qt::DropAction action,
|
||||
insertAfter = visibleCurves[insertAfterPosition];
|
||||
}
|
||||
}
|
||||
RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( trackTarget, wellLogPlotCurves, insertAfter );
|
||||
RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( trackTarget,
|
||||
wellLogPlotCurves,
|
||||
insertAfter,
|
||||
isSwapOperation );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -521,7 +558,8 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop( Qt::DropAction action,
|
||||
bool RiuDragDrop::handleWellLogPlotDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& draggedObjects,
|
||||
RimWellLogPlot* wellLogPlotTarget,
|
||||
int insertAtPosition )
|
||||
int insertAtPosition,
|
||||
bool isSwapOperation )
|
||||
{
|
||||
std::vector<RimWellLogTrack*> wellLogPlotTracks =
|
||||
RiuTypedPdmObjects<RimWellLogTrack>::typedObjectsFromGroup( draggedObjects );
|
||||
@ -539,7 +577,10 @@ bool RiuDragDrop::handleWellLogPlotDrop( Qt::DropAction action,
|
||||
insertAfter = dynamic_cast<RimWellLogTrack*>( visibleTracks[insertAfterPosition] );
|
||||
}
|
||||
}
|
||||
RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot( wellLogPlotTarget, wellLogPlotTracks, insertAfter );
|
||||
RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot( wellLogPlotTarget,
|
||||
wellLogPlotTracks,
|
||||
insertAfter,
|
||||
isSwapOperation );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -64,12 +64,14 @@ private:
|
||||
bool handleWellLogPlotTrackDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimWellLogTrack* wellLogPlotTrack,
|
||||
int insertAtPosition );
|
||||
int insertAtPosition,
|
||||
bool isSwapOperation = false );
|
||||
|
||||
bool handleWellLogPlotDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimWellLogPlot* wellLogPlot,
|
||||
int insertAtPosition );
|
||||
int insertAtPosition,
|
||||
bool isSwapOperation = false );
|
||||
|
||||
bool handleMultiPlotDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
@ -77,7 +79,8 @@ private:
|
||||
int insertAtPosition );
|
||||
bool handleWellLogPlotCurveDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimWellLogCurve* wellLogPlotCurve );
|
||||
RimWellLogCurve* wellLogPlotCurve,
|
||||
bool isSwapOperation = false );
|
||||
bool handleSummaryCaseCollectionDrop( Qt::DropAction action,
|
||||
caf::PdmObjectGroup& objectGroup,
|
||||
RimSummaryCaseCollection* summaryCaseCollection );
|
||||
@ -87,6 +90,7 @@ private:
|
||||
|
||||
static void objectGroupFromModelIndexes( caf::PdmObjectGroup* objectGroup, const QModelIndexList& indexes );
|
||||
static std::vector<caf::PdmPointer<caf::PdmObjectHandle>> objectHandlesFromSelection();
|
||||
static bool isSwapOperation( const QModelIndexList& dragIndices, const QModelIndex& dropTargetIndex );
|
||||
|
||||
private:
|
||||
mutable std::vector<caf::PdmPointer<caf::PdmObjectHandle>> m_dragItems;
|
||||
|
Loading…
Reference in New Issue
Block a user