Refactors selection handling for improved code clarity

Modernize the interface to selection system. Create and return data instead of populating incoming parameters.
This commit is contained in:
Magne Sjaastad committed 2025-04-09 07:21:54 +02:00
1 parent 380f559f0d
commit ae8446073b
136 files changed
+357 -870

No files matched your search

@@ -34,9 +34,7 @@ CAF_CMD_SOURCE_INIT( Ric3dWellLogCurveDeleteFeature, "Ric3dWellLogCurveDeleteFea
//--------------------------------------------------------------------------------------------------
bool Ric3dWellLogCurveDeleteFeature::isCommandEnabled() const
{
std::vector<Rim3dWellLogCurve*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
auto objects = caf::SelectionManager::instance()->objectsByType<Rim3dWellLogCurve>();
return !objects.empty();
}
@@ -45,9 +43,7 @@ bool Ric3dWellLogCurveDeleteFeature::isCommandEnabled() const
//--------------------------------------------------------------------------------------------------
void Ric3dWellLogCurveDeleteFeature::onActionTriggered( bool isChecked )
{
std::vector<Rim3dWellLogCurve*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
auto objects = caf::SelectionManager::instance()->objectsByType<Rim3dWellLogCurve>();
if ( objects.empty() ) return;
Rim3dWellLogCurve* firstCurve = objects[0];
@@ -118,7 +118,5 @@ void RicAddWellLogToPlotFeature::setupActionLook( QAction* actionToSetup )
//--------------------------------------------------------------------------------------------------
std::vector<RimWellLogChannel*> RicAddWellLogToPlotFeature::selectedWellLogs()
{
std::vector<RimWellLogChannel*> selection;
caf::SelectionManager::instance()->objectsByType( &selection );
return selection;
return caf::SelectionManager::instance()->objectsByType<RimWellLogChannel>();
}
@@ -46,9 +46,8 @@ void RicAsciiExportWellLogPlotFeature::onActionTriggered( bool isChecked )
{
disableModelChangeContribution();
std::vector<RimWellLogPlot*> selectedWellLogPlots;
caf::SelectionManager::instance()->objectsByType( &selectedWellLogPlots );
QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallbackToProjectFolder( "PLOT_ASCIIEXPORT_DIR" );
auto selectedWellLogPlots = caf::SelectionManager::instance()->objectsByType<RimWellLogPlot>();
QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallbackToProjectFolder( "PLOT_ASCIIEXPORT_DIR" );
caf::ProgressInfo pi( selectedWellLogPlots.size(), QString( "Exporting plot data to ASCII" ) );
size_t progress = 0;
@@ -57,8 +57,7 @@ bool RicChangeDataSourceFeature::isCommandEnabled() const
//--------------------------------------------------------------------------------------------------
void RicChangeDataSourceFeature::onActionTriggered( bool isChecked )
{
std::vector<caf::PdmObject*> selectedObjects;
caf::SelectionManager::instance()->objectsByType( &selectedObjects );
const auto selectedObjects = caf::SelectionManager::instance()->objectsByType<caf::PdmObject>();
std::vector<RimWellLogCurve*> curves;
std::vector<RimWellLogTrack*> tracks;
@@ -92,9 +91,8 @@ void RicChangeDataSourceFeature::setupActionLook( QAction* actionToSetup )
bool RicChangeDataSourceFeature::selectedTracksAndCurves( std::vector<RimWellLogCurve*>* curves, std::vector<RimWellLogTrack*>* tracks )
{
CVF_ASSERT( curves && tracks );
std::vector<caf::PdmObject*> selectedObjects;
caf::SelectionManager::instance()->objectsByType( &selectedObjects );
const auto selectedObjects = caf::SelectionManager::instance()->objectsByType<caf::PdmObject>();
if ( selectedObjects.empty() ) return false;
for ( caf::PdmObject* selectedObject : selectedObjects )
@@ -54,8 +54,7 @@ void RicDeleteSubPlotFeature::onActionTriggered( bool isChecked )
{
if ( RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot() ) return;
std::vector<RimPlot*> selection;
getSelection( selection );
std::vector<RimPlot*> selection = getSelection();
std::set<RimMultiPlot*> alteredPlotWindows;
@@ -98,8 +97,7 @@ void RicDeleteSubPlotFeature::onActionTriggered( bool isChecked )
void RicDeleteSubPlotFeature::setupActionLook( QAction* actionToSetup )
{
QString actionText;
std::vector<RimPlot*> selection;
getSelection( selection );
std::vector<RimPlot*> selection = getSelection();
size_t tracksSelected = 0u;
for ( RimPlot* object : selection )
@@ -130,8 +128,9 @@ void RicDeleteSubPlotFeature::setupActionLook( QAction* actionToSetup )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDeleteSubPlotFeature::getSelection( std::vector<RimPlot*>& selection ) const
std::vector<RimPlot*> RicDeleteSubPlotFeature::getSelection() const
{
std::vector<RimPlot*> selection;
if ( sender() )
{
QVariant userData = this->userData();
@@ -144,8 +143,10 @@ void RicDeleteSubPlotFeature::getSelection( std::vector<RimPlot*>& selection ) c
if ( selection.empty() )
{
caf::SelectionManager::instance()->objectsByType( &selection );
selection = caf::SelectionManager::instance()->objectsByType<RimPlot>();
}
return selection;
}
//--------------------------------------------------------------------------------------------------
@@ -153,10 +154,7 @@ void RicDeleteSubPlotFeature::getSelection( std::vector<RimPlot*>& selection ) c
//--------------------------------------------------------------------------------------------------
bool RicDeleteSubPlotFeature::isAnyDeletablePlotSelected() const
{
std::vector<RimPlot*> selection;
getSelection( selection );
for ( RimPlot* plot : selection )
for ( RimPlot* plot : getSelection() )
{
if ( !plot ) continue;
@@ -38,6 +38,6 @@ protected:
void setupActionLook( QAction* actionToSetup ) override;
private:
void getSelection( std::vector<RimPlot*>& selection ) const;
bool isAnyDeletablePlotSelected() const;
std::vector<RimPlot*> getSelection() const;
bool isAnyDeletablePlotSelected() const;
};
@@ -167,10 +167,9 @@ RimSimWellInView* RicNewPltPlotFeature::selectedSimulationWell( int* branchIndex
}
else
{
std::vector<RimSimWellInView*> selection;
caf::SelectionManager::instance()->objectsByType( &selection );
( *branchIndex ) = 0;
return !selection.empty() ? selection[0] : nullptr;
return caf::SelectionManager::instance()->selectedItemOfType<RimSimWellInView>();
}
}
@@ -40,8 +40,7 @@ CAF_CMD_SOURCE_INIT( RicNewWellLogCalculatedCurveFeature, "RicNewWellLogCalculat
//--------------------------------------------------------------------------------------------------
bool RicNewWellLogCalculatedCurveFeature::isCommandEnabled() const
{
std::vector<RimWellLogCurve*> wellLogCurves;
caf::SelectionManager::instance()->objectsByType( &wellLogCurves );
const auto wellLogCurves = caf::SelectionManager::instance()->objectsByType<RimWellLogCurve>();
return ( caf::SelectionManager::instance()->selectedItemOfType<RimWellLogTrack>() != nullptr || wellLogCurves.size() == 2 );
}
@@ -58,8 +57,7 @@ void RicNewWellLogCalculatedCurveFeature::onActionTriggered( bool isChecked )
}
else
{
std::vector<RimWellLogCurve*> wellLogCurves;
caf::SelectionManager::instance()->objectsByType( &wellLogCurves );
const auto wellLogCurves = caf::SelectionManager::instance()->objectsByType<RimWellLogCurve>();
if ( wellLogCurves.size() != 2 ) return;
RimWellLogTrack* wellLogTrack = wellLogCurves[0]->firstAncestorOrThisOfType<RimWellLogTrack>();
@@ -82,7 +82,5 @@ void RicNewWellLogPlotTrackFeature::setupActionLook( QAction* actionToSetup )
//--------------------------------------------------------------------------------------------------
RimWellLogPlot* RicNewWellLogPlotTrackFeature::selectedWellLogPlot()
{
std::vector<RimWellLogPlot*> selection;
caf::SelectionManager::instance()->objectsByType( &selection );
return !selection.empty() ? selection[0] : nullptr;
return caf::SelectionManager::instance()->selectedItemOfType<RimWellLogPlot>();
}
@@ -51,9 +51,7 @@ std::vector<RimWellLogCurve*> RicWellLogPlotCurveFeatureImpl::selectedWellLogCur
std::set<RimWellLogCurve*> uniqueCurves;
{
std::vector<caf::PdmUiItem*> selectedItems;
caf::SelectionManager::instance()->selectedItems( selectedItems );
const auto selectedItems = caf::SelectionManager::instance()->selectedItems();
for ( caf::PdmUiItem* selectedItem : selectedItems )
{
caf::PdmObjectHandle* objHandle = dynamic_cast<caf::PdmObjectHandle*>( selectedItem );