From b6f0164de73a557deea36f4bcdd4c46785e2fdf3 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 14 Nov 2025 11:14:48 +0100 Subject: [PATCH] #13176 Use guarded pointers for highlighted curves --- .../Summary/RimSummaryMultiPlot.cpp | 4 +++- .../UserInterface/RiuQwtPlotWidget.cpp | 12 +++++++----- .../UserInterface/RiuQwtPlotWidget.h | 14 +++++++------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp index cd256a3341..70b04783a2 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp @@ -1846,7 +1846,9 @@ void RimSummaryMultiPlot::updateReadOutLines( double qwtTimeValue, double yValue { for ( auto highlightCurve : plotWidget->highlightedCurves() ) { - if ( auto summaryCurve = dynamic_cast( highlightCurve ) ) + if ( highlightCurve.isNull() ) continue; + + if ( auto summaryCurve = dynamic_cast( highlightCurve.p() ) ) { summaryCurves.push_back( summaryCurve ); } diff --git a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp index cf84cf5634..aeac34447a 100644 --- a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp @@ -1018,8 +1018,10 @@ void RiuQwtPlotWidget::selectClosestPlotItem( const QPoint& pos, bool toggleItem bool wasToggledOff = false; if ( toggleItemInSelection ) { - for ( auto highlightedCurve : m_hightlightedCurves ) + for ( auto highlightedCurve : m_highlightedCurves ) { + if ( highlightedCurve.isNull() ) continue; + if ( highlightedCurve == clickedCurve ) { wasToggledOff = true; @@ -1165,7 +1167,7 @@ void RiuQwtPlotWidget::highlightPlotCurves( const std::vector& cu plotCurve->setZ( zValue + 100.0 ); highlightPlotAxes( plotCurve->xAxis(), plotCurve->yAxis() ); - m_hightlightedCurves.push_back( currentRimPlotCurve ); + m_highlightedCurves.push_back( currentRimPlotCurve ); } else { @@ -1225,9 +1227,9 @@ void RiuQwtPlotWidget::resetPlotItemHighlighting( bool doUpdateCurveOrder ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiuQwtPlotWidget::highlightedCurves() const +std::vector> RiuQwtPlotWidget::highlightedCurves() const { - return m_hightlightedCurves; + return m_highlightedCurves; } //-------------------------------------------------------------------------------------------------- @@ -1235,7 +1237,7 @@ std::vector RiuQwtPlotWidget::highlightedCurves() const //-------------------------------------------------------------------------------------------------- void RiuQwtPlotWidget::resetPlotCurveHighlighting() { - m_hightlightedCurves.clear(); + m_highlightedCurves.clear(); if ( !m_plotDefinition || m_originalZValues.empty() ) { diff --git a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h index 1bb9bb4d90..d75b1ae0c4 100644 --- a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h +++ b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h @@ -162,10 +162,10 @@ public: QwtAxisId toQwtPlotAxis( RiuPlotAxis axis ) const; - void highlightPlotItem( const QwtPlotItem* plotItem ); - void highlightCurvesUpdateOrder( const std::vector& curves ); - void resetPlotItemHighlighting( bool doUpdateCurveOrder = true ); - std::vector highlightedCurves() const; + void highlightPlotItem( const QwtPlotItem* plotItem ); + void highlightCurvesUpdateOrder( const std::vector& curves ); + void resetPlotItemHighlighting( bool doUpdateCurveOrder = true ); + std::vector> highlightedCurves() const; void replot() override; @@ -231,9 +231,9 @@ private: int lineWidth; }; - std::map m_originalZValues; - std::vector m_hightlightedCurves; - std::map m_axisMapping; + std::map m_originalZValues; + std::vector> m_highlightedCurves; + std::map m_axisMapping; QPointer m_plot;