From a413f672eca23c24df01a006cd34a1396a3bc9ae Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 7 Nov 2019 08:48:11 +0100 Subject: [PATCH 1/2] #5007 Janitor : Do not call virtual methods from destructors --- .../RifEclipseRestartFilesetAccess.cpp | 2 - .../Flow/RimFlowCharacteristicsPlot.cpp | 6 ++- .../RimTofAccumulatedPhaseFractionsPlot.cpp | 6 ++- .../Flow/RimTotalWellAllocationPlot.cpp | 6 ++- .../Flow/RimWellAllocationPlot.cpp | 6 ++- .../GridCrossPlots/RimGridCrossPlot.cpp | 26 +++++++++---- .../GridCrossPlots/RimGridCrossPlot.h | 3 ++ .../ProjectDataModel/Rim3dView.cpp | 3 +- .../ProjectDataModel/RimGridPlotWindow.cpp | 28 +++++++++---- .../ProjectDataModel/RimGridPlotWindow.h | 2 + .../Summary/RimSummaryPlot.cpp | 39 +++++++++++++++---- .../ProjectDataModel/Summary/RimSummaryPlot.h | 2 + 12 files changed, 99 insertions(+), 30 deletions(-) diff --git a/ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.cpp b/ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.cpp index 16bba0a34e..9ed95cff16 100644 --- a/ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.cpp +++ b/ApplicationCode/FileInterface/RifEclipseRestartFilesetAccess.cpp @@ -41,8 +41,6 @@ RifEclipseRestartFilesetAccess::RifEclipseRestartFilesetAccess() //-------------------------------------------------------------------------------------------------- RifEclipseRestartFilesetAccess::~RifEclipseRestartFilesetAccess() { - close(); - for ( size_t i = 0; i < m_ecl_files.size(); i++ ) { if ( m_ecl_files[i] ) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp index eed12db7f3..5775f31719 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp @@ -116,7 +116,11 @@ RimFlowCharacteristicsPlot::~RimFlowCharacteristicsPlot() { removeMdiWindowFromMdiArea(); - deleteViewWidget(); + if ( m_flowCharPlotWidget ) + { + m_flowCharPlotWidget->deleteLater(); + m_flowCharPlotWidget = nullptr; + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Flow/RimTofAccumulatedPhaseFractionsPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimTofAccumulatedPhaseFractionsPlot.cpp index 48dbd76ab0..37c266dd76 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimTofAccumulatedPhaseFractionsPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimTofAccumulatedPhaseFractionsPlot.cpp @@ -69,7 +69,11 @@ RimTofAccumulatedPhaseFractionsPlot::~RimTofAccumulatedPhaseFractionsPlot() { removeMdiWindowFromMdiArea(); - deleteViewWidget(); + if ( m_tofAccumulatedPhaseFractionsPlotWidget ) + { + m_tofAccumulatedPhaseFractionsPlotWidget->deleteLater(); + m_tofAccumulatedPhaseFractionsPlotWidget = nullptr; + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp index e1f4ef6b47..0481a7b256 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp @@ -57,7 +57,11 @@ RimTotalWellAllocationPlot::~RimTotalWellAllocationPlot() { removeMdiWindowFromMdiArea(); - deleteViewWidget(); + if ( m_wellTotalAllocationPlotWidget ) + { + m_wellTotalAllocationPlotWidget->deleteLater(); + m_wellTotalAllocationPlotWidget = nullptr; + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 315849bf45..35a98e7e3d 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -140,7 +140,11 @@ RimWellAllocationPlot::~RimWellAllocationPlot() delete m_totalWellAllocationPlot(); delete m_tofAccumulatedPhaseFractionsPlot(); - deleteViewWidget(); + if ( m_wellAllocationPlotWidget ) + { + m_wellAllocationPlotWidget->deleteLater(); + m_wellAllocationPlotWidget = nullptr; + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp index 82a4075871..c3ed8f08a3 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp @@ -87,7 +87,7 @@ RimGridCrossPlot::RimGridCrossPlot() RimGridCrossPlot::~RimGridCrossPlot() { removeMdiWindowFromMdiArea(); - deleteViewWidget(); + cleanupBeforeClose(); } //-------------------------------------------------------------------------------------------------- @@ -481,12 +481,7 @@ QWidget* RimGridCrossPlot::createViewWidget( QWidget* mainWindowParent ) //-------------------------------------------------------------------------------------------------- void RimGridCrossPlot::deleteViewWidget() { - detachAllCurves(); - if ( m_plotWidget ) - { - m_plotWidget->deleteLater(); - m_plotWidget = nullptr; - } + cleanupBeforeClose(); } //-------------------------------------------------------------------------------------------------- @@ -1115,6 +1110,23 @@ void RimGridCrossPlot::updatePlotTitle() updateCurveNamesAndPlotTitle(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimGridCrossPlot::cleanupBeforeClose() +{ + for ( auto dataSet : m_crossPlotDataSets() ) + { + dataSet->detachAllCurves(); + } + + if ( m_plotWidget ) + { + m_plotWidget->deleteLater(); + m_plotWidget = nullptr; + } +} + //-------------------------------------------------------------------------------------------------- /// Name Configuration /// diff --git a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.h b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.h index dfeaf5c8fc..bd403aad96 100644 --- a/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.h +++ b/ApplicationCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.h @@ -153,6 +153,9 @@ protected: void updatePlotTitle() override; +private: + void cleanupBeforeClose(); + private: caf::PdmField m_showInfoBox; caf::PdmField m_showLegend_OBSOLETE; diff --git a/ApplicationCode/ProjectDataModel/Rim3dView.cpp b/ApplicationCode/ProjectDataModel/Rim3dView.cpp index 42ec444b24..f3e62de869 100644 --- a/ApplicationCode/ProjectDataModel/Rim3dView.cpp +++ b/ApplicationCode/ProjectDataModel/Rim3dView.cpp @@ -164,7 +164,8 @@ Rim3dView::~Rim3dView( void ) } removeMdiWindowFromMdiArea(); - deleteViewWidget(); + delete m_viewer; + m_viewer = nullptr; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimGridPlotWindow.cpp b/ApplicationCode/ProjectDataModel/RimGridPlotWindow.cpp index 66663ba92a..be0c286b13 100644 --- a/ApplicationCode/ProjectDataModel/RimGridPlotWindow.cpp +++ b/ApplicationCode/ProjectDataModel/RimGridPlotWindow.cpp @@ -66,7 +66,7 @@ RimGridPlotWindow::~RimGridPlotWindow() removeMdiWindowFromMdiArea(); m_plots.deleteAllChildObjects(); - deleteViewWidget(); + cleanupBeforeClose(); } //-------------------------------------------------------------------------------------------------- @@ -389,13 +389,7 @@ QWidget* RimGridPlotWindow::createViewWidget( QWidget* mainWindowParent ) //-------------------------------------------------------------------------------------------------- void RimGridPlotWindow::deleteViewWidget() { - detachAllCurves(); - - if ( m_viewer ) - { - m_viewer->deleteLater(); - m_viewer = nullptr; - } + cleanupBeforeClose(); } //-------------------------------------------------------------------------------------------------- @@ -624,6 +618,24 @@ void RimGridPlotWindow::detachAllCurves() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimGridPlotWindow::cleanupBeforeClose() +{ + auto plotVector = plots(); + for ( size_t tIdx = 0; tIdx < plotVector.size(); ++tIdx ) + { + plotVector[tIdx]->detachAllCurves(); + } + + if ( m_viewer ) + { + m_viewer->deleteLater(); + m_viewer = nullptr; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimGridPlotWindow.h b/ApplicationCode/ProjectDataModel/RimGridPlotWindow.h index a4a71a2c31..a39c533a5e 100644 --- a/ApplicationCode/ProjectDataModel/RimGridPlotWindow.h +++ b/ApplicationCode/ProjectDataModel/RimGridPlotWindow.h @@ -118,6 +118,8 @@ protected: private: void detachAllCurves() override; + void cleanupBeforeClose(); + static RimPlotInterface* toPlotInterfaceAsserted( caf::PdmObject* pdmObject ); static const RimPlotInterface* toPlotInterfaceAsserted( const caf::PdmObject* pdmObject ); static caf::PdmObject* toPdmObjectAsserted( RimPlotInterface* plotInterface ); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index c41c357c79..5b5729ffb1 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -226,7 +226,7 @@ RimSummaryPlot::~RimSummaryPlot() { removeMdiWindowFromMdiArea(); - deleteViewWidget(); + cleanupBeforeClose(); m_summaryCurves_OBSOLETE.deleteAllChildObjects(); m_curveFilters_OBSOLETE.deleteAllChildObjects(); @@ -1508,6 +1508,35 @@ std::set RimSummaryPlot::allPlotAxes() const return {m_timeAxisProperties, m_bottomAxisProperties, m_leftYAxisProperties, m_rightYAxisProperties}; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryPlot::cleanupBeforeClose() +{ + if ( m_summaryCurveCollection ) + { + m_summaryCurveCollection->detachQwtCurves(); + } + + m_ensembleCurveSetCollection->detachQwtCurves(); + + for ( RimGridTimeHistoryCurve* curve : m_gridTimeHistoryCurves ) + { + curve->detachQwtCurve(); + } + + for ( RimAsciiDataCurve* curve : m_asciiDataCurves ) + { + curve->detachQwtCurve(); + } + + if ( m_plotWidget ) + { + m_plotWidget->deleteLater(); + m_plotWidget = nullptr; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1736,13 +1765,7 @@ QWidget* RimSummaryPlot::createViewWidget( QWidget* mainWindowParent ) //-------------------------------------------------------------------------------------------------- void RimSummaryPlot::deleteViewWidget() { - detachAllCurves(); - - if ( m_plotWidget ) - { - m_plotWidget->deleteLater(); - m_plotWidget = nullptr; - } + cleanupBeforeClose(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h index 4799ccc285..ce97bd4809 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -224,6 +224,8 @@ private: std::set allPlotAxes() const; + void cleanupBeforeClose(); + private: caf::PdmField m_normalizeCurveYValues; From 388b92c092b0e44e1289afb16f7a04b593c59e50 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 7 Nov 2019 09:01:31 +0100 Subject: [PATCH 2/2] #5007 Janitor : Do not call virtual methods from constructors --- .../GeoMech/GeoMechDataModel/RigFemPart.cpp | 3 ++- .../GeoMech/GeoMechDataModel/RigFemPartGrid.cpp | 14 +++++++++++--- .../GeoMech/GeoMechDataModel/RigFemPartGrid.h | 4 +++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.cpp b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.cpp index 0b3379eedc..451f954768 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.cpp +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPart.cpp @@ -72,7 +72,8 @@ const RigFemPartGrid* RigFemPart::getOrCreateStructGrid() const { if ( m_structGrid.isNull() ) { - m_structGrid = new RigFemPartGrid( this ); + m_structGrid = new RigFemPartGrid(); + m_structGrid->setFemPart( this ); } return m_structGrid.p(); diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartGrid.cpp b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartGrid.cpp index cbe5283411..9861d33b3c 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartGrid.cpp +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartGrid.cpp @@ -26,10 +26,9 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigFemPartGrid::RigFemPartGrid( const RigFemPart* femPart ) +RigFemPartGrid::RigFemPartGrid() + : m_femPart( nullptr ) { - m_femPart = femPart; - generateStructGridData(); } //-------------------------------------------------------------------------------------------------- @@ -37,6 +36,15 @@ RigFemPartGrid::RigFemPartGrid( const RigFemPart* femPart ) //-------------------------------------------------------------------------------------------------- RigFemPartGrid::~RigFemPartGrid() {} +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigFemPartGrid::setFemPart( const RigFemPart* femPart ) +{ + m_femPart = femPart; + generateStructGridData(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartGrid.h b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartGrid.h index f01e859e9a..7c72aa9259 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartGrid.h +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartGrid.h @@ -26,9 +26,11 @@ class RigFemPart; class RigFemPartGrid : public cvf::StructGridInterface { public: - explicit RigFemPartGrid( const RigFemPart* femPart ); + RigFemPartGrid(); ~RigFemPartGrid() override; + void setFemPart( const RigFemPart* femPart ); + bool ijkFromCellIndex( size_t cellIndex, size_t* i, size_t* j, size_t* k ) const override; size_t cellIndexFromIJK( size_t i, size_t j, size_t k ) const override;