Memory Management : Adjustment and fixes

Add release of several static singleton objects
Fix several minor memory leaks
This commit is contained in:
Magne Sjaastad 2022-03-03 10:15:32 +01:00
parent 7a2a297648
commit 0e57cfe201
36 changed files with 441 additions and 141 deletions

View File

@ -68,9 +68,9 @@ endif()
# Defining all the source (and header) files
# ##############################################################################
set(CODE_HEADER_FILES)
set(CODE_HEADER_FILES RiaMainTools.h)
set(CODE_SOURCE_FILES RiaMain.cpp)
set(CODE_SOURCE_FILES RiaMain.cpp RiaMainTools.cpp)
if(RESINSIGHT_ENABLE_GRPC)
list(APPEND CODE_HEAD_FILES RiaGrpcConsoleApplication.h

View File

@ -18,6 +18,7 @@
#include "RiaArgumentParser.h"
#include "RiaLogging.h"
#include "RiaMainTools.h"
#ifdef ENABLE_GRPC
#include "RiaGrpcConsoleApplication.h"
@ -26,6 +27,7 @@
#include "RiaConsoleApplication.h"
#include "RiaGuiApplication.h"
#endif
#include "cvfProgramOptions.h"
#include "cvfqtUtils.h"
@ -66,8 +68,12 @@ int main( int argc, char* argv[] )
return 1;
}
#endif
// Global initialization
RiaLogging::loggerInstance()->setLevel( int( RILogLevel::RI_LL_DEBUG ) );
// Create feature manager before the application object is created
RiaMainTools::initializeSingletons();
std::unique_ptr<RiaApplication> app( createApplication( argc, argv ) );
cvf::ProgramOptions progOpt;
@ -112,6 +118,9 @@ int main( int argc, char* argv[] )
// Make sure project is closed to avoid assert and crash in destruction of widgets
app->closeProject();
app.reset();
RiaMainTools::releaseSingletonAndFactoryObjects();
return 0;
}
else if ( status == RiaApplication::ApplicationStatus::EXIT_WITH_ERROR )
@ -147,6 +156,9 @@ int main( int argc, char* argv[] )
throw;
}
app.reset();
RiaMainTools::releaseSingletonAndFactoryObjects();
return exitCode;
}

View File

@ -0,0 +1,61 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaMainTools.h"
#include "RiaRegressionTestRunner.h"
#include "RiaSocketCommand.h"
#include "cafCmdFeature.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmDefaultObjectFactory.h"
#include "cafPdmUiFieldEditorHandle.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaMainTools::initializeSingletons()
{
caf::CmdFeatureManager::createSingleton();
RiaRegressionTestRunner::createSingleton();
caf::PdmDefaultObjectFactory::createSingleton();
}
//--------------------------------------------------------------------------------------------------
/// This method is used to release memory allocated by static functions. This enables use of memory allocation tools
/// after the application has closed down.
//--------------------------------------------------------------------------------------------------
void RiaMainTools::releaseSingletonAndFactoryObjects()
{
caf::CmdFeatureManager::deleteSingleton();
RiaRegressionTestRunner::deleteSingleton();
caf::PdmDefaultObjectFactory::deleteSingleton();
{
auto factory = caf::Factory<caf::PdmUiFieldEditorHandle, QString>::instance();
factory->deleteCreatorObjects();
}
{
auto factory = caf::Factory<caf::CmdFeature, std::string>::instance();
factory->deleteCreatorObjects();
}
{
auto factory = caf::Factory<RiaSocketCommand, QString>::instance();
factory->deleteCreatorObjects();
}
}

View File

@ -0,0 +1,25 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
class RiaMainTools
{
public:
static void initializeSingletons();
static void releaseSingletonAndFactoryObjects();
};

View File

@ -189,8 +189,6 @@ RiaGuiApplication::RiaGuiApplication( int& argc, char** argv )
//--------------------------------------------------------------------------------------------------
RiaGuiApplication::~RiaGuiApplication()
{
deleteMainPlotWindow();
deleteMainWindow();
}
//--------------------------------------------------------------------------------------------------
@ -925,7 +923,7 @@ RiuMainWindow* RiaGuiApplication::getOrCreateAndShowMainWindow()
m_mainWindow->loadWinGeoAndDockToolBarLayout();
}
return m_mainWindow;
return m_mainWindow.get();
}
//--------------------------------------------------------------------------------------------------
@ -933,7 +931,7 @@ RiuMainWindow* RiaGuiApplication::getOrCreateAndShowMainWindow()
//--------------------------------------------------------------------------------------------------
RiuMainWindow* RiaGuiApplication::mainWindow()
{
return m_mainWindow;
return m_mainWindow.get();
}
//--------------------------------------------------------------------------------------------------
@ -947,7 +945,7 @@ RiuPlotMainWindow* RiaGuiApplication::getOrCreateMainPlotWindow()
m_mainPlotWindow->initializeGuiNewProjectLoaded();
loadAndUpdatePlotData();
}
return m_mainPlotWindow;
return m_mainPlotWindow.get();
}
//--------------------------------------------------------------------------------------------------
@ -962,7 +960,7 @@ void RiaGuiApplication::createMainWindow()
caf::CmdExecCommandManager::instance()->enableUndoCommandSystem( true );
}
m_mainWindow = new RiuMainWindow;
m_mainWindow = std::make_unique<RiuMainWindow>();
QString platform = cvf::System::is64Bit() ? "(64bit)" : "(32bit)";
m_mainWindow->setWindowTitle( "ResInsight " + platform );
m_mainWindow->setDefaultWindowSize();
@ -972,18 +970,6 @@ void RiaGuiApplication::createMainWindow()
m_mainWindow->showWindow();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaGuiApplication::deleteMainWindow()
{
if ( m_mainWindow )
{
delete m_mainWindow;
m_mainWindow = nullptr;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -996,26 +982,13 @@ void RiaGuiApplication::createMainPlotWindow()
caf::CmdExecCommandManager::instance()->enableUndoCommandSystem( true );
}
m_mainPlotWindow = new RiuPlotMainWindow;
m_mainPlotWindow = std::make_unique<RiuPlotMainWindow>();
m_mainPlotWindow->setWindowTitle( "Plots - ResInsight" );
m_mainPlotWindow->setDefaultWindowSize();
m_mainPlotWindow->loadWinGeoAndDockToolBarLayout();
m_mainPlotWindow->hideAllDockWidgets();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaGuiApplication::deleteMainPlotWindow()
{
if ( m_mainPlotWindow )
{
m_mainPlotWindow->setParent( nullptr );
delete m_mainPlotWindow;
m_mainPlotWindow = nullptr;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1052,7 +1025,7 @@ RiuPlotMainWindow* RiaGuiApplication::getOrCreateAndShowMainPlotWindow()
m_mainPlotWindow->restoreDockWidgetVisibilities();
}
return m_mainPlotWindow;
return m_mainPlotWindow.get();
}
//--------------------------------------------------------------------------------------------------
@ -1060,7 +1033,7 @@ RiuPlotMainWindow* RiaGuiApplication::getOrCreateAndShowMainPlotWindow()
//--------------------------------------------------------------------------------------------------
RiuPlotMainWindow* RiaGuiApplication::mainPlotWindow()
{
return m_mainPlotWindow;
return m_mainPlotWindow.get();
}
//--------------------------------------------------------------------------------------------------
@ -1069,9 +1042,9 @@ RiuPlotMainWindow* RiaGuiApplication::mainPlotWindow()
RiuMainWindowBase* RiaGuiApplication::mainWindowByID( int mainWindowID )
{
if ( mainWindowID == 0 )
return m_mainWindow;
return m_mainWindow.get();
else if ( mainWindowID == 1 )
return m_mainPlotWindow;
return m_mainPlotWindow.get();
else
return nullptr;
}
@ -1478,7 +1451,7 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences*
}
QMessageBox::StandardButton reply;
reply = QMessageBox::question( m_mainWindow,
reply = QMessageBox::question( m_mainWindow.get(),
QString( "Apply %1 to Existing Views or Plots?" ).arg( listString ),
QString( "You have changed default %1 and have existing views or plots with "
"different settings.\n" )

View File

@ -155,9 +155,7 @@ private:
void setWindowCaptionFromAppState();
void createMainWindow();
void deleteMainWindow();
void createMainPlotWindow();
void deleteMainPlotWindow();
void storeTreeViewState();
@ -168,8 +166,8 @@ private slots:
void onLastWindowClosed();
private:
QPointer<RiuMainWindow> m_mainWindow;
QPointer<RiuPlotMainWindow> m_mainPlotWindow;
std::unique_ptr<RiuMainWindow> m_mainWindow;
std::unique_ptr<RiuPlotMainWindow> m_mainPlotWindow;
std::unique_ptr<RiuRecentFileActionProvider> m_recentFileActionProvider;

View File

@ -69,6 +69,8 @@ const QString reportFileName = "ResInsightRegressionTestReport.html";
const QString commandFileFilter = "commandfile-*";
}; // namespace RegTestNames
RiaRegressionTestRunner* RiaRegressionTestRunner::sm_singleton = nullptr;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -95,8 +97,25 @@ RiaRegressionTestRunner::RiaRegressionTestRunner()
//--------------------------------------------------------------------------------------------------
RiaRegressionTestRunner* RiaRegressionTestRunner::instance()
{
static RiaRegressionTestRunner* singleton = new RiaRegressionTestRunner;
return singleton;
CAF_ASSERT( sm_singleton );
return sm_singleton;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaRegressionTestRunner::createSingleton()
{
if ( !sm_singleton ) sm_singleton = new RiaRegressionTestRunner;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaRegressionTestRunner::deleteSingleton()
{
if ( sm_singleton ) delete sm_singleton;
sm_singleton = nullptr;
}
//--------------------------------------------------------------------------------------------------

View File

@ -34,6 +34,9 @@ class RiaRegressionTestRunner
public:
static RiaRegressionTestRunner* instance();
static void createSingleton();
static void deleteSingleton();
void executeRegressionTests( const QString& regressionTestPath, const QStringList& testFilter );
void executeRegressionTests();
@ -73,4 +76,6 @@ private:
bool m_appendAllTestsAfterLastItemInFilter;
bool m_runningRegressionTests;
RiaRegressionTest m_regressionTestSettings;
static RiaRegressionTestRunner* sm_singleton;
};

View File

@ -70,7 +70,7 @@ void RicEditSummaryCurveCalculationFeature::onActionTriggered( bool isChecked )
}
}
RicSummaryCurveCalculatorDialog* dialog = RicShowSummaryCurveCalculatorFeature::curveCalculatorDialog();
RicSummaryCurveCalculatorDialog* dialog = RicShowSummaryCurveCalculatorFeature::curveCalculatorDialog( true );
dialog->setCalculationAndUpdateUi( calculation );
dialog->show();
dialog->raise();

View File

@ -50,7 +50,7 @@ RicEditSummaryPlotFeature::RicEditSummaryPlotFeature()
//--------------------------------------------------------------------------------------------------
void RicEditSummaryPlotFeature::closeDialogAndResetTargetPlot()
{
auto dialog = RicEditSummaryPlotFeature::curveCreatorDialog();
auto dialog = RicEditSummaryPlotFeature::curveCreatorDialog( false );
if ( dialog )
{
@ -65,13 +65,13 @@ void RicEditSummaryPlotFeature::closeDialogAndResetTargetPlot()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSummaryPlotEditorDialog* RicEditSummaryPlotFeature::curveCreatorDialog()
RicSummaryPlotEditorDialog* RicEditSummaryPlotFeature::curveCreatorDialog( bool createIfNotPresent )
{
RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow();
if ( mainPlotWindow )
{
return mainPlotWindow->summaryCurveCreatorDialog();
return mainPlotWindow->summaryCurveCreatorDialog( createIfNotPresent );
}
return nullptr;
@ -82,7 +82,7 @@ RicSummaryPlotEditorDialog* RicEditSummaryPlotFeature::curveCreatorDialog()
//--------------------------------------------------------------------------------------------------
void RicEditSummaryPlotFeature::editSummaryPlot( RimSummaryPlot* plot )
{
auto dialog = RicEditSummaryPlotFeature::curveCreatorDialog();
auto dialog = RicEditSummaryPlotFeature::curveCreatorDialog( true );
if ( !dialog->isVisible() )
{

View File

@ -34,7 +34,7 @@ class RicEditSummaryPlotFeature : public caf::CmdFeature
public:
void closeDialogAndResetTargetPlot();
static RicSummaryPlotEditorDialog* curveCreatorDialog();
static RicSummaryPlotEditorDialog* curveCreatorDialog( bool createIfNotPresent );
static void editSummaryPlot( RimSummaryPlot* plot );
protected:

View File

@ -123,7 +123,7 @@ void RicNewSummaryPlotFeature::onActionTriggered( bool isChecked )
}
}
auto dialog = RicEditSummaryPlotFeature::curveCreatorDialog();
auto dialog = RicEditSummaryPlotFeature::curveCreatorDialog( true );
if ( !dialog->isVisible() )
{

View File

@ -34,13 +34,13 @@ CAF_CMD_SOURCE_INIT( RicShowSummaryCurveCalculatorFeature, "RicShowSummaryCurveC
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSummaryCurveCalculatorDialog* RicShowSummaryCurveCalculatorFeature::curveCalculatorDialog()
RicSummaryCurveCalculatorDialog* RicShowSummaryCurveCalculatorFeature::curveCalculatorDialog( bool createIfNotPresent )
{
RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow();
if ( mainPlotWindow )
{
return mainPlotWindow->summaryCurveCalculatorDialog();
return mainPlotWindow->summaryCurveCalculatorDialog( createIfNotPresent );
}
return nullptr;
@ -51,9 +51,8 @@ RicSummaryCurveCalculatorDialog* RicShowSummaryCurveCalculatorFeature::curveCalc
//--------------------------------------------------------------------------------------------------
void RicShowSummaryCurveCalculatorFeature::hideCurveCalculatorDialog()
{
auto dialog = RicShowSummaryCurveCalculatorFeature::curveCalculatorDialog();
dialog->hide();
auto dialog = RicShowSummaryCurveCalculatorFeature::curveCalculatorDialog( false );
if ( dialog ) dialog->hide();
}
//--------------------------------------------------------------------------------------------------
@ -74,7 +73,7 @@ bool RicShowSummaryCurveCalculatorFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicShowSummaryCurveCalculatorFeature::onActionTriggered( bool isChecked )
{
RicSummaryCurveCalculatorDialog* dialog = RicShowSummaryCurveCalculatorFeature::curveCalculatorDialog();
RicSummaryCurveCalculatorDialog* dialog = RicShowSummaryCurveCalculatorFeature::curveCalculatorDialog( true );
RimProject* proj = RimProject::current();
RimSummaryCalculationCollection* calcColl = proj->calculationCollection();

View File

@ -30,7 +30,7 @@ class RicShowSummaryCurveCalculatorFeature : public caf::CmdFeature
CAF_CMD_HEADER_INIT;
public:
static RicSummaryCurveCalculatorDialog* curveCalculatorDialog();
static RicSummaryCurveCalculatorDialog* curveCalculatorDialog( bool createIfNotPresent );
static void hideCurveCalculatorDialog();
protected:

View File

@ -55,6 +55,7 @@ RicSummaryPlotEditorDialog::RicSummaryPlotEditorDialog( QWidget* parent )
RicSummaryPlotEditorDialog::~RicSummaryPlotEditorDialog()
{
m_curveCreatorSplitterUi->setPdmObject( nullptr );
delete m_curveCreatorSplitterUi;
}
//--------------------------------------------------------------------------------------------------

View File

@ -119,7 +119,7 @@ RiuMainWindow::RiuMainWindow()
, m_windowMenu( nullptr )
, m_holoLensToolBar( nullptr )
{
m_mdiArea = new RiuMdiArea;
m_mdiArea = new RiuMdiArea( this );
connect( m_mdiArea, SIGNAL( subWindowActivated( QMdiSubWindow* ) ), SLOT( slotSubWindowActivated( QMdiSubWindow* ) ) );
setCentralWidget( m_mdiArea );

View File

@ -73,6 +73,19 @@ RiuMainWindowBase::RiuMainWindowBase()
connect( m_redoAction, SIGNAL( triggered() ), SLOT( slotRedo() ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuMainWindowBase::~RiuMainWindowBase()
{
for ( auto v : m_projectTreeViews )
{
delete v;
}
m_projectTreeViews.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -47,7 +47,8 @@ class RiuMainWindowBase : public QMainWindow
Q_OBJECT
public:
RiuMainWindowBase();
RiuMainWindowBase();
~RiuMainWindowBase();
virtual QString mainWindowName() = 0;

View File

@ -20,6 +20,22 @@
#include "RiuMainWindow.h"
#include "RiuMdiSubWindow.h"
#include "RiuPlotMainWindow.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuMdiArea::RiuMdiArea( QWidget* parent /*= nullptr*/ )
: QMdiArea( parent )
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuMdiArea::~RiuMdiArea()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -29,6 +29,9 @@ class RiuMdiArea : public QMdiArea
Q_OBJECT
public:
RiuMdiArea( QWidget* parent = nullptr );
~RiuMdiArea();
std::list<QMdiSubWindow*> subWindowListSortedByPosition();
protected:

View File

@ -77,7 +77,7 @@ RiuPlotMainWindow::RiuPlotMainWindow()
: m_activePlotViewWindow( nullptr )
, m_windowMenu( nullptr )
{
m_mdiArea = new RiuMdiArea;
m_mdiArea = new RiuMdiArea( this );
connect( m_mdiArea, SIGNAL( subWindowActivated( QMdiSubWindow* ) ), SLOT( slotSubWindowActivated( QMdiSubWindow* ) ) );
setCentralWidget( m_mdiArea );
@ -417,13 +417,13 @@ void RiuPlotMainWindow::createToolBars()
}
}
m_wellLogPlotToolBarEditor = new caf::PdmUiToolBarEditor( "Well Log Plot", this );
m_wellLogPlotToolBarEditor = std::make_unique<caf::PdmUiToolBarEditor>( "Well Log Plot", this );
m_wellLogPlotToolBarEditor->hide();
m_summaryPlotToolBarEditor = new caf::PdmUiToolBarEditor( "Summary Plot", this );
m_summaryPlotToolBarEditor = std::make_unique<caf::PdmUiToolBarEditor>( "Summary Plot", this );
m_summaryPlotToolBarEditor->hide();
m_multiPlotToolBarEditor = new caf::PdmUiToolBarEditor( "Multi Plot", this );
m_multiPlotToolBarEditor = std::make_unique<caf::PdmUiToolBarEditor>( "Multi Plot", this );
m_multiPlotToolBarEditor->hide();
if ( RiaPreferences::current()->useUndoRedo() )
@ -516,8 +516,8 @@ void RiuPlotMainWindow::createDockPanels()
dockWidget->setObjectName( RiuDockWidgetTools::plotMainWindowPropertyEditorName() );
dockWidget->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
m_pdmUiPropertyView = new caf::PdmUiPropertyView( dockWidget );
dockWidget->setWidget( m_pdmUiPropertyView );
m_pdmUiPropertyView = std::make_unique<caf::PdmUiPropertyView>( dockWidget );
dockWidget->setWidget( m_pdmUiPropertyView.get() );
addDockWidget( Qt::LeftDockWidgetArea, dockWidget );
}
@ -535,14 +535,14 @@ void RiuPlotMainWindow::createDockPanels()
QDockWidget* dockWidget = new QDockWidget( "Plot Manager", this );
dockWidget->setObjectName( RiuDockWidgetTools::summaryPlotManagerName() );
m_summaryPlotManagerView = new caf::PdmUiPropertyView( dockWidget );
m_summaryPlotManagerView = std::make_unique<caf::PdmUiPropertyView>( dockWidget );
auto plotManager = std::make_unique<RimSummaryPlotManager>();
m_summaryPlotManagerView->showProperties( plotManager.get() );
m_summaryPlotManagerView->installEventFilter( plotManager.get() );
m_summaryPlotManager = std::move( plotManager );
dockWidget->setWidget( m_summaryPlotManagerView );
dockWidget->setWidget( m_summaryPlotManagerView.get() );
addDockWidget( Qt::BottomDockWidgetArea, dockWidget );
dockWidget->hide();
}
@ -750,27 +750,27 @@ void RiuPlotMainWindow::setFocusToLineEditInSummaryToolBar()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSummaryPlotEditorDialog* RiuPlotMainWindow::summaryCurveCreatorDialog()
RicSummaryPlotEditorDialog* RiuPlotMainWindow::summaryCurveCreatorDialog( bool createIfNotPresent )
{
if ( m_summaryCurveCreatorDialog.isNull() )
if ( !m_summaryCurveCreatorDialog && createIfNotPresent )
{
m_summaryCurveCreatorDialog = new RicSummaryPlotEditorDialog( this );
m_summaryCurveCreatorDialog = std::make_unique<RicSummaryPlotEditorDialog>( this );
}
return m_summaryCurveCreatorDialog;
return m_summaryCurveCreatorDialog.get();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSummaryCurveCalculatorDialog* RiuPlotMainWindow::summaryCurveCalculatorDialog()
RicSummaryCurveCalculatorDialog* RiuPlotMainWindow::summaryCurveCalculatorDialog( bool createIfNotPresent )
{
if ( m_summaryCurveCalculatorDialog.isNull() )
if ( !m_summaryCurveCalculatorDialog && createIfNotPresent )
{
m_summaryCurveCalculatorDialog = new RicSummaryCurveCalculatorDialog( this );
m_summaryCurveCalculatorDialog = std::make_unique<RicSummaryCurveCalculatorDialog>( this );
}
return m_summaryCurveCalculatorDialog;
return m_summaryCurveCalculatorDialog.get();
}
//--------------------------------------------------------------------------------------------------

View File

@ -88,8 +88,8 @@ public:
void updateSummaryPlotToolBar( bool forceUpdateUi = false );
void setFocusToLineEditInSummaryToolBar();
RicSummaryPlotEditorDialog* summaryCurveCreatorDialog();
RicSummaryCurveCalculatorDialog* summaryCurveCalculatorDialog();
RicSummaryPlotEditorDialog* summaryCurveCreatorDialog( bool createIfNotPresent );
RicSummaryCurveCalculatorDialog* summaryCurveCalculatorDialog( bool createIfNotPresent );
RiuMessagePanel* messagePanel();
@ -132,16 +132,16 @@ private:
QMenu* m_windowMenu;
caf::PdmUiToolBarEditor* m_wellLogPlotToolBarEditor;
caf::PdmUiToolBarEditor* m_multiPlotToolBarEditor;
caf::PdmUiToolBarEditor* m_summaryPlotToolBarEditor;
std::unique_ptr<caf::PdmUiToolBarEditor> m_wellLogPlotToolBarEditor;
std::unique_ptr<caf::PdmUiToolBarEditor> m_multiPlotToolBarEditor;
std::unique_ptr<caf::PdmUiToolBarEditor> m_summaryPlotToolBarEditor;
caf::PdmUiPropertyView* m_pdmUiPropertyView;
caf::PdmUiPropertyView* m_summaryPlotManagerView;
std::unique_ptr<caf::PdmUiPropertyView> m_pdmUiPropertyView;
std::unique_ptr<caf::PdmUiPropertyView> m_summaryPlotManagerView;
QPointer<RicSummaryPlotEditorDialog> m_summaryCurveCreatorDialog;
QPointer<RicSummaryCurveCalculatorDialog> m_summaryCurveCalculatorDialog;
std::unique_ptr<caf::PdmObject> m_summaryPlotManager;
std::unique_ptr<RicSummaryPlotEditorDialog> m_summaryCurveCreatorDialog;
std::unique_ptr<RicSummaryCurveCalculatorDialog> m_summaryCurveCalculatorDialog;
std::unique_ptr<caf::PdmObject> m_summaryPlotManager;
std::vector<QWidget*> m_temporaryWidgets;
};

View File

@ -71,7 +71,7 @@ public:
{
}
virtual ~SummaryIdentifierAndField() { delete m_pdmField; }
virtual ~SummaryIdentifierAndField();
RifEclipseSummaryAddress::SummaryIdentifierType summaryIdentifier() const { return m_summaryIdentifier; }
caf::PdmField<std::vector<QString>>* pdmField() { return m_pdmField; }
@ -81,6 +81,14 @@ private:
caf::PdmField<std::vector<QString>>* m_pdmField;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
SummaryIdentifierAndField::~SummaryIdentifierAndField()
{
delete m_pdmField;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -303,7 +311,7 @@ RiuSummaryVectorSelectionUi::~RiuSummaryVectorSelectionUi()
{
for ( const auto& identifierAndField : identifierAndFieldList.second )
{
delete identifierAndField->pdmField();
delete identifierAndField;
}
}
}

View File

@ -46,6 +46,9 @@
namespace caf
{
typedef Factory<CmdFeature, std::string> CommandFeatureFactory;
CmdFeatureManager* CmdFeatureManager::sm_singleton = nullptr;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -67,6 +70,18 @@ CmdFeatureManager::CmdFeatureManager()
//--------------------------------------------------------------------------------------------------
CmdFeatureManager::~CmdFeatureManager()
{
releaseAllCommandFeatures();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeatureManager::createSingleton()
{
if ( !sm_singleton )
{
sm_singleton = new CmdFeatureManager;
}
}
//--------------------------------------------------------------------------------------------------
@ -74,8 +89,8 @@ CmdFeatureManager::~CmdFeatureManager()
//--------------------------------------------------------------------------------------------------
CmdFeatureManager* CmdFeatureManager::instance()
{
static CmdFeatureManager* singleton = new CmdFeatureManager;
return singleton;
CAF_ASSERT( sm_singleton );
return sm_singleton;
}
//--------------------------------------------------------------------------------------------------
@ -345,4 +360,25 @@ QWidget* CmdFeatureManager::currentContextMenuTargetWidget()
return m_currentContextMenuTargetWidget;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeatureManager::releaseAllCommandFeatures()
{
for ( auto c : m_commandFeatures )
{
if ( c ) delete c;
c = nullptr;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeatureManager::deleteSingleton()
{
if ( sm_singleton ) delete sm_singleton;
sm_singleton = nullptr;
}
} // end namespace caf

View File

@ -63,6 +63,9 @@ public:
static CmdFeatureManager* instance();
~CmdFeatureManager() override;
static void createSingleton();
static void deleteSingleton();
QAction* action( const QString& commandId );
QAction* action( const QString& commandId, const QString& customActionText );
QAction* actionWithUserData( const QString& commandId, const QString& customActionText, const QVariant& userData );
@ -86,7 +89,11 @@ private:
CmdFeature* commandFeature( const std::string& commandId ) const;
void releaseAllCommandFeatures();
private:
static CmdFeatureManager* sm_singleton;
std::vector<CmdFeature*> m_commandFeatures;
std::map<std::string, size_t> m_commandIdToFeatureIdxMap;
std::map<QAction*, size_t> m_actionToFeatureIdxMap;

View File

@ -152,6 +152,15 @@ public:
return keys;
}
void deleteCreatorObjects()
{
for ( auto f : m_factoryMap )
{
if ( f.second ) delete f.second;
}
m_factoryMap.clear();
}
private:
Factory() {}
~Factory()

View File

@ -1,11 +1,63 @@
#include "cafPdmDefaultObjectFactory.h"
#include <set>
namespace caf
{
//--------------------------------------------------------------------------------------------------
/// PdmObjectFactory implementations
//--------------------------------------------------------------------------------------------------
PdmDefaultObjectFactory* PdmDefaultObjectFactory::sm_singleton = nullptr;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmDefaultObjectFactory::~PdmDefaultObjectFactory()
{
// Each keyword alias is connected to the one creator object, so it is not possible to traverse the map directly and
// delete the creator objects. Create a set of unique creator objects.
std::set<PdmObjectCreatorBase*> uniqueObjects;
for ( const auto& f : m_factoryMap )
{
uniqueObjects.insert( f.second );
}
for ( auto obj : uniqueObjects )
{
if ( obj ) delete obj;
}
m_factoryMap.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmDefaultObjectFactory* PdmDefaultObjectFactory::instance()
{
createSingleton();
return sm_singleton;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmDefaultObjectFactory::createSingleton()
{
if ( !sm_singleton ) sm_singleton = new PdmDefaultObjectFactory;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmDefaultObjectFactory::deleteSingleton()
{
if ( sm_singleton ) delete sm_singleton;
sm_singleton = nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -17,10 +69,8 @@ PdmObjectHandle* PdmDefaultObjectFactory::create( const QString& classNameKeywor
{
return entryIt->second->create();
}
else
{
return nullptr;
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
@ -38,13 +88,4 @@ std::vector<QString> PdmDefaultObjectFactory::classKeywords() const
return names;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmDefaultObjectFactory* PdmDefaultObjectFactory::instance()
{
static PdmDefaultObjectFactory* fact = new PdmDefaultObjectFactory;
return fact;
}
} // End of namespace caf

View File

@ -58,46 +58,28 @@ class PdmDefaultObjectFactory : public PdmObjectFactory
public:
static PdmDefaultObjectFactory* instance();
static void createSingleton();
static void deleteSingleton();
PdmObjectHandle* create( const QString& classNameKeyword ) override;
template <typename PdmObjectBaseDerivative>
bool registerCreator()
{
std::vector<QString> classNameKeywords = PdmObjectBaseDerivative::classKeywordAliases();
for ( QString classNameKeyword : classNameKeywords )
{
auto entryIt = m_factoryMap.find( classNameKeyword );
if ( entryIt != m_factoryMap.end() )
{
CAF_ASSERT( classNameKeyword != entryIt->first ); // classNameKeyword has already been used
CAF_ASSERT( false ); // To be sure ..
return false; // never hit;
}
}
auto object = new PdmObjectCreator<PdmObjectBaseDerivative>();
for ( QString classNameKeyword : classNameKeywords )
{
m_factoryMap[classNameKeyword] = object;
}
return true;
}
bool registerCreator();
std::vector<QString> classKeywords() const override;
private:
PdmDefaultObjectFactory() {}
~PdmDefaultObjectFactory() override
{ /* Could clean up, but ... */
}
~PdmDefaultObjectFactory() override;
static PdmDefaultObjectFactory* sm_singleton;
// Internal helper classes
class PdmObjectCreatorBase
{
public:
PdmObjectCreatorBase() {}
virtual ~PdmObjectCreatorBase() {}
PdmObjectCreatorBase() = default;
virtual ~PdmObjectCreatorBase() = default;
virtual PdmObjectHandle* create() = 0;
};
@ -112,4 +94,30 @@ private:
std::map<QString, PdmObjectCreatorBase*> m_factoryMap;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename PdmObjectBaseDerivative>
bool caf::PdmDefaultObjectFactory::registerCreator()
{
std::vector<QString> classNameKeywords = PdmObjectBaseDerivative::classKeywordAliases();
for ( const QString& classNameKeyword : classNameKeywords )
{
auto entryIt = m_factoryMap.find( classNameKeyword );
if ( entryIt != m_factoryMap.end() )
{
CAF_ASSERT( classNameKeyword != entryIt->first ); // classNameKeyword has already been used
CAF_ASSERT( false ); // To be sure ..
return false; // never hit;
}
}
auto object = new PdmObjectCreator<PdmObjectBaseDerivative>();
for ( const QString& classNameKeyword : classNameKeywords )
{
m_factoryMap[classNameKeyword] = object;
}
return true;
}
} // End of namespace caf

View File

@ -1,16 +1,38 @@
#include "MainWindow.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmDefaultObjectFactory.h"
#include "cafFactory.h"
#include "cafPdmUiFieldEditorHandle.h"
#include <QApplication>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
auto appExitCode = 0;
{
QApplication app(argc, argv);
MainWindow window;
window.setWindowTitle("Ceetron Application Framework Test Application");
window.resize(1000, 810);
window.show();
MainWindow window;
window.setWindowTitle("Ceetron Application Framework Test Application");
window.resize(1000, 810);
window.show();
return app.exec();
appExitCode = app.exec();
}
caf::CmdFeatureManager::deleteSingleton();
caf::PdmDefaultObjectFactory::deleteSingleton();
{
auto factory = caf::Factory<caf::PdmUiFieldEditorHandle, QString>::instance();
factory->deleteCreatorObjects();
}
{
auto factory = caf::Factory<caf::CmdFeature, std::string>::instance();
factory->deleteCreatorObjects();
}
return appExitCode;
}

View File

@ -1299,6 +1299,8 @@ MainWindow::~MainWindow()
m_pdmUiPropertyView->showProperties(nullptr);
m_pdmUiTableView->setChildArrayField(nullptr);
releaseTestData();
delete m_pdmUiTreeView;
delete m_pdmUiTreeView2;
delete m_pdmUiPropertyView;

View File

@ -160,6 +160,12 @@ PdmUiTreeViewEditor::~PdmUiTreeViewEditor()
{
m_treeView->removeEventFilter( this );
m_treeViewModel->setPdmItemRoot( nullptr );
if ( m_mainWidget ) delete m_mainWidget;
if ( m_delegate ) delete m_delegate;
if ( m_treeViewModel ) delete m_treeViewModel;
if ( m_filterModel ) delete m_filterModel;
if ( m_treeView ) delete m_treeView;
}
//--------------------------------------------------------------------------------------------------

View File

@ -160,10 +160,10 @@ private:
QPointer<QWidget> m_mainWidget;
QVBoxLayout* m_layout;
PdmUiTreeViewWidget* m_treeView;
PdmUiTreeViewQModel* m_treeViewModel;
PdmUiTreeViewItemDelegate* m_delegate;
QSortFilterProxyModel* m_filterModel;
QPointer<PdmUiTreeViewWidget> m_treeView;
QPointer<PdmUiTreeViewQModel> m_treeViewModel;
QPointer<PdmUiTreeViewItemDelegate> m_delegate;
QPointer<QSortFilterProxyModel> m_filterModel;
bool m_useDefaultContextMenu;
bool m_updateSelectionManager;

View File

@ -61,6 +61,18 @@ PdmUiTreeViewQModel::PdmUiTreeViewQModel( PdmUiTreeViewEditor* treeViewEditor )
m_treeViewEditor = treeViewEditor;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUiTreeViewQModel::~PdmUiTreeViewQModel()
{
if ( m_dragDropInterface )
{
delete m_dragDropInterface;
m_dragDropInterface = nullptr;
}
}
//--------------------------------------------------------------------------------------------------
/// Will populate the tree with the contents of the Pdm data structure rooted at rootItem.
/// Will not show the rootItem itself, only the children and downwards

View File

@ -60,6 +60,7 @@ class PdmUiTreeViewQModel : public QAbstractItemModel
public:
explicit PdmUiTreeViewQModel( PdmUiTreeViewEditor* treeViewEditor );
virtual ~PdmUiTreeViewQModel();
void setPdmItemRoot( PdmUiItem* rootItem );
void updateSubTree( PdmUiItem* subTreeRoot );

View File

@ -85,6 +85,7 @@ class RiaGrpcServiceCallback : public RiaGrpcCallbackInterface
{
public:
RiaGrpcServiceCallback( ServiceT* service );
~RiaGrpcServiceCallback();
QString name() const override;
const RequestT& request() const;
@ -99,6 +100,14 @@ protected:
ReplyT m_reply;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename ServiceT, typename RequestT, typename ReplyT>
RiaGrpcServiceCallback<ServiceT, RequestT, ReplyT>::~RiaGrpcServiceCallback()
{
}
//==================================================================================================
//
// Templated gRPC-callback for non-streaming services

View File

@ -74,6 +74,7 @@ private:
std::unique_ptr<grpc::Server> m_server;
std::list<std::shared_ptr<RiaGrpcServiceInterface>> m_services;
std::list<RiaGrpcCallbackInterface*> m_unprocessedRequests;
std::list<RiaGrpcCallbackInterface*> m_allocatedCallbakcs;
std::mutex m_requestMutex;
std::thread m_thread;
};
@ -217,6 +218,12 @@ void RiaGrpcServerImpl::quit()
m_server.reset();
m_completionQueue.reset();
for ( auto c : m_allocatedCallbakcs )
{
delete c;
}
m_allocatedCallbakcs.clear();
// Finally clear services
m_services.clear();
}
@ -253,6 +260,8 @@ void RiaGrpcServerImpl::process( RiaGrpcCallbackInterface* method )
if ( method->callState() == RiaGrpcCallbackInterface::CREATE_HANDLER )
{
method->createRequestHandler( m_completionQueue.get() );
m_allocatedCallbakcs.push_back( method );
}
else if ( method->callState() == RiaGrpcCallbackInterface::INIT_REQUEST_STARTED )
{
@ -269,7 +278,11 @@ void RiaGrpcServerImpl::process( RiaGrpcCallbackInterface* method )
else
{
method->onFinishRequest();
process( method->createNewFromThis() );
m_allocatedCallbakcs.remove( method );
delete method;
}
}