Change API for PdmObjectHandle and PdmFieldHandle

* Refactor interface to PdmObjectHandle and PdmFieldHandle
Return objects instead of passing in structures as parameters

* Add nodiscard to several functions
* Remove redundant this->
* Rename to ptrReferencedObjectsByType
This commit is contained in:
Magne Sjaastad
2023-05-12 21:41:34 +02:00
committed by GitHub
parent 37e29a0f68
commit 0c90f67dcc
510 changed files with 1651 additions and 3111 deletions
@@ -147,8 +147,7 @@ void RiuAdvancedSnapshotExportWidget::addSnapshotItemFromActiveView()
multiSnapshot->timeStepStart = activeView->currentTimeStep();
multiSnapshot->timeStepEnd = activeView->currentTimeStep();
RimCase* sourceCase = nullptr;
activeView->firstAncestorOrThisOfType( sourceCase );
auto sourceCase = activeView->firstAncestorOrThisOfType<RimCase>();
if ( sourceCase )
{
multiSnapshot->additionalCases().push_back( sourceCase );
@@ -266,7 +266,7 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
if ( intersectionView )
{
intersectionView->intersection()->firstAncestorOrThisOfType( associatedGridView );
associatedGridView = intersectionView->intersection()->firstAncestorOrThisOfType<RimGridView>();
}
// Use the clicked views default settings if we have not found any special stuff
@@ -158,8 +158,7 @@ private:
std::vector<T*> typedAncestorsVec;
for ( size_t i = 0; i < m_objects.size(); i++ )
{
T* typedAncestor = nullptr;
m_objects[i]->firstAncestorOfType( typedAncestor );
auto typedAncestor = m_objects[i]->firstAncestorOfType<T>();
if ( typedAncestor )
{
typedAncestorsVec.push_back( typedAncestor );
@@ -246,8 +245,7 @@ Qt::ItemFlags RiuDragDrop::flags( const QModelIndex& index ) const
caf::PdmObject* pdmObj = dynamic_cast<caf::PdmObject*>( uiItem );
if ( pdmObj )
{
RimWellAllocationPlot* wellAllocationPlot = nullptr;
pdmObj->firstAncestorOrThisOfType( wellAllocationPlot );
auto wellAllocationPlot = pdmObj->firstAncestorOrThisOfType<RimWellAllocationPlot>();
if ( wellAllocationPlot ) return itemflags;
}
@@ -399,57 +397,49 @@ bool RiuDragDrop::dropMimeData( const QMimeData* data, Qt::DropAction action, in
dropTargetIndex.parent(),
RiuTypedPdmObjects<const caf::PdmUiItem>::typedObjectsFromGroup( draggedObjects ) );
RimIdenticalGridCaseGroup* gridCaseGroup;
dropTarget->firstAncestorOrThisOfType( gridCaseGroup );
auto gridCaseGroup = dropTarget->firstAncestorOrThisOfType<RimIdenticalGridCaseGroup>();
if ( gridCaseGroup )
{
return handleGridCaseGroupDrop( action, draggedObjects, gridCaseGroup );
}
RimWellLogTrack* wellLogPlotTrack;
dropTarget->firstAncestorOrThisOfType( wellLogPlotTrack );
auto wellLogPlotTrack = dropTarget->firstAncestorOrThisOfType<RimWellLogTrack>();
if ( wellLogPlotTrack )
{
return handleWellLogPlotTrackDrop( action, draggedObjects, wellLogPlotTrack, row );
}
RimWellLogPlot* wellLogPlot;
dropTarget->firstAncestorOrThisOfType( wellLogPlot );
auto wellLogPlot = dropTarget->firstAncestorOrThisOfType<RimWellLogPlot>();
if ( wellLogPlot )
{
return handleWellLogPlotDrop( action, draggedObjects, wellLogPlot, row );
}
RimSummaryPlot* summaryPlot;
dropTarget->firstAncestorOrThisOfType( summaryPlot );
auto summaryPlot = dropTarget->firstAncestorOrThisOfType<RimSummaryPlot>();
if ( summaryPlot )
{
return handleSummaryPlotDrop( action, draggedObjects, summaryPlot, row );
}
RimMultiPlot* multiPlot;
dropTarget->firstAncestorOrThisOfType( multiPlot );
auto multiPlot = dropTarget->firstAncestorOrThisOfType<RimMultiPlot>();
if ( multiPlot )
{
return handleMultiPlotDrop( action, draggedObjects, multiPlot, row );
}
RimSummaryCaseCollection* summaryCaseCollection;
dropTarget->firstAncestorOrThisOfType( summaryCaseCollection );
auto summaryCaseCollection = dropTarget->firstAncestorOrThisOfType<RimSummaryCaseCollection>();
if ( summaryCaseCollection )
{
return handleSummaryCaseCollectionDrop( action, draggedObjects, summaryCaseCollection );
}
RimSummaryCaseMainCollection* summaryCaseMainCollection;
dropTarget->firstAncestorOrThisOfType( summaryCaseMainCollection );
auto summaryCaseMainCollection = dropTarget->firstAncestorOrThisOfType<RimSummaryCaseMainCollection>();
if ( summaryCaseMainCollection )
{
return handleSummaryCaseMainCollectionDrop( action, draggedObjects, summaryCaseMainCollection );
}
RimSurfaceCollection* surfaceCollection;
dropTarget->firstAncestorOrThisOfType( surfaceCollection );
auto surfaceCollection = dropTarget->firstAncestorOrThisOfType<RimSurfaceCollection>();
if ( surfaceCollection )
{
return handleSurfaceCollectionDrop( action, row, draggedObjects, surfaceCollection );
@@ -624,8 +614,7 @@ bool RiuDragDrop::handleSummaryCaseCollectionDrop( Qt::DropAction act
for ( RimSummaryCase* summaryCase : summaryCases )
{
RimSummaryCaseCollection* summaryCaseCollection;
summaryCase->firstAncestorOrThisOfType( summaryCaseCollection );
auto summaryCaseCollection = summaryCase->firstAncestorOrThisOfType<RimSummaryCaseCollection>();
if ( summaryCaseCollection )
{
@@ -635,8 +624,7 @@ bool RiuDragDrop::handleSummaryCaseCollectionDrop( Qt::DropAction act
continue;
}
RimSummaryCaseMainCollection* summaryCaseMainCollection;
summaryCase->firstAncestorOrThisOfType( summaryCaseMainCollection );
auto summaryCaseMainCollection = summaryCase->firstAncestorOrThisOfType<RimSummaryCaseMainCollection>();
if ( summaryCaseMainCollection )
{
summaryCaseMainCollection->removeCase( summaryCase );
@@ -661,8 +649,7 @@ bool RiuDragDrop::handleSummaryCaseMainCollectionDrop( Qt::DropAction
for ( RimSummaryCase* summaryCase : summaryCases )
{
RimSummaryCaseCollection* summaryCaseCollection;
summaryCase->firstAncestorOrThisOfType( summaryCaseCollection );
auto summaryCaseCollection = summaryCase->firstAncestorOrThisOfType<RimSummaryCaseCollection>();
if ( summaryCaseCollection )
{
@@ -734,8 +721,7 @@ bool RiuDragDrop::handleSurfaceCollectionDrop( Qt::DropAction action, int row, c
for ( RimSurface* surface : surfaces )
{
RimSurfaceCollection* sourceCollection;
surface->firstAncestorOrThisOfType( sourceCollection );
auto sourceCollection = surface->firstAncestorOrThisOfType<RimSurfaceCollection>();
if ( sourceCollection )
{
@@ -237,8 +237,7 @@ bool RiuGridCrossQwtPlot::curveText( const QwtPlotCurve* curve, QString* curveTi
{
*curveTitle = crossPlotCurve->curveName();
RimGridCrossPlotDataSet* dataSet = nullptr;
crossPlotCurve->firstAncestorOrThisOfType( dataSet );
auto dataSet = crossPlotCurve->firstAncestorOrThisOfType<RimGridCrossPlotDataSet>();
if ( dataSet )
{
*xParamName = dataSet->xAxisName();
@@ -1090,8 +1090,7 @@ RimViewWindow* RiuMainWindow::findViewWindowFromSubWindow( QMdiSubWindow* subWin
{
if ( subWindow )
{
std::vector<RimViewWindow*> allViewWindows;
RimProject::current()->descendantsIncludingThisOfType( allViewWindows );
std::vector<RimViewWindow*> allViewWindows = RimProject::current()->descendantsIncludingThisOfType<RimViewWindow>();
for ( RimViewWindow* viewWindow : allViewWindows )
{
@@ -1354,9 +1353,7 @@ void RiuMainWindow::selectViewInProjectTreePreservingSubItemSelection( const Rim
if ( !is3dViewCurrentlySelected )
{
std::vector<RimEclipseCellColors*> objects;
activatedView->descendantsIncludingThisOfType( objects );
std::vector<RimEclipseCellColors*> objects = activatedView->descendantsIncludingThisOfType<RimEclipseCellColors>();
if ( !objects.empty() )
{
auto candidate = tv->findModelIndex( objects.front() );
@@ -1485,7 +1482,7 @@ void RiuMainWindow::selectedObjectsChanged()
Rim3dView* selectedReservoirView = dynamic_cast<Rim3dView*>( firstSelectedObject );
if ( !selectedReservoirView )
{
firstSelectedObject->firstAncestorOrThisOfType( selectedReservoirView );
selectedReservoirView = firstSelectedObject->firstAncestorOrThisOfType<Rim3dView>();
}
bool isActiveViewChanged = false;
@@ -1610,7 +1607,7 @@ void RiuMainWindow::slotToggleFaultLabelsAction( bool showLabels )
Rim2dIntersectionView* isectView = dynamic_cast<Rim2dIntersectionView*>( activeView );
if ( isectView )
{
isectView->intersection()->firstAncestorOrThisOfType( activeRiv );
activeRiv = isectView->intersection()->firstAncestorOrThisOfType<RimEclipseView>();
}
}
@@ -1683,7 +1680,7 @@ void RiuMainWindow::refreshDrawStyleActions()
Rim2dIntersectionView* intView = dynamic_cast<Rim2dIntersectionView*>( view );
if ( intView && intView->intersection() )
{
intView->intersection()->firstAncestorOrThisOfType( eclView );
eclView = intView->intersection()->firstAncestorOrThisOfType<RimEclipseView>();
}
}
@@ -830,8 +830,7 @@ void RiuPlotMainWindow::slotSubWindowActivated( QMdiSubWindow* subWindow )
caf::PdmObject* pdmObject = dynamic_cast<caf::PdmObject*>( uiItem );
if ( pdmObject )
{
std::vector<RimViewWindow*> ancestralViews;
pdmObject->allAncestorsOrThisOfType( ancestralViews );
std::vector<RimViewWindow*> ancestralViews = pdmObject->allAncestorsOrThisOfType<RimViewWindow>();
for ( auto ancestralView : ancestralViews )
{
if ( ancestralView == activatedView )
@@ -909,7 +908,7 @@ void RiuPlotMainWindow::selectedObjectsChanged()
RimViewWindow* selectedWindow = dynamic_cast<RimViewWindow*>( firstSelectedObject );
if ( !selectedWindow )
{
firstSelectedObject->firstAncestorOrThisOfType( selectedWindow );
selectedWindow = firstSelectedObject->firstAncestorOrThisOfType<RimViewWindow>();
}
// If we cant find the view window as an MDI sub window, we search higher in the
@@ -918,7 +917,7 @@ void RiuPlotMainWindow::selectedObjectsChanged()
{
if ( selectedWindow->parentField() && selectedWindow->parentField()->ownerObject() )
{
selectedWindow->parentField()->ownerObject()->firstAncestorOrThisOfType( selectedWindow );
selectedWindow = selectedWindow->parentField()->ownerObject()->firstAncestorOrThisOfType<RimViewWindow>();
}
}
@@ -935,14 +934,12 @@ void RiuPlotMainWindow::selectedObjectsChanged()
if ( firstSelectedObject )
{
RimSummaryMultiPlot* multiSummaryPlot = nullptr;
firstSelectedObject->firstAncestorOrThisOfType( multiSummaryPlot );
auto multiSummaryPlot = firstSelectedObject->firstAncestorOrThisOfType<RimSummaryMultiPlot>();
if ( multiSummaryPlot )
{
updateMultiPlotToolBar();
RimSummaryPlot* summaryPlot = nullptr;
firstSelectedObject->firstAncestorOrThisOfType( summaryPlot );
auto summaryPlot = firstSelectedObject->firstAncestorOrThisOfType<RimSummaryPlot>();
if ( summaryPlot )
{
multiSummaryPlot->makeSureIsVisible( summaryPlot );
@@ -288,8 +288,7 @@ QString RiuResultTextBuilder::coordinatesText( const RigGridBase* grid, size_t g
if ( m_eclipseView )
{
std::vector<RimMultipleEclipseResults*> additionalResultSettings;
m_eclipseView->descendantsOfType( additionalResultSettings );
std::vector<RimMultipleEclipseResults*> additionalResultSettings = m_eclipseView->descendantsOfType<RimMultipleEclipseResults>();
if ( !additionalResultSettings.empty() )
{
showCenter = additionalResultSettings[0]->showCenterCoordinates();
@@ -1121,8 +1120,7 @@ std::map<QString, QString> RiuResultTextBuilder::cellResultTextAndValueText( Rim
}
else
{
RimIntersectionResultDefinition* interResDef = nullptr;
eclResDef->firstAncestorOrThisOfType( interResDef );
auto interResDef = eclResDef->firstAncestorOrThisOfType<RimIntersectionResultDefinition>();
if ( interResDef )
{
legendConfig = interResDef->regularLegendConfig();
@@ -148,8 +148,7 @@ void RiuSeismicHistogramPanel::showHistogram( caf::PdmObjectHandle* selectedObje
RimRegularLegendConfig* legend = dynamic_cast<RimRegularLegendConfig*>( selectedObject );
if ( legend )
{
RimSeismicSection* section = nullptr;
legend->firstAncestorOfType( section );
auto section = legend->firstAncestorOfType<RimSeismicSection>();
if ( section != nullptr )
{
seisData = section->seismicData();
@@ -88,8 +88,7 @@ void RiuSummaryPlot::showContextMenu( QPoint pos )
QString clickedQuantityName;
QStringList allQuantityNamesInPlot;
RimEnsembleCurveSet* clickedEnsembleCurveSet = nullptr;
summaryCurve->firstAncestorOrThisOfType( clickedEnsembleCurveSet );
auto clickedEnsembleCurveSet = summaryCurve->firstAncestorOrThisOfType<RimEnsembleCurveSet>();
bool curveClicked = distanceFromClick < 50;
@@ -124,9 +123,8 @@ void RiuSummaryPlot::showContextMenu( QPoint pos )
if ( !curveClicked )
{
auto* summaryPlot = static_cast<RimSummaryPlot*>( plotWidget()->plotDefinition() );
std::vector<RimEnsembleCurveSet*> allCurveSetsInPlot;
summaryPlot->descendantsOfType( allCurveSetsInPlot );
auto* summaryPlot = static_cast<RimSummaryPlot*>( plotWidget()->plotDefinition() );
std::vector<RimEnsembleCurveSet*> allCurveSetsInPlot = summaryPlot->descendantsOfType<RimEnsembleCurveSet>();
for ( auto curveSet : allCurveSetsInPlot )
{
allQuantityNamesInPlot.push_back( QString::fromStdString( curveSet->summaryAddress().uiText() ) );
@@ -842,9 +842,7 @@ void RiuViewerCommands::handlePickAction( int winPosX, int winPosY, Qt::Keyboard
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>( mainOrComparisonView );
if ( eclipseView )
{
RimEclipseCase* eclipseCase = nullptr;
eclipseView->firstAncestorOrThisOfTypeAsserted( eclipseCase );
auto eclipseCase = eclipseView->firstAncestorOrThisOfType<RimEclipseCase>();
if ( eclipseCase->eclipseCaseData() && eclipseCase->eclipseCaseData()->virtualPerforationTransmissibilities() )
{
std::vector<RigCompletionData> completionsForOneCell;
@@ -914,9 +912,7 @@ void RiuViewerCommands::handlePickAction( int winPosX, int winPosY, Qt::Keyboard
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>( mainOrComparisonView );
if ( eclipseView )
{
RimEclipseCase* eclipseCase = nullptr;
eclipseView->firstAncestorOrThisOfTypeAsserted( eclipseCase );
auto eclipseCase = eclipseView->firstAncestorOrThisOfType<RimEclipseCase>();
if ( eclipseCase->eclipseCaseData() && eclipseCase->eclipseCaseData()->virtualPerforationTransmissibilities() )
{
auto connectionFactors = eclipseCase->eclipseCaseData()->virtualPerforationTransmissibilities();
@@ -51,8 +51,7 @@
RiuWellLogTrack::RiuWellLogTrack( RimWellLogTrack* track, QWidget* parent /*= nullptr */ )
: RiuQwtPlotWidget( track, parent )
{
RimWellLogPlot* wlp = nullptr;
track->firstAncestorOfType( wlp );
auto wlp = track->firstAncestorOfType<RimWellLogPlot>();
bool isVertical = ( wlp && wlp->depthOrientation() == RiaDefines::Orientation::VERTICAL );
setAxisEnabled( QwtAxis::YLeft, true );
@@ -101,8 +100,7 @@ void RiuWellLogTrack::createAnnotationsInPlot( const std::vector<RimPlotAxisAnno
// Not required to update annotations in an invisible plot
if ( !plotDefinition()->showWindow() ) return;
RimDepthTrackPlot* depthTrackPlot = nullptr;
m_plotDefinition->firstAncestorOfType( depthTrackPlot );
auto depthTrackPlot = m_plotDefinition->firstAncestorOfType<RimDepthTrackPlot>();
if ( !depthTrackPlot ) return;
auto orientation = depthTrackPlot->depthOrientation() == RiaDefines::Orientation::HORIZONTAL ? RiaDefines::Orientation::VERTICAL
@@ -125,8 +123,7 @@ void RiuWellLogTrack::onMouseMoveEvent( QMouseEvent* mouseEvent )
if ( !m_plotDefinition ) return;
if ( mouseEvent->type() != QMouseEvent::MouseMove ) return;
RimDepthTrackPlot* depthTrackPlot = nullptr;
m_plotDefinition->firstAncestorOfType( depthTrackPlot );
auto depthTrackPlot = m_plotDefinition->firstAncestorOfType<RimDepthTrackPlot>();
if ( !depthTrackPlot || !depthTrackPlot->isDepthMarkerLineEnabled() ) return;
auto plotwidget = dynamic_cast<RiuQwtPlotWidget*>( m_plotDefinition->plotWidget() );
@@ -188,9 +185,7 @@ QwtText RiuWellLogCurvePointTracker::trackerText( const QPoint& pos ) const
{
QString str;
RimWellLogPlot* wlp = nullptr;
m_wellLogTrack->firstAncestorOfType( wlp );
auto wlp = m_wellLogTrack->firstAncestorOfType<RimWellLogPlot>();
if ( wlp && wlp->depthOrientation() == RiaDefines::Orientation::HORIZONTAL )
{
str = QString( "%1\nDepth: %2" ).arg( depthAxisValueString ).arg( xAxisValueString );
@@ -135,8 +135,8 @@ void RiuWellPathComponentPlotItem::calculateColumnOffsets( const RimWellPathComp
{
std::set<double> uniqueCasingDiameters;
std::vector<RimWellPathAttributeCollection*> attributeCollection;
m_wellPath->descendantsIncludingThisOfType( attributeCollection );
std::vector<RimWellPathAttributeCollection*> attributeCollection =
m_wellPath->descendantsIncludingThisOfType<RimWellPathAttributeCollection>();
for ( const RimWellPathAttribute* otherAttribute : attributeCollection.front()->attributes() )
{
if ( otherAttribute->componentType() == RiaDefines::WellPathComponentType::CASING )