Memory Management : Fixes related to plot objects and curves

This commit is contained in:
Magne Sjaastad
2022-02-25 14:47:15 +01:00
parent 47a44a79df
commit 4693dc44ef
14 changed files with 128 additions and 60 deletions

View File

@@ -131,7 +131,6 @@ RimPlotCurve::~RimPlotCurve()
{
if ( m_plotCurve )
{
detach();
delete m_plotCurve;
m_plotCurve = nullptr;
}
@@ -1017,12 +1016,15 @@ void RimPlotCurve::detach( bool deletePlotCurve )
{
if ( m_plotCurve )
{
m_plotCurve->detach();
if ( deletePlotCurve )
{
delete m_plotCurve;
m_plotCurve = nullptr;
}
else
{
m_plotCurve->detach();
}
}
replotParentPlot();
@@ -1033,7 +1035,7 @@ void RimPlotCurve::detach( bool deletePlotCurve )
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::reattach()
{
if ( m_parentPlot ) attach( m_parentPlot );
if ( m_parentPlot && canCurveBeAttached() ) attach( m_parentPlot );
}
//--------------------------------------------------------------------------------------------------
@@ -1044,6 +1046,15 @@ bool RimPlotCurve::isSameCurve( const RiuPlotCurve* plotCurve ) const
return m_plotCurve == plotCurve;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotCurve::deletePlotCurve()
{
delete m_plotCurve;
m_plotCurve = nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -126,6 +126,7 @@ public:
void detach( bool deletePlotCurve = false );
void reattach();
bool isSameCurve( const RiuPlotCurve* plotCurve ) const;
void deletePlotCurve();
protected:
virtual QString createCurveAutoName() = 0;

View File

@@ -179,7 +179,7 @@ RimSummaryPlot::~RimSummaryPlot()
{
removeMdiWindowFromMdiArea();
cleanupBeforeClose();
deletePlotCurvesAndPlotWidget();
delete m_summaryCurveCollection;
delete m_ensembleCurveSetCollection;
@@ -1378,7 +1378,7 @@ void RimSummaryPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
// Destroy viewer
removeMdiWindowFromMdiArea();
cleanupBeforeClose();
deletePlotCurvesAndPlotWidget();
}
#endif
@@ -1401,14 +1401,9 @@ void RimSummaryPlot::childFieldChangedByUi( const caf::PdmFieldHandle* changedCh
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::updateStackedCurveData()
{
for ( RimPlotAxisPropertiesInterface* axisProperties : m_axisProperties )
{
if ( axisProperties->plotAxisType().axis() == RiaDefines::PlotAxis::PLOT_AXIS_LEFT ||
axisProperties->plotAxisType().axis() == RiaDefines::PlotAxis::PLOT_AXIS_RIGHT )
updateStackedCurveDataForAxis( axisProperties->plotAxisType() );
}
auto anyStackedCurvesPresent = updateStackedCurveDataForRelevantAxes();
if ( plotWidget() )
if ( plotWidget() && anyStackedCurvesPresent )
{
reattachAllCurves();
plotWidget()->scheduleReplot();
@@ -1418,13 +1413,30 @@ void RimSummaryPlot::updateStackedCurveData()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::updateStackedCurveDataForAxis( RiuPlotAxis plotAxis )
bool RimSummaryPlot::updateStackedCurveDataForRelevantAxes()
{
std::map<RiaDefines::PhaseType, size_t> curvePhaseCount;
bool anyStackedCurvesPresent = false;
for ( RimPlotAxisPropertiesInterface* axisProperties : m_axisProperties )
{
if ( axisProperties->plotAxisType().axis() == RiaDefines::PlotAxis::PLOT_AXIS_LEFT ||
axisProperties->plotAxisType().axis() == RiaDefines::PlotAxis::PLOT_AXIS_RIGHT )
{
anyStackedCurvesPresent |= updateStackedCurveDataForAxis( axisProperties->plotAxisType() );
}
}
return anyStackedCurvesPresent;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSummaryPlot::updateStackedCurveDataForAxis( RiuPlotAxis plotAxis )
{
auto stackedCurves = visibleStackedSummaryCurvesForAxis( plotAxis );
if ( stackedCurves.empty() ) return false;
// Reset all curves
std::map<RiaDefines::PhaseType, size_t> curvePhaseCount;
for ( RimSummaryCurve* curve : stackedCurves )
{
// Apply a area filled style if it isn't already set
@@ -1473,6 +1485,8 @@ void RimSummaryPlot::updateStackedCurveDataForAxis( RiuPlotAxis plotAxis )
zPos -= 1.0;
}
}
return true;
}
//--------------------------------------------------------------------------------------------------
@@ -1595,7 +1609,7 @@ void RimSummaryPlot::updateZoomFromParentPlot()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::cleanupBeforeClose()
void RimSummaryPlot::deletePlotCurvesAndPlotWidget()
{
if ( isDeletable() )
{
@@ -1606,6 +1620,8 @@ void RimSummaryPlot::cleanupBeforeClose()
plotWidget()->setParent( nullptr );
}
deleteAllPlotCurves();
if ( m_summaryPlot )
{
m_summaryPlot.reset();
@@ -1905,7 +1921,11 @@ void RimSummaryPlot::handleDroppedObjects( const std::vector<caf::PdmObjectHandl
}
}
if ( newCurves > 0 ) applyDefaultCurveAppearances();
if ( newCurves > 0 )
{
applyDefaultCurveAppearances();
loadDataAndUpdate();
}
updateConnectedEditors();
}
@@ -1919,7 +1939,6 @@ void RimSummaryPlot::addNewCurveY( const RifEclipseSummaryAddress& address, RimS
newCurve->setSummaryCaseY( summaryCase );
newCurve->setSummaryAddressYAndApplyInterpolation( address );
addCurveNoUpdate( newCurve );
newCurve->loadDataAndUpdate( true );
}
//--------------------------------------------------------------------------------------------------
@@ -1996,7 +2015,7 @@ RiuPlotWidget* RimSummaryPlot::doCreatePlotViewWidget( QWidget* mainWindowParent
if ( useQtCharts )
{
m_summaryPlot = std::make_unique<RiuSummaryQtChartsPlot>( this, mainWindowParent );
m_summaryPlot = std::make_unique<RiuSummaryQtChartsPlot>( this );
}
else
{
@@ -2044,7 +2063,7 @@ RiuPlotWidget* RimSummaryPlot::doCreatePlotViewWidget( QWidget* mainWindowParent
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::deleteViewWidget()
{
cleanupBeforeClose();
deletePlotCurvesAndPlotWidget();
}
//--------------------------------------------------------------------------------------------------
@@ -2190,6 +2209,17 @@ void RimSummaryPlot::detachAllPlotItems()
m_plotInfoLabel->detach();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::deleteAllPlotCurves()
{
for ( auto* c : summaryCurves() )
{
c->deletePlotCurve();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -206,6 +206,7 @@ private:
void doUpdateLayout() override;
void detachAllPlotItems();
void deleteAllPlotCurves();
void handleKeyPressEvent( QKeyEvent* keyEvent ) override;
@@ -223,9 +224,6 @@ protected:
void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
std::vector<caf::PdmObjectHandle*>& referringObjects ) override;
void updateStackedCurveData();
void updateStackedCurveDataForAxis( RiuPlotAxis plotAxis );
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void onLoadDataAndUpdate() override;
@@ -249,7 +247,7 @@ private:
void updateTimeAxis( RimSummaryTimeAxisProperties* timeAxisProperties );
void cleanupBeforeClose();
void deletePlotCurvesAndPlotWidget();
void connectCurveSignals( RimSummaryCurve* curve );
void disconnectCurveSignals( RimSummaryCurve* curve );
@@ -272,6 +270,10 @@ private:
void addNewCurveY( const RifEclipseSummaryAddress& address, RimSummaryCase* summaryCase );
void updateStackedCurveData();
bool updateStackedCurveDataForAxis( RiuPlotAxis plotAxis );
bool updateStackedCurveDataForRelevantAxes();
private:
#ifdef USE_QTCHARTS
caf::PdmField<bool> m_useQtChartsPlot;