Valgrind: Move global settings handling closer to current pattern

Change-Id: I41f35485ef51b977ee75fec53dbf0c8d75a27461
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2023-07-19 09:59:00 +02:00
parent 08bbe885b4
commit 773a28acea
8 changed files with 47 additions and 61 deletions

View File

@@ -77,7 +77,6 @@ public:
void resetProjectToGlobalSettings(); void resetProjectToGlobalSettings();
ISettingsAspect *projectSettings() const { return m_projectSettings; } ISettingsAspect *projectSettings() const { return m_projectSettings; }
ISettingsAspect *globalSettings() const { return m_globalSettings; }
ISettingsAspect *currentSettings() const; ISettingsAspect *currentSettings() const;
struct Data : Utils::BaseAspect::Data struct Data : Utils::BaseAspect::Data

View File

@@ -342,8 +342,6 @@ CallgrindToolPrivate::CallgrindToolPrivate()
updateCostFormat(); updateCostFormat();
ValgrindGlobalSettings *settings = ValgrindGlobalSettings::instance();
// //
// Control Widget // Control Widget
// //
@@ -360,8 +358,8 @@ CallgrindToolPrivate::CallgrindToolPrivate()
Theme::IconsBaseColor}}); Theme::IconsBaseColor}});
action->setIcon(kCachegrindIcon.icon()); action->setIcon(kCachegrindIcon.icon());
action->setToolTip(Tr::tr("Open results in KCachegrind.")); action->setToolTip(Tr::tr("Open results in KCachegrind."));
connect(action, &QAction::triggered, this, [this, settings] { connect(action, &QAction::triggered, this, [this] {
Process::startDetached({settings->kcachegrindExecutable(), { m_lastFileName }}); Process::startDetached({globalSettings().kcachegrindExecutable(), { m_lastFileName }});
}); });
// dump action // dump action
@@ -468,7 +466,7 @@ CallgrindToolPrivate::CallgrindToolPrivate()
} }
// Filtering // Filtering
action = m_filterProjectCosts = settings->filterExternalIssues.action(); action = m_filterProjectCosts = globalSettings().filterExternalIssues.action();
connect(action, &QAction::toggled, this, &CallgrindToolPrivate::handleFilterProjectCosts); connect(action, &QAction::toggled, this, &CallgrindToolPrivate::handleFilterProjectCosts);
// Filter // Filter
@@ -477,10 +475,10 @@ CallgrindToolPrivate::CallgrindToolPrivate()
connect(m_searchFilter, &QLineEdit::textChanged, connect(m_searchFilter, &QLineEdit::textChanged,
&m_updateTimer, QOverload<>::of(&QTimer::start)); &m_updateTimer, QOverload<>::of(&QTimer::start));
setCostFormat(CostDelegate::CostFormat(settings->costFormat())); setCostFormat(CostDelegate::CostFormat(globalSettings().costFormat()));
m_perspective.addToolBarAction(settings->detectCycles.action()); m_perspective.addToolBarAction(globalSettings().detectCycles.action());
m_perspective.addToolBarAction(settings->shortenTemplates.action()); m_perspective.addToolBarAction(globalSettings().shortenTemplates.action());
m_perspective.addToolBarAction(m_filterProjectCosts); m_perspective.addToolBarAction(m_filterProjectCosts);
m_perspective.addToolBarWidget(m_searchFilter); m_perspective.addToolBarWidget(m_searchFilter);
@@ -625,8 +623,7 @@ void CallgrindToolPrivate::updateCostFormat()
m_calleesView->setCostFormat(format); m_calleesView->setCostFormat(format);
m_callersView->setCostFormat(format); m_callersView->setCostFormat(format);
} }
if (ValgrindGlobalSettings *settings = ValgrindGlobalSettings::instance()) globalSettings().costFormat.setValue(format);
settings->costFormat.setValue(format);
} }
void CallgrindToolPrivate::handleFilterProjectCosts() void CallgrindToolPrivate::handleFilterProjectCosts()
@@ -908,8 +905,7 @@ void CallgrindToolPrivate::takeParserData(ParseData *data)
doClear(true); doClear(true);
setParseData(data); setParseData(data);
const FilePath kcachegrindExecutable = const FilePath kcachegrindExecutable = globalSettings().kcachegrindExecutable();
ValgrindGlobalSettings::instance()->kcachegrindExecutable();
const FilePath found = kcachegrindExecutable.searchInPath(); const FilePath found = kcachegrindExecutable.searchInPath();
const bool kcachegrindExists = found.isExecutableFile(); const bool kcachegrindExists = found.isExecutableFile();
m_startKCachegrind->setEnabled(kcachegrindExists && !m_lastFileName.isEmpty()); m_startKCachegrind->setEnabled(kcachegrindExists && !m_lastFileName.isEmpty());

View File

@@ -519,7 +519,7 @@ private:
MemcheckToolPrivate::MemcheckToolPrivate() MemcheckToolPrivate::MemcheckToolPrivate()
{ {
m_settings = ValgrindGlobalSettings::instance(); m_settings = &globalSettings();
setObjectName("MemcheckTool"); setObjectName("MemcheckTool");
@@ -904,7 +904,7 @@ void MemcheckToolPrivate::updateRunActions()
void MemcheckToolPrivate::settingsDestroyed(QObject *settings) void MemcheckToolPrivate::settingsDestroyed(QObject *settings)
{ {
QTC_ASSERT(m_settings == settings, return); QTC_ASSERT(m_settings == settings, return);
m_settings = ValgrindGlobalSettings::instance(); m_settings = &globalSettings();
} }
void MemcheckToolPrivate::updateFromSettings() void MemcheckToolPrivate::updateFromSettings()
@@ -943,7 +943,7 @@ void MemcheckToolPrivate::maybeActiveRunConfigurationChanged()
settings = rc->currentSettings<ValgrindBaseSettings>(ANALYZER_VALGRIND_SETTINGS); settings = rc->currentSettings<ValgrindBaseSettings>(ANALYZER_VALGRIND_SETTINGS);
if (!settings) // fallback to global settings if (!settings) // fallback to global settings
settings = ValgrindGlobalSettings::instance(); settings = &globalSettings();
if (m_settings == settings) if (m_settings == settings)
return; return;
@@ -1045,8 +1045,8 @@ void MemcheckToolPrivate::loadXmlLogFile(const QString &filePath)
clearErrorView(); clearErrorView();
m_loadExternalLogFile->setDisabled(true); m_loadExternalLogFile->setDisabled(true);
if (!m_settings || m_settings != ValgrindGlobalSettings::instance()) { if (!m_settings || m_settings != &globalSettings()) {
m_settings = ValgrindGlobalSettings::instance(); m_settings = &globalSettings();
m_errorView->settingsChanged(m_settings); m_errorView->settingsChanged(m_settings);
updateFromSettings(); updateFromSettings();
} }

View File

@@ -16,8 +16,7 @@
using namespace Utils; using namespace Utils;
namespace Valgrind { namespace Valgrind::Internal {
namespace Internal {
class ValgrindConfigWidget : public Core::IOptionsPageWidget class ValgrindConfigWidget : public Core::IOptionsPageWidget
{ {
@@ -26,13 +25,13 @@ public:
void apply() final void apply() final
{ {
ValgrindGlobalSettings::instance()->apply(); globalSettings().apply();
ValgrindGlobalSettings::instance()->writeSettings(); globalSettings().writeSettings();
} }
void finish() final void finish() final
{ {
ValgrindGlobalSettings::instance()->finish(); globalSettings().finish();
} }
}; };
@@ -87,20 +86,26 @@ ValgrindConfigWidget::ValgrindConfigWidget(ValgrindBaseSettings *settings)
// ValgrindOptionsPage // ValgrindOptionsPage
ValgrindOptionsPage::ValgrindOptionsPage() class ValgrindOptionsPage final : public Core::IOptionsPage
{ {
setId(ANALYZER_VALGRIND_SETTINGS); public:
setDisplayName(Tr::tr("Valgrind")); ValgrindOptionsPage()
setCategory("T.Analyzer"); {
setDisplayCategory(::Debugger::Tr::tr("Analyzer")); setId(ANALYZER_VALGRIND_SETTINGS);
setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER); setDisplayName(Tr::tr("Valgrind"));
setWidgetCreator([] { return new ValgrindConfigWidget(ValgrindGlobalSettings::instance()); }); setCategory("T.Analyzer");
} setDisplayCategory(::Debugger::Tr::tr("Analyzer"));
setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
setWidgetCreator([] { return new ValgrindConfigWidget(&globalSettings()); });
}
};
QWidget *ValgrindOptionsPage::createSettingsWidget(ValgrindBaseSettings *settings) const ValgrindOptionsPage settingsPage;
QWidget *createSettingsWidget(ValgrindBaseSettings *settings)
{ {
return new ValgrindConfigWidget(settings); return new ValgrindConfigWidget(settings);
} }
} // namespace Internal } // Valgrind::Internal
} // namespace Valgrind

View File

@@ -7,12 +7,6 @@
namespace Valgrind::Internal { namespace Valgrind::Internal {
class ValgrindOptionsPage final : public Core::IOptionsPage QWidget *createSettingsWidget(class ValgrindBaseSettings *settings);
{
public:
ValgrindOptionsPage();
static QWidget *createSettingsWidget(class ValgrindBaseSettings *settings);
};
} // Valgrind::Internal } // Valgrind::Internal

View File

@@ -7,7 +7,6 @@
#include "valgrindsettings.h" #include "valgrindsettings.h"
#include "valgrindtr.h" #include "valgrindtr.h"
#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/icontext.h> #include <coreplugin/icontext.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -34,7 +33,7 @@ public:
ValgrindRunConfigurationAspect(Target *) ValgrindRunConfigurationAspect(Target *)
{ {
setProjectSettings(new ValgrindProjectSettings); setProjectSettings(new ValgrindProjectSettings);
setGlobalSettings(ValgrindGlobalSettings::instance()); setGlobalSettings(&globalSettings());
setId(ANALYZER_VALGRIND_SETTINGS); setId(ANALYZER_VALGRIND_SETTINGS);
setDisplayName(Tr::tr("Valgrind Settings")); setDisplayName(Tr::tr("Valgrind Settings"));
setUsingGlobalSettings(true); setUsingGlobalSettings(true);
@@ -46,10 +45,8 @@ public:
class ValgrindPluginPrivate class ValgrindPluginPrivate
{ {
public: public:
ValgrindGlobalSettings valgrindGlobalSettings; // Needs to come before the tools.
MemcheckTool memcheckTool; MemcheckTool memcheckTool;
CallgrindTool callgrindTool; CallgrindTool callgrindTool;
ValgrindOptionsPage valgrindOptionsPage;
}; };
class ValgrindPlugin final : public ExtensionSystem::IPlugin class ValgrindPlugin final : public ExtensionSystem::IPlugin

View File

@@ -59,18 +59,16 @@ void SuppressionAspect::addSuppressionFile(const FilePath &suppression)
void SuppressionAspectPrivate::slotAddSuppression() void SuppressionAspectPrivate::slotAddSuppression()
{ {
ValgrindGlobalSettings *conf = ValgrindGlobalSettings::instance();
QTC_ASSERT(conf, return);
const FilePaths files = const FilePaths files =
FileUtils::getOpenFilePaths(nullptr, FileUtils::getOpenFilePaths(nullptr,
Tr::tr("Valgrind Suppression Files"), Tr::tr("Valgrind Suppression Files"),
conf->lastSuppressionDirectory(), globalSettings().lastSuppressionDirectory(),
Tr::tr("Valgrind Suppression File (*.supp);;All Files (*)")); Tr::tr("Valgrind Suppression File (*.supp);;All Files (*)"));
//dialog.setHistory(conf->lastSuppressionDialogHistory()); //dialog.setHistory(conf->lastSuppressionDialogHistory());
if (!files.isEmpty()) { if (!files.isEmpty()) {
for (const FilePath &file : files) for (const FilePath &file : files)
m_model.appendRow(new QStandardItem(file.toString())); m_model.appendRow(new QStandardItem(file.toString()));
conf->lastSuppressionDirectory.setValue(files.at(0).absolutePath()); globalSettings().lastSuppressionDirectory.setValue(files.at(0).absolutePath());
//conf->setLastSuppressionDialogHistory(dialog.history()); //conf->setLastSuppressionDialogHistory(dialog.history());
if (!isGlobal) if (!isGlobal)
q->apply(); q->apply();
@@ -327,13 +325,15 @@ ValgrindBaseSettings::ValgrindBaseSettings(bool global)
// //
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
static ValgrindGlobalSettings *theGlobalSettings = nullptr; ValgrindGlobalSettings &globalSettings()
{
static ValgrindGlobalSettings theSettings;
return theSettings;
}
ValgrindGlobalSettings::ValgrindGlobalSettings() ValgrindGlobalSettings::ValgrindGlobalSettings()
: ValgrindBaseSettings(true) : ValgrindBaseSettings(true)
{ {
theGlobalSettings = this;
const QString base = "Analyzer.Valgrind"; const QString base = "Analyzer.Valgrind";
lastSuppressionDirectory.setSettingsKey(base + "LastSuppressionDirectory"); lastSuppressionDirectory.setSettingsKey(base + "LastSuppressionDirectory");
@@ -355,17 +355,12 @@ ValgrindGlobalSettings::ValgrindGlobalSettings()
shortenTemplates.setLabelText("<>"); // FIXME: Create a real icon shortenTemplates.setLabelText("<>"); // FIXME: Create a real icon
shortenTemplates.setToolTip(Tr::tr("Remove template parameter lists when displaying function names.")); shortenTemplates.setToolTip(Tr::tr("Remove template parameter lists when displaying function names."));
setConfigWidgetCreator([this] { return ValgrindOptionsPage::createSettingsWidget(this); }); setConfigWidgetCreator([this] { return createSettingsWidget(this); });
readSettings(); readSettings();
setAutoApply(false); setAutoApply(false);
} }
ValgrindGlobalSettings *ValgrindGlobalSettings::instance()
{
return theGlobalSettings;
}
// //
// Memcheck // Memcheck
// //
@@ -417,7 +412,7 @@ void ValgrindGlobalSettings::writeSettings() const
ValgrindProjectSettings::ValgrindProjectSettings() ValgrindProjectSettings::ValgrindProjectSettings()
: ValgrindBaseSettings(false) : ValgrindBaseSettings(false)
{ {
setConfigWidgetCreator([this] { return ValgrindOptionsPage::createSettingsWidget(this); }); setConfigWidgetCreator([this] { return createSettingsWidget(this); });
connect(this, &AspectContainer::fromMapFinished, [this] { connect(this, &AspectContainer::fromMapFinished, [this] {
// FIXME: Update project page e.g. on "Restore Global", aspects // FIXME: Update project page e.g. on "Restore Global", aspects

View File

@@ -111,8 +111,6 @@ class ValgrindGlobalSettings : public ValgrindBaseSettings
public: public:
ValgrindGlobalSettings(); ValgrindGlobalSettings();
static ValgrindGlobalSettings *instance();
/** /**
* Global memcheck settings * Global memcheck settings
*/ */
@@ -132,6 +130,8 @@ public:
Utils::BoolAspect shortenTemplates{this}; Utils::BoolAspect shortenTemplates{this};
}; };
ValgrindGlobalSettings &globalSettings();
/** /**
* Per-project valgrind settings. * Per-project valgrind settings.