Disallow dropping curves onto other curves

* Dropping curves between other curves works much better with this change.
This commit is contained in:
Gaute Lindkvist 2020-08-13 12:00:53 +02:00
parent fee1608cda
commit 6bcf1b56fe
6 changed files with 85 additions and 239 deletions

View File

@ -35,10 +35,8 @@
//--------------------------------------------------------------------------------------------------
void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( RimWellLogTrack* destTrack,
const std::vector<RimWellLogCurve*>& curves,
RimWellLogCurve* curveToInsertBeforeOrAfter,
int insertAtPosition )
int insertAtPosition )
{
CVF_ASSERT( insertAtPosition >= 0 );
CVF_ASSERT( destTrack );
std::set<RimWellLogTrack*> srcTracks;
@ -62,8 +60,15 @@ void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( RimWellLogTra
for ( size_t cIdx = 0; cIdx < curves.size(); cIdx++ )
{
size_t position = (size_t)insertAtPosition + cIdx;
destTrack->insertCurve( curves[cIdx], position );
if ( insertAtPosition >= 0 )
{
size_t position = (size_t)insertAtPosition + cIdx;
destTrack->insertCurve( curves[cIdx], position );
}
else
{
destTrack->addCurve( curves[cIdx] );
}
}
for ( auto track : srcTracks )
@ -91,8 +96,7 @@ void RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( RimWellLogTra
//--------------------------------------------------------------------------------------------------
void RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot( RimWellLogPlot* wellLogPlot,
const std::vector<RimWellLogTrack*>& tracksToMove,
RimWellLogTrack* trackToInsertBeforeOrAfter,
bool isSwapOperation )
int insertAtPosition )
{
CVF_ASSERT( wellLogPlot );
@ -108,15 +112,15 @@ void RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot( RimWellLogPlot*
}
}
size_t insertionStartIndex = 0;
if ( trackToInsertBeforeOrAfter )
{
insertionStartIndex = wellLogPlot->plotIndex( trackToInsertBeforeOrAfter );
if ( !isSwapOperation ) insertionStartIndex += 1;
}
for ( size_t tIdx = 0; tIdx < tracksToMove.size(); tIdx++ )
{
wellLogPlot->insertPlot( tracksToMove[tIdx], insertionStartIndex + tIdx );
if ( insertAtPosition >= 0 )
{
wellLogPlot->insertPlot( tracksToMove[tIdx], (size_t)insertAtPosition + tIdx );
}
else
{
wellLogPlot->addPlot( tracksToMove[tIdx] );
}
}
}

View File

@ -33,10 +33,8 @@ class RicWellLogPlotTrackFeatureImpl
public:
static void moveCurvesToWellLogPlotTrack( RimWellLogTrack* dstTrack,
const std::vector<RimWellLogCurve*>& curves,
RimWellLogCurve* curveToInsertBeforeOrAfter,
int insertAtPosition );
static void moveTracksToWellLogPlot( RimWellLogPlot* wellLogPlot,
const std::vector<RimWellLogTrack*>& tracks,
RimWellLogTrack* trackToInsertBeforeOrAfter,
bool isSwapOperation );
int insertAtPosition );
};

View File

@ -229,7 +229,7 @@ void RimMultiPlot::removePlot( RimPlot* plot )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimMultiPlot::movePlotsToThis( const std::vector<RimPlot*>& plotsToMove, RimPlot* plotToInsertAfter )
void RimMultiPlot::movePlotsToThis( const std::vector<RimPlot*>& plotsToMove, int insertAtPosition )
{
for ( size_t tIdx = 0; tIdx < plotsToMove.size(); tIdx++ )
{
@ -245,12 +245,16 @@ void RimMultiPlot::movePlotsToThis( const std::vector<RimPlot*>& plotsToMove, Ri
}
}
size_t insertionStartIndex = 0;
if ( plotToInsertAfter ) insertionStartIndex = this->plotIndex( plotToInsertAfter ) + 1;
for ( size_t tIdx = 0; tIdx < plotsToMove.size(); tIdx++ )
{
this->insertPlot( plotsToMove[tIdx], insertionStartIndex + tIdx );
if ( insertAtPosition >= 0 )
{
this->insertPlot( plotsToMove[tIdx], (size_t)insertAtPosition + tIdx );
}
else
{
this->addPlot( plotsToMove[tIdx] );
}
}
this->updateLayout();

View File

@ -72,7 +72,7 @@ public:
void addPlot( RimPlot* plot );
void insertPlot( RimPlot* plot, size_t index );
void removePlot( RimPlot* plot );
void movePlotsToThis( const std::vector<RimPlot*>& plots, RimPlot* plotToInsertAfter );
void movePlotsToThis( const std::vector<RimPlot*>& plots, int insertAtPosition );
size_t plotCount() const;
size_t plotIndex( const RimPlot* plot ) const;

View File

@ -118,6 +118,18 @@ public:
return typedObjectsGetter.typedObjects().size() > 0;
}
static std::vector<T*> typedAncestorsFromGroup( const caf::PdmObjectGroup& objectGroup )
{
RiuTypedPdmObjects<T> typedObjectsGetter( objectGroup );
return typedObjectsGetter.typedAncestors();
}
static std::vector<T*> typedAncestorsFromGroup( const std::vector<caf::PdmPointer<caf::PdmObjectHandle>>& objectHandles )
{
RiuTypedPdmObjects<T> typedObjectsGetter( objectHandles );
return typedObjectsGetter.typedAncestors();
}
private:
std::vector<T*> typedObjects()
{
@ -134,6 +146,22 @@ private:
return typedObjectsVec;
}
std::vector<T*> typedAncestors()
{
std::vector<T*> typedAncestorsVec;
for ( size_t i = 0; i < m_objects.size(); i++ )
{
T* typedAncestor = nullptr;
m_objects[i]->firstAncestorOfType( typedAncestor );
if ( typedAncestor )
{
typedAncestorsVec.push_back( typedAncestor );
}
}
return typedAncestorsVec;
}
private:
std::vector<caf::PdmPointer<caf::PdmObject>> m_objects;
};
@ -203,7 +231,7 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
if ( m_dragItems.empty() ) return itemflags;
if ( dynamic_cast<RimEclipseCase*>( uiItem ) || dynamic_cast<RimCaseCollection*>( uiItem ) )
if ( dynamic_cast<RimCaseCollection*>( uiItem ) )
{
if ( RiuTypedPdmObjects<RimEclipseCase>::containsTypedObjects( m_dragItems ) )
{
@ -216,7 +244,14 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
{
if ( RiuTypedPdmObjects<RimWellLogTrack>::containsTypedObjects( m_dragItems ) )
{
itemflags |= Qt::ItemIsDropEnabled;
auto plotParents = RiuTypedPdmObjects<RimWellLogPlot>::typedAncestorsFromGroup( m_dragItems );
bool draggedOntoSameParent = index.row() == -1 && plotParents.size() == 1u &&
plotParents.front() == uiItem;
if ( !draggedOntoSameParent )
{
itemflags |= Qt::ItemIsDropEnabled;
}
}
}
else if ( dynamic_cast<RimMultiPlot*>( uiItem ) )
@ -231,42 +266,23 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
{
if ( RiuTypedPdmObjects<RimWellLogCurve>::containsTypedObjects( m_dragItems ) )
{
itemflags |= Qt::ItemIsDropEnabled;
}
else if ( RiuTypedPdmObjects<RimWellLogTrack>::containsTypedObjects( m_dragItems ) )
{
itemflags |= Qt::ItemIsDropEnabled;
auto trackParents = RiuTypedPdmObjects<RimWellLogTrack>::typedAncestorsFromGroup( m_dragItems );
bool draggedOntoSameParent = index.row() == -1 && trackParents.size() == 1u &&
trackParents.front() == uiItem;
if ( !draggedOntoSameParent )
{
itemflags |= Qt::ItemIsDropEnabled;
}
}
}
else if ( dynamic_cast<RimWellLogCurve*>( uiItem ) )
{
if ( RiuTypedPdmObjects<RimWellLogCurve>::containsTypedObjects( m_dragItems ) )
{
itemflags |= Qt::ItemIsDropEnabled;
}
}
else if ( dynamic_cast<RimSummaryCurve*>( uiItem ) || dynamic_cast<RimSummaryPlot*>( uiItem ) ||
dynamic_cast<RimSummaryCurveCollection*>( uiItem ) )
else if ( dynamic_cast<RimSummaryPlot*>( uiItem ) || dynamic_cast<RimSummaryCurveCollection*>( uiItem ) )
{
if ( RiuTypedPdmObjects<RimSummaryCurve>::containsTypedObjects( m_dragItems ) )
{
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 ) )
{
itemflags |= Qt::ItemIsDropEnabled;
}
}
else if ( dynamic_cast<RimSummaryCaseCollection*>( uiItem ) )
{
if ( RiuTypedPdmObjects<RimSummaryCase>::containsTypedObjects( m_dragItems ) )
@ -304,22 +320,6 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
return itemflags;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuDragDrop::isSwapOperation( int targetRow, const QModelIndexList& dragIndices, const QModelIndex& dropTargetIndex )
{
if ( dragIndices.size() == 1u && targetRow == -1 ) // targetRow >= 0 means a drop between two other rows.
{
QModelIndex dragIndex = dragIndices.front();
bool sharesParent = dropTargetIndex.parent() == dragIndex.parent();
bool targetIsJustAboveOrBelow = dropTargetIndex.row() >= 0 && dragIndex.row() >= 0 &&
std::abs( dragIndex.row() - dropTargetIndex.row() ) == 1;
return sharesParent && targetIsJustAboveOrBelow;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -356,48 +356,18 @@ bool RiuDragDrop::dropMimeData( const QMimeData* data, Qt::DropAction action, in
return handleGridCaseGroupDrop( action, draggedObjects, gridCaseGroup );
}
RimWellLogCurve* wellLogPlotCurve;
dropTarget->firstAncestorOrThisOfType( wellLogPlotCurve );
if ( wellLogPlotCurve )
{
return handleWellLogPlotCurveDrop( action,
draggedObjects,
wellLogPlotCurve,
row,
isSwapOperation( row, myMimeData->indexes(), dropTargetIndex ) );
}
RimWellLogTrack* wellLogPlotTrack;
dropTarget->firstAncestorOrThisOfType( wellLogPlotTrack );
if ( wellLogPlotTrack )
{
return handleWellLogPlotTrackDrop( action,
draggedObjects,
wellLogPlotTrack,
row,
isSwapOperation( row, myMimeData->indexes(), dropTargetIndex ) );
return handleWellLogPlotTrackDrop( action, draggedObjects, wellLogPlotTrack, row );
}
RimWellLogPlot* wellLogPlot;
dropTarget->firstAncestorOrThisOfType( wellLogPlot );
if ( wellLogPlot )
{
return handleWellLogPlotDrop( action,
draggedObjects,
wellLogPlot,
row,
isSwapOperation( row, myMimeData->indexes(), dropTargetIndex ) );
}
RimSummaryCurve* summaryCurve;
dropTarget->firstAncestorOrThisOfType( summaryCurve );
if ( summaryCurve )
{
return handleSummaryCurveDrop( action,
draggedObjects,
summaryCurve,
row,
isSwapOperation( row, myMimeData->indexes(), dropTargetIndex ) );
return handleWellLogPlotDrop( action, draggedObjects, wellLogPlot, row );
}
RimSummaryPlot* summaryPlot;
@ -512,52 +482,7 @@ bool RiuDragDrop::handleMultiPlotDrop( Qt::DropAction action,
{
if ( action == Qt::MoveAction )
{
RimPlot* insertAfter = nullptr;
if ( insertAtPosition > 0 )
{
auto visibleTracks = multiPlot->visiblePlots();
if ( !visibleTracks.empty() )
{
int insertAfterPosition = std::min( insertAtPosition - 1, (int)visibleTracks.size() - 1 );
insertAfter = dynamic_cast<RimPlot*>( visibleTracks[insertAfterPosition] );
}
}
multiPlot->movePlotsToThis( plots, insertAfter );
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuDragDrop::handleWellLogPlotCurveDrop( Qt::DropAction action,
caf::PdmObjectGroup& draggedObjects,
RimWellLogCurve* curveDropTarget,
int insertAtPosition,
bool isSwapOperation )
{
std::vector<RimWellLogCurve*> wellLogPlotCurves =
RiuTypedPdmObjects<RimWellLogCurve>::typedObjectsFromGroup( draggedObjects );
if ( wellLogPlotCurves.size() > 0 )
{
if ( action == Qt::MoveAction )
{
RimWellLogTrack* wellLogPlotTrack;
curveDropTarget->firstAncestorOrThisOfTypeAsserted( wellLogPlotTrack );
if ( insertAtPosition == -1 )
{
insertAtPosition = (int)wellLogPlotTrack->curveIndex( curveDropTarget );
if ( !isSwapOperation ) insertAtPosition += 1;
}
RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( wellLogPlotTrack,
wellLogPlotCurves,
curveDropTarget,
insertAtPosition );
multiPlot->movePlotsToThis( plots, insertAtPosition );
return true;
}
}
@ -571,8 +496,7 @@ bool RiuDragDrop::handleWellLogPlotCurveDrop( Qt::DropAction action,
bool RiuDragDrop::handleWellLogPlotTrackDrop( Qt::DropAction action,
caf::PdmObjectGroup& draggedObjects,
RimWellLogTrack* trackTarget,
int insertAtPosition,
bool isSwapOperation )
int insertAtPosition )
{
std::vector<RimWellLogFileChannel*> wellLogFileChannels =
RiuTypedPdmObjects<RimWellLogFileChannel>::typedObjectsFromGroup( draggedObjects );
@ -591,38 +515,11 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop( Qt::DropAction action,
{
if ( action == Qt::MoveAction )
{
RimWellLogCurve* insertBeforeOrAfter = nullptr;
auto visibleCurves = trackTarget->visibleCurves();
if ( insertAtPosition == -1 )
{
insertAtPosition = (int)visibleCurves.size();
if ( !visibleCurves.empty() ) insertBeforeOrAfter = visibleCurves.back();
}
else if ( insertAtPosition < (int)visibleCurves.size() )
{
insertBeforeOrAfter = visibleCurves[insertAtPosition];
}
RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( trackTarget,
wellLogPlotCurves,
insertBeforeOrAfter,
insertAtPosition );
RicWellLogPlotTrackFeatureImpl::moveCurvesToWellLogPlotTrack( trackTarget, wellLogPlotCurves, insertAtPosition );
return true;
}
}
std::vector<RimWellLogTrack*> wellLogPlotTracks =
RiuTypedPdmObjects<RimWellLogTrack>::typedObjectsFromGroup( draggedObjects );
if ( wellLogPlotTracks.size() > 0 )
{
if ( action == Qt::MoveAction )
{
RimWellLogPlot* wellLogPlot;
trackTarget->firstAncestorOrThisOfType( wellLogPlot );
return handleWellLogPlotDrop( action, draggedObjects, wellLogPlot, insertAtPosition, isSwapOperation );
}
}
return false;
}
@ -632,8 +529,7 @@ bool RiuDragDrop::handleWellLogPlotTrackDrop( Qt::DropAction action,
bool RiuDragDrop::handleWellLogPlotDrop( Qt::DropAction action,
caf::PdmObjectGroup& draggedObjects,
RimWellLogPlot* wellLogPlotTarget,
int insertAtPosition,
bool isSwapOperation )
int insertAtPosition )
{
std::vector<RimWellLogTrack*> wellLogPlotTracks =
RiuTypedPdmObjects<RimWellLogTrack>::typedObjectsFromGroup( draggedObjects );
@ -641,20 +537,7 @@ bool RiuDragDrop::handleWellLogPlotDrop( Qt::DropAction action,
{
if ( action == Qt::MoveAction )
{
RimWellLogTrack* insertAfter = nullptr;
if ( insertAtPosition > 0 )
{
auto visibleTracks = wellLogPlotTarget->visiblePlots();
if ( !visibleTracks.empty() )
{
int insertAfterPosition = std::min( insertAtPosition - 1, (int)visibleTracks.size() - 1 );
insertAfter = dynamic_cast<RimWellLogTrack*>( visibleTracks[insertAfterPosition] );
}
}
RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot( wellLogPlotTarget,
wellLogPlotTracks,
insertAfter,
isSwapOperation );
RicWellLogPlotTrackFeatureImpl::moveTracksToWellLogPlot( wellLogPlotTarget, wellLogPlotTracks, insertAtPosition );
return true;
}
}
@ -662,34 +545,6 @@ bool RiuDragDrop::handleWellLogPlotDrop( Qt::DropAction action,
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuDragDrop::handleSummaryCurveDrop( Qt::DropAction action,
caf::PdmObjectGroup& objectGroup,
RimSummaryCurve* summaryCurveTarget,
int insertAtPosition,
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,
insertAtPosition,
isSwapOperation );
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -64,29 +64,15 @@ private:
caf::PdmObjectGroup& objectGroup,
RimIdenticalGridCaseGroup* gridCaseGroup );
bool handleWellLogPlotCurveDrop( Qt::DropAction action,
caf::PdmObjectGroup& objectGroup,
RimWellLogCurve* wellLogPlotCurve,
int insertAtPosition,
bool isSwapOperation = false );
bool handleWellLogPlotTrackDrop( Qt::DropAction action,
caf::PdmObjectGroup& objectGroup,
RimWellLogTrack* wellLogPlotTrack,
int insertAtPosition,
bool isSwapOperation = false );
int insertAtPosition );
bool handleWellLogPlotDrop( Qt::DropAction action,
caf::PdmObjectGroup& objectGroup,
RimWellLogPlot* wellLogPlot,
int insertAtPosition,
bool isSwapOperation = false );
bool handleSummaryCurveDrop( Qt::DropAction action,
caf::PdmObjectGroup& objectGroup,
RimSummaryCurve* summaryCurveTarget,
int insertAtPosition,
bool isSwapOperation = false );
int insertAtPosition );
bool handleSummaryPlotDrop( Qt::DropAction action,
caf::PdmObjectGroup& objectGroup,
@ -106,7 +92,6 @@ private:
static void objectGroupFromModelIndexes( caf::PdmObjectGroup* objectGroup, const QModelIndexList& indexes );
static std::vector<caf::PdmPointer<caf::PdmObjectHandle>> objectHandlesFromSelection();
static bool isSwapOperation( int targetRow, const QModelIndexList& dragIndices, const QModelIndex& dropTargetIndex );
private:
mutable std::vector<caf::PdmPointer<caf::PdmObjectHandle>> m_dragItems;