Guard null pointer access to currently selected object

This commit is contained in:
Magne Sjaastad 2020-12-12 09:54:18 +01:00
parent 2dd5743f18
commit be91314ba6
8 changed files with 22 additions and 17 deletions

View File

@ -39,17 +39,17 @@ CAF_CMD_SOURCE_INIT( RicNewAnalysisPlotFeature, "RicNewAnalysisPlotFeature" );
bool RicNewAnalysisPlotFeature::isCommandEnabled()
{
RimAnalysisPlotCollection* analysisPlotColl = nullptr;
RimSummaryPlot* summaryPlot = nullptr;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( selObj )
{
selObj->firstAncestorOrThisOfType( analysisPlotColl );
selObj->firstAncestorOrThisOfType( summaryPlot );
}
if ( analysisPlotColl ) return true;
RimSummaryPlot* summaryPlot = nullptr;
selObj->firstAncestorOrThisOfType( summaryPlot );
if ( summaryPlot ) return true;
return false;

View File

@ -40,17 +40,17 @@ CAF_CMD_SOURCE_INIT( RicNewCorrelationMatrixPlotFeature, "RicNewCorrelationMatri
bool RicNewCorrelationMatrixPlotFeature::isCommandEnabled()
{
RimCorrelationPlotCollection* correlationPlotColl = nullptr;
RimSummaryPlot* summaryPlot = nullptr;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( selObj )
{
selObj->firstAncestorOrThisOfType( correlationPlotColl );
selObj->firstAncestorOrThisOfType( summaryPlot );
}
if ( correlationPlotColl ) return true;
RimSummaryPlot* summaryPlot = nullptr;
selObj->firstAncestorOrThisOfType( summaryPlot );
if ( summaryPlot ) return true;
return false;

View File

@ -37,17 +37,17 @@ CAF_CMD_SOURCE_INIT( RicNewCorrelationPlotFeature, "RicNewCorrelationPlotFeature
bool RicNewCorrelationPlotFeature::isCommandEnabled()
{
RimCorrelationPlotCollection* correlationPlotColl = nullptr;
RimSummaryPlot* summaryPlot = nullptr;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( selObj )
{
selObj->firstAncestorOrThisOfType( correlationPlotColl );
selObj->firstAncestorOrThisOfType( summaryPlot );
}
if ( correlationPlotColl ) return true;
RimSummaryPlot* summaryPlot = nullptr;
selObj->firstAncestorOrThisOfType( summaryPlot );
if ( summaryPlot ) return true;
return false;

View File

@ -38,17 +38,17 @@ CAF_CMD_SOURCE_INIT( RicNewCorrelationReportPlotFeature, "RicNewCorrelationRepor
bool RicNewCorrelationReportPlotFeature::isCommandEnabled()
{
RimCorrelationPlotCollection* correlationPlotColl = nullptr;
RimSummaryPlot* summaryPlot = nullptr;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( selObj )
{
selObj->firstAncestorOrThisOfType( correlationPlotColl );
selObj->firstAncestorOrThisOfType( summaryPlot );
}
if ( correlationPlotColl ) return true;
RimSummaryPlot* summaryPlot = nullptr;
selObj->firstAncestorOrThisOfType( summaryPlot );
if ( summaryPlot ) return true;
return false;

View File

@ -39,17 +39,17 @@ CAF_CMD_SOURCE_INIT( RicNewParameterResultCrossPlotFeature, "RicNewParameterResu
bool RicNewParameterResultCrossPlotFeature::isCommandEnabled()
{
RimCorrelationPlotCollection* correlationPlotColl = nullptr;
RimSummaryPlot* summaryPlot = nullptr;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( selObj )
{
selObj->firstAncestorOrThisOfType( correlationPlotColl );
selObj->firstAncestorOrThisOfType( summaryPlot );
}
if ( correlationPlotColl ) return true;
RimSummaryPlot* summaryPlot = nullptr;
selObj->firstAncestorOrThisOfType( summaryPlot );
if ( summaryPlot ) return true;
return false;

View File

@ -45,6 +45,8 @@ bool RicNewCustomObjectiveFunctionFeature::isCommandEnabled()
void RicNewCustomObjectiveFunctionFeature::onActionTriggered( bool isChecked )
{
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( !selObj ) return;
std::vector<RimCustomObjectiveFunctionCollection*> coll;
selObj->descendantsIncludingThisOfType( coll );

View File

@ -44,6 +44,8 @@ bool RicNewCustomObjectiveFunctionWeightFeature::isCommandEnabled()
void RicNewCustomObjectiveFunctionWeightFeature::onActionTriggered( bool isChecked )
{
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( !selObj ) return;
std::vector<RimCustomObjectiveFunction*> func;
selObj->descendantsIncludingThisOfType( func );

View File

@ -54,20 +54,19 @@ CAF_CMD_SOURCE_INIT( RicNewSummaryPlotFeature, "RicNewSummaryPlotFeature" );
bool RicNewSummaryPlotFeature::isCommandEnabled()
{
RimSummaryPlotCollection* sumPlotColl = nullptr;
RimCustomObjectiveFunctionCollection* customObjFuncCollection = nullptr;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( selObj )
{
sumPlotColl = RiaSummaryTools::parentSummaryPlotCollection( selObj );
selObj->firstAncestorOrThisOfType( customObjFuncCollection );
}
auto ensembleFilter = dynamic_cast<RimEnsembleCurveFilter*>( selObj );
auto ensembleFilterColl = dynamic_cast<RimEnsembleCurveFilterCollection*>( selObj );
auto legendConfig = dynamic_cast<RimRegularLegendConfig*>( selObj );
RimCustomObjectiveFunctionCollection* customObjFuncCollection = nullptr;
selObj->firstAncestorOrThisOfType( customObjFuncCollection );
if ( ensembleFilter || ensembleFilterColl || legendConfig || customObjFuncCollection ) return false;
if ( sumPlotColl ) return true;
@ -243,12 +242,14 @@ bool RicNewDefaultSummaryPlotFeature::isCommandEnabled()
std::vector<RimSummaryCase*> selectedIndividualSummaryCases;
std::vector<RimSummaryCaseCollection*> selectedEnsembles;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles );
RimCustomObjectiveFunctionCollection* customObjFuncCollection = nullptr;
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( selObj )
{
selObj->firstAncestorOrThisOfType( customObjFuncCollection );
}
return selectedIndividualSummaryCases.empty() && selectedEnsembles.empty() && ( customObjFuncCollection == nullptr );
}