mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
Make RicHistogramPlotTools robust against null plots, data sources, and missing singletons
Guard all public entry points against null plot/data-source/curve/ensemble arguments, null-check RiaGuiApplication::instance() and RimMainPlotCollection::current() before dereferencing, and skip null curves/data sources when collecting existing data sources.
This commit is contained in:
1 parent
b22a2e3106
commit
b0e8d0b62c
2 files changed
+41
-13
No files matched your search
@@ -37,8 +37,6 @@
|
||||
#include "RiuPlotMainWindow.h"
|
||||
#include "RiuPlotMainWindowTools.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
@@ -68,6 +66,8 @@ std::vector<RicHistogramPlotTools::DataSourceType> RicHistogramPlotTools::allDat
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHistogramPlotTools::createDefaultHistogramCurve( RimHistogramPlot* plot, RicHistogramPlotTools::DataSourceType dataSourceType )
|
||||
{
|
||||
if ( !plot ) return;
|
||||
|
||||
auto getDataSourceFromType = []( DataSourceType dataSourceType ) -> RimHistogramDataSource*
|
||||
{
|
||||
if ( dataSourceType == DataSourceType::ENSEMBLE_PARAMETER )
|
||||
@@ -82,8 +82,10 @@ void RicHistogramPlotTools::createDefaultHistogramCurve( RimHistogramPlot* plot,
|
||||
};
|
||||
|
||||
RimHistogramDataSource* dataSource = getDataSourceFromType( dataSourceType );
|
||||
if ( !dataSource ) return;
|
||||
|
||||
dataSource->setDefaults();
|
||||
return createHistogramCurve( plot, dataSource );
|
||||
createHistogramCurve( plot, dataSource );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -91,9 +93,13 @@ void RicHistogramPlotTools::createDefaultHistogramCurve( RimHistogramPlot* plot,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHistogramPlotTools::createHistogramCurve( RimHistogramPlot* plot, RimHistogramDataSource* dataSource )
|
||||
{
|
||||
RiaGuiApplication* app = RiaGuiApplication::instance();
|
||||
RimProject* project = app->project();
|
||||
CAF_ASSERT( project );
|
||||
if ( !plot || !dataSource ) return;
|
||||
|
||||
RiaGuiApplication* app = RiaGuiApplication::instance();
|
||||
if ( !app ) return;
|
||||
|
||||
RimProject* project = app->project();
|
||||
if ( !project ) return;
|
||||
|
||||
RimHistogramCurve* newCurve = new RimHistogramCurve();
|
||||
|
||||
@@ -112,7 +118,10 @@ void RicHistogramPlotTools::createHistogramCurve( RimHistogramPlot* plot, RimHis
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimHistogramMultiPlot* RicHistogramPlotTools::addNewHistogramMultiplot()
|
||||
{
|
||||
auto collection = RimMainPlotCollection::current()->histogramMultiPlotCollection();
|
||||
auto mainPlotCollection = RimMainPlotCollection::current();
|
||||
if ( !mainPlotCollection ) return nullptr;
|
||||
|
||||
auto collection = mainPlotCollection->histogramMultiPlotCollection();
|
||||
if ( !collection ) return nullptr;
|
||||
|
||||
return addNewHistogramMultiplot( collection );
|
||||
@@ -123,9 +132,10 @@ RimHistogramMultiPlot* RicHistogramPlotTools::addNewHistogramMultiplot()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimHistogramMultiPlot* RicHistogramPlotTools::addNewHistogramMultiplot( RimHistogramMultiPlotCollection* collection )
|
||||
{
|
||||
CAF_ASSERT( collection );
|
||||
if ( !collection ) return nullptr;
|
||||
|
||||
RimHistogramMultiPlot* multiplot = collection->appendHistogramMultiPlot();
|
||||
if ( !multiplot ) return nullptr;
|
||||
multiplot->dockAsPlotWindow();
|
||||
multiplot->setShowWindow( true );
|
||||
multiplot->loadDataAndUpdate();
|
||||
@@ -141,6 +151,8 @@ RimHistogramMultiPlot* RicHistogramPlotTools::addNewHistogramMultiplot( RimHisto
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimHistogramPlot* RicHistogramPlotTools::addNewHistogramPlot( RimHistogramMultiPlot* histogramMultiPlot )
|
||||
{
|
||||
if ( !histogramMultiPlot ) return nullptr;
|
||||
|
||||
RimHistogramPlot* plot = new RimHistogramPlot();
|
||||
plot->enableAutoPlotTitle( true );
|
||||
histogramMultiPlot->addPlot( plot );
|
||||
@@ -156,10 +168,16 @@ RimHistogramPlot* RicHistogramPlotTools::addNewHistogramPlot( RimHistogramMultiP
|
||||
std::vector<RimHistogramDataSource*> RicHistogramPlotTools::existingDataSources( RimHistogramPlot* plot )
|
||||
{
|
||||
std::vector<RimHistogramDataSource*> sources;
|
||||
if ( !plot ) return sources;
|
||||
|
||||
for ( auto curve : plot->histogramCurves() )
|
||||
{
|
||||
sources.push_back( curve->dataSource() );
|
||||
if ( !curve ) continue;
|
||||
|
||||
if ( auto source = curve->dataSource() )
|
||||
{
|
||||
sources.push_back( source );
|
||||
}
|
||||
}
|
||||
|
||||
return sources;
|
||||
@@ -170,6 +188,8 @@ std::vector<RimHistogramDataSource*> RicHistogramPlotTools::existingDataSources(
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHistogramPlotTools::appendEnsembleParameterHistogramCurve( RimHistogramPlot* plot, RimEnsembleParameterHistogramDataSource* dataSource )
|
||||
{
|
||||
if ( !plot || !dataSource ) return;
|
||||
|
||||
for ( auto source : existingDataSources( plot ) )
|
||||
{
|
||||
if ( auto histSource = dynamic_cast<RimEnsembleParameterHistogramDataSource*>( source ) )
|
||||
@@ -190,8 +210,12 @@ void RicHistogramPlotTools::appendEnsembleParameterHistogramCurve( RimHistogramP
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHistogramPlotTools::addHistogramCurveToPlot( RimHistogramPlot* plot, RimHistogramCurve* curve, bool resolveRefs )
|
||||
{
|
||||
RiaGuiApplication* app = RiaGuiApplication::instance();
|
||||
RimProject* project = app->project();
|
||||
if ( !plot || !curve ) return;
|
||||
|
||||
RiaGuiApplication* app = RiaGuiApplication::instance();
|
||||
if ( !app ) return;
|
||||
|
||||
RimProject* project = app->project();
|
||||
if ( project == nullptr ) return;
|
||||
|
||||
plot->addCurveNoUpdate( curve );
|
||||
@@ -202,7 +226,7 @@ void RicHistogramPlotTools::addHistogramCurveToPlot( RimHistogramPlot* plot, Rim
|
||||
plot->updateConnectedEditors();
|
||||
|
||||
RiuPlotMainWindow* mainPlotWindow = app->mainPlotWindow();
|
||||
mainPlotWindow->updateMultiPlotToolBar();
|
||||
if ( mainPlotWindow ) mainPlotWindow->updateMultiPlotToolBar();
|
||||
|
||||
RiuPlotMainWindowTools::onObjectAppended( curve, plot );
|
||||
}
|
||||
@@ -213,6 +237,7 @@ void RicHistogramPlotTools::addHistogramCurveToPlot( RimHistogramPlot* plot, Rim
|
||||
std::set<QString> RicHistogramPlotTools::existingEnsembleParameters( RimHistogramPlot* plot )
|
||||
{
|
||||
std::set<QString> foundParameters;
|
||||
if ( !plot ) return foundParameters;
|
||||
|
||||
for ( auto source : existingDataSources( plot ) )
|
||||
{
|
||||
@@ -231,6 +256,7 @@ std::set<QString> RicHistogramPlotTools::existingEnsembleParameters( RimHistogra
|
||||
std::set<std::pair<RifEclipseSummaryAddress, QDateTime>> RicHistogramPlotTools::existingSummaryVectors( RimHistogramPlot* plot )
|
||||
{
|
||||
std::set<std::pair<RifEclipseSummaryAddress, QDateTime>> foundVectors;
|
||||
if ( !plot ) return foundVectors;
|
||||
|
||||
for ( auto source : existingDataSources( plot ) )
|
||||
{
|
||||
@@ -248,6 +274,8 @@ std::set<std::pair<RifEclipseSummaryAddress, QDateTime>> RicHistogramPlotTools::
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicHistogramPlotTools::appendEnsembleToHistogram( RimHistogramPlot* plot, RimSummaryEnsemble* ensemble )
|
||||
{
|
||||
if ( !plot || !ensemble ) return;
|
||||
|
||||
auto currentParameters = existingEnsembleParameters( plot );
|
||||
auto currentVectors = existingSummaryVectors( plot );
|
||||
|
||||
|
||||
@@ -557,7 +557,7 @@ void RimHistogramCurve::loadAndUpdateDataAndPlot()
|
||||
plot->updateConnectedEditors();
|
||||
|
||||
RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow();
|
||||
mainPlotWindow->updateMultiPlotToolBar();
|
||||
if ( mainPlotWindow ) mainPlotWindow->updateMultiPlotToolBar();
|
||||
|
||||
dataChanged.send();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user