mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-01 08:38:00 -06:00
Add reordering and drag/drop for summary ensembles
This commit is contained in:
1 parent
71c575ce10
commit
3727a12634
3 files changed
+35
-9
No files matched your search
@@ -109,6 +109,7 @@ RimSummaryCaseMainCollection::RimSummaryCaseMainCollection()
|
||||
caf::PdmFieldReorderCapability::addToField( &m_cases );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_ensembles, "SummaryCaseCollections", "" );
|
||||
caf::PdmFieldReorderCapability::addToField( &m_ensembles );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -214,17 +215,25 @@ void RimSummaryCaseMainCollection::removeCases( std::vector<RimSummaryCase*>& ca
|
||||
dataSourceHasChanged.send();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Lambda function to move an object in a child array field
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
auto moveObjectInChildArrayField = []( auto& childArrayField, auto* object, int destinationIndex )
|
||||
{
|
||||
auto currentIndex = childArrayField.indexOf( object );
|
||||
if ( currentIndex < childArrayField.size() )
|
||||
{
|
||||
childArrayField.erase( currentIndex );
|
||||
childArrayField.insertAt( std::min( destinationIndex, static_cast<int>( childArrayField.size() ) ), object );
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCaseMainCollection::moveCase( RimSummaryCase* summaryCase, int destinationIndex )
|
||||
{
|
||||
auto currentIndex = m_cases.indexOf( summaryCase );
|
||||
if ( currentIndex < m_cases.size() )
|
||||
{
|
||||
m_cases.erase( currentIndex );
|
||||
m_cases.insertAt( std::min( destinationIndex, (int)m_cases.size() ), summaryCase );
|
||||
}
|
||||
moveObjectInChildArrayField( m_cases, summaryCase, destinationIndex );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -264,6 +273,14 @@ RimSummaryEnsemble* RimSummaryCaseMainCollection::addEnsemble( const std::vector
|
||||
return ensemble;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryCaseMainCollection::moveEnsemble( RimSummaryEnsemble* ensemble, int destinationIndex )
|
||||
{
|
||||
moveObjectInChildArrayField( m_ensembles, ensemble, destinationIndex );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
std::function<RimSummaryEnsemble*()> allocator = defaultAllocator );
|
||||
void removeEnsemble( RimSummaryEnsemble* ensemble );
|
||||
void addEnsemble( RimSummaryEnsemble* ensemble );
|
||||
void moveEnsemble( RimSummaryEnsemble* ensemble, int destinationIndex );
|
||||
|
||||
void loadAllSummaryCaseData();
|
||||
|
||||
|
||||
@@ -325,7 +325,8 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
|
||||
}
|
||||
else if ( dynamic_cast<RimSummaryCaseMainCollection*>( uiItem ) )
|
||||
{
|
||||
if ( RiuTypedPdmObjects<RimSummaryCase>::containsTypedObjects( m_dragItems ) )
|
||||
if ( RiuTypedPdmObjects<RimSummaryCase>::containsTypedObjects( m_dragItems ) ||
|
||||
RiuTypedPdmObjects<RimSummaryEnsemble>::containsTypedObjects( m_dragItems ) )
|
||||
{
|
||||
itemflags |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
@@ -610,9 +611,9 @@ bool RiuDragDrop::handleSummaryCaseMainCollectionDrop( Qt::DropAction
|
||||
RimSummaryCaseMainCollection* summaryCaseDropTarget,
|
||||
int insertAtPosition )
|
||||
{
|
||||
std::vector<RimSummaryCase*> summaryCases = RiuTypedPdmObjects<RimSummaryCase>::typedObjectsFromGroup( draggedObjects );
|
||||
if ( action != Qt::MoveAction ) return false;
|
||||
|
||||
if ( action != Qt::MoveAction || summaryCases.empty() ) return false;
|
||||
std::vector<RimSummaryCase*> summaryCases = RiuTypedPdmObjects<RimSummaryCase>::typedObjectsFromGroup( draggedObjects );
|
||||
|
||||
for ( RimSummaryCase* summaryCase : summaryCases )
|
||||
{
|
||||
@@ -639,6 +640,13 @@ bool RiuDragDrop::handleSummaryCaseMainCollectionDrop( Qt::DropAction
|
||||
}
|
||||
}
|
||||
|
||||
auto ensembles = RiuTypedPdmObjects<RimSummaryEnsemble>::typedObjectsFromGroup( draggedObjects );
|
||||
if ( ensembles.size() == 1 )
|
||||
{
|
||||
auto ensemble = ensembles.front();
|
||||
summaryCaseDropTarget->moveEnsemble( ensemble, insertAtPosition );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user