From bfff15568df067de2cad281f09a54fd21917e130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Wed, 25 Sep 2019 13:09:47 +0200 Subject: [PATCH] #4712 Fix stray widgets in Plot Property Panel Added comments showing that the reason is mainly deleteLater beeing called outside all event loops --- ApplicationCode/Application/RiaMain.cpp | 7 +++ .../RicSummaryPlotFeatureImpl.cpp | 43 +++++++++---------- .../cafPdmUiFieldEditorHandle.cpp | 4 ++ 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/ApplicationCode/Application/RiaMain.cpp b/ApplicationCode/Application/RiaMain.cpp index dfaf2232a9..c6e0b9d554 100644 --- a/ApplicationCode/Application/RiaMain.cpp +++ b/ApplicationCode/Application/RiaMain.cpp @@ -86,7 +86,14 @@ int main( int argc, char* argv[] ) QLocale::setDefault( QLocale( QLocale::English, QLocale::UnitedStates ) ); setlocale( LC_NUMERIC, "C" ); + // Handle the command line arguments. + // Todo: Move to a one-shot timer, delaying the execution until we are inside the event loop. + // The complete handling of the resulting ApplicationStatus must be moved along. + // The reason for this is: deleteLater() does not work outside the event loop + // Make execution of command line stuff operate in identical conditions as interactive operation. + RiaApplication::ApplicationStatus status = app->handleArguments( &progOpt ); + if ( status == RiaApplication::EXIT_COMPLETED ) { return 0; diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp index b95de8a954..0e9382cc6f 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp @@ -52,6 +52,7 @@ #include "RimSummaryPlotCollection.h" #include "RiuMainWindow.h" +#include "RiuPlotMainWindow.h" #include "RiuPlotMainWindowTools.h" #include @@ -178,7 +179,6 @@ RimSummaryCurve* createHistoryCurve( const RifEclipseSummaryAddress& addr, RimSu return nullptr; } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -406,6 +406,11 @@ void RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( const QStrin QStringList gridResultAddressFilters; QStringList summaryAddressFilters; + RimSummaryPlot* lastPlotCreated = nullptr; + + RimSummaryPlotCollection* sumPlotColl = + RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection(); + splitAddressFiltersInGridAndSummary( summaryCasesToUse[0], allCurveAddressFilters, &summaryAddressFilters, @@ -413,10 +418,6 @@ void RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( const QStrin if ( summaryAddressFilters.size() ) { - RimSummaryPlotCollection* sumPlotColl = - RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection(); - - RimSummaryPlot* lastPlotCreated = nullptr; RimSummaryCaseCollection* ensemble = nullptr; if ( isEnsembleMode ) @@ -479,11 +480,6 @@ void RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( const QStrin newPlot->applyDefaultCurveAppearances(); newPlot->loadDataAndUpdate(); - - sumPlotColl->updateConnectedEditors(); - - RiuPlotMainWindowTools::setExpanded( newPlot ); - RiuPlotMainWindowTools::selectAsCurrentItem( newPlot ); } else // Multiplot, one for each separate summary address { @@ -556,16 +552,6 @@ void RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( const QStrin } } } - - sumPlotColl->updateConnectedEditors(); - - if ( lastPlotCreated ) - { - RiuPlotMainWindowTools::setExpanded( lastPlotCreated ); - RiuPlotMainWindowTools::selectAsCurrentItem( lastPlotCreated ); - RiuPlotMainWindowTools::showPlotMainWindow(); - RiuMainWindow::instance()->close(); - } } // Grid Cell Result vectors @@ -576,9 +562,6 @@ void RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( const QStrin std::vector gridCasesToPlotFrom = openEclipseCasesForCellPlotting( gridFileNames ); - RimSummaryPlotCollection* sumPlotColl = - RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection(); - if ( isSinglePlot ) { std::vector createdCurves; @@ -632,6 +615,7 @@ void RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( const QStrin newPlot->showLegend( !hideLegend ); newPlot->setNormalizationEnabled( isNormalizedY ); newPlot->loadDataAndUpdate(); + lastPlotCreated = newPlot; } } else // Multiplot @@ -683,14 +667,27 @@ void RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( const QStrin newPlot->showLegend( !hideLegend ); newPlot->setNormalizationEnabled( isNormalizedY ); newPlot->loadDataAndUpdate(); + lastPlotCreated = newPlot; } } } } + } + if ( lastPlotCreated ) + { sumPlotColl->updateConnectedEditors(); + RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow(); + // Needed to avoid unneccessary activation of sub windows (plots) + // which results in population of property editor, and missing deleteLater because we are outside any event loop + // when switching object. Results in stray widgets. + mpw->setBlockSlotSubWindowActivated( true ); RiuPlotMainWindowTools::showPlotMainWindow(); + mpw->setBlockSlotSubWindowActivated( false ); + RiuPlotMainWindowTools::setExpanded( lastPlotCreated ); + RiuPlotMainWindowTools::selectAsCurrentItem( lastPlotCreated ); + RiuMainWindow::instance()->close(); } } diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp index 2ff803dc60..e813cb987c 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp @@ -66,6 +66,10 @@ PdmUiFieldEditorHandle::PdmUiFieldEditorHandle() //-------------------------------------------------------------------------------------------------- PdmUiFieldEditorHandle::~PdmUiFieldEditorHandle() { + // Note : deleteLater will not work unless you are actually inside an event loop. + // See https://doc.qt.io/qt-5/qobject.html#deleteLater + // Although it states that they will be deleted at startup of the event loop, it seems as that is not happening. + if (!m_combinedWidget.isNull()) m_combinedWidget->deleteLater(); if (!m_editorWidget.isNull()) m_editorWidget->deleteLater(); if (!m_labelWidget.isNull()) m_labelWidget->deleteLater();