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();
ISettingsAspect *projectSettings() const { return m_projectSettings; }
ISettingsAspect *globalSettings() const { return m_globalSettings; }
ISettingsAspect *currentSettings() const;
struct Data : Utils::BaseAspect::Data

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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