Commit 9b19a9c8 authored by Nicolas Arnaud-Cormos's avatar Nicolas Arnaud-Cormos Committed by hjk
Browse files

Analyzer: refactor global and project tool settings usage.



IAnalyzerTool has now 2 new virtual methods used to create the global and per-project settings.
No need to create any static factory method and pass a pointer to them to the AnalyzerGlobalSettings
instance anymore.

The Valgrind plugin is now using it, the memchecktool creates the settings for all
valgrind tools.

Change-Id: I3c5845ceb7151130032cfff4ab5b7b36ca2459d9
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 4a843211
......@@ -41,6 +41,7 @@
#include "analyzerstartparameters.h"
#include "analyzerutils.h"
#include "ianalyzertool.h"
#include "analyzersettings.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/findplaceholder.h>
......@@ -809,6 +810,7 @@ void AnalyzerManager::shutdown()
void AnalyzerManager::addTool(IAnalyzerTool *tool, const StartModes &modes)
{
m_instance->d->addTool(tool, modes);
AnalyzerGlobalSettings::instance()->registerTool(tool);
}
QDockWidget *AnalyzerManager::createDockWidget(IAnalyzerTool *tool, const QString &title,
......@@ -829,6 +831,11 @@ IAnalyzerTool *AnalyzerManager::currentSelectedTool()
return m_instance->d->m_currentTool;
}
QList<IAnalyzerTool *> AnalyzerManager::tools()
{
return m_instance->d->m_tools;
}
void AnalyzerManager::selectTool(IAnalyzerTool *tool, StartMode mode)
{
m_instance->d->selectTool(tool, mode);
......
......@@ -82,6 +82,7 @@ public:
static void showMode();
static IAnalyzerTool *currentSelectedTool();
static QList<IAnalyzerTool *> tools();
static void selectTool(IAnalyzerTool *tool, StartMode mode);
static void startTool(IAnalyzerTool *tool, StartMode mode);
static void stopTool();
......
......@@ -95,6 +95,7 @@ QVariantMap AnalyzerSettings::toMap(const QList<AbstractAnalyzerSubConfig *> &su
return map;
}
AnalyzerGlobalSettings::AnalyzerGlobalSettings(QObject *parent)
: AnalyzerSettings(parent)
{
......@@ -143,30 +144,26 @@ void AnalyzerGlobalSettings::writeSettings() const
settings->endGroup();
}
void AnalyzerGlobalSettings::registerSubConfigs
(AnalyzerSubConfigFactory globalCreator, AnalyzerSubConfigFactory projectCreator)
void AnalyzerGlobalSettings::registerTool(IAnalyzerTool *tool)
{
m_projectSubConfigFactories.append(projectCreator);
AbstractAnalyzerSubConfig *config = globalCreator();
m_subConfigs.append(config);
AnalyzerPlugin::instance()->addAutoReleasedObject(new AnalyzerOptionsPage(config));
readSettings();
AbstractAnalyzerSubConfig *config = tool->createGlobalSettings();
if (config) {
m_subConfigs.append(config);
AnalyzerPlugin::instance()->addAutoReleasedObject(new AnalyzerOptionsPage(config));
readSettings();
}
}
QList<AnalyzerSubConfigFactory> AnalyzerGlobalSettings::projectSubConfigFactories() const
{
return m_projectSubConfigFactories;
}
AnalyzerProjectSettings::AnalyzerProjectSettings(QObject *parent)
: AnalyzerSettings(parent), m_useGlobalSettings(true)
{
QList<IAnalyzerTool*> tools = AnalyzerManager::tools();
// add sub configs
foreach (AnalyzerSubConfigFactory factory, AnalyzerGlobalSettings::instance()->projectSubConfigFactories()) {
AbstractAnalyzerSubConfig *config = factory();
m_customConfigurations.append(config);
foreach (IAnalyzerTool *tool, tools) {
AbstractAnalyzerSubConfig *config = tool->createProjectSettings();
if (config)
m_customConfigurations.append(config);
}
m_subConfigs = AnalyzerGlobalSettings::instance()->subConfigs();
......
......@@ -44,6 +44,8 @@
namespace Analyzer {
class IAnalyzerTool;
/**
* Utility function to set @p val if @p key is present in @p map.
*/
......@@ -121,8 +123,6 @@ protected:
};
typedef AbstractAnalyzerSubConfig *(*AnalyzerSubConfigFactory)();
// global and local settings are loaded and saved differently, and they also handle suppressions
// differently.
/**
......@@ -144,13 +144,11 @@ public:
void writeSettings() const;
void readSettings();
void registerSubConfigs(AnalyzerSubConfigFactory globalFactory, AnalyzerSubConfigFactory projectFactory);
QList<AnalyzerSubConfigFactory> projectSubConfigFactories() const;
void registerTool(IAnalyzerTool *tool);
private:
AnalyzerGlobalSettings(QObject *parent);
static AnalyzerGlobalSettings *m_instance;
QList<AnalyzerSubConfigFactory> m_projectSubConfigFactories;
};
/**
......
......@@ -70,4 +70,14 @@ QString IAnalyzerTool::defaultActionName(const IAnalyzerTool *tool, StartMode mo
return base;
}
AbstractAnalyzerSubConfig *IAnalyzerTool::createGlobalSettings()
{
return 0;
}
AbstractAnalyzerSubConfig *IAnalyzerTool::createProjectSettings()
{
return 0;
}
} // namespace Analyzer
......@@ -51,6 +51,7 @@ namespace Analyzer {
class IAnalyzerOutputPaneAdapter;
class IAnalyzerEngine;
class AbstractAnalyzerSubConfig;
/**
......@@ -137,6 +138,12 @@ public:
/// Called when tools gets deselected.
virtual void toolDeselected() const {}
/// Factory method to create the global tool setting
virtual AbstractAnalyzerSubConfig *createGlobalSettings();
/// Factory method to create the project tool setting
virtual AbstractAnalyzerSubConfig *createProjectSettings();
};
} // namespace Analyzer
......
......@@ -298,7 +298,17 @@ QString MemcheckTool::displayName() const
QString MemcheckTool::description() const
{
return tr("Valgrind Analyze Memory uses the \"memcheck\" tool to find "
"memory leaks");
"memory leaks");
}
AbstractAnalyzerSubConfig *MemcheckTool::createGlobalSettings()
{
return new ValgrindGlobalSettings();
}
AbstractAnalyzerSubConfig *MemcheckTool::createProjectSettings()
{
return new ValgrindProjectSettings();
}
IAnalyzerTool::ToolMode MemcheckTool::toolMode() const
......
......@@ -97,6 +97,10 @@ public:
QString displayName() const;
QString description() const;
// Create the valgrind settings (for all valgrind tools)
Analyzer::AbstractAnalyzerSubConfig *createGlobalSettings();
Analyzer::AbstractAnalyzerSubConfig *createProjectSettings();
private slots:
void settingsDestroyed(QObject *settings);
void maybeActiveRunConfigurationChanged();
......
......@@ -36,7 +36,6 @@
#include "callgrindtool.h"
#include "memchecktool.h"
#include "valgrindsettings.h"
#include <analyzerbase/analyzerconstants.h>
#include <analyzerbase/analyzermanager.h>
......@@ -96,20 +95,8 @@ void ValgrindPlugin::startValgrindTool(IAnalyzerTool *tool, StartMode mode)
startRemoteTool(tool);
}
static AbstractAnalyzerSubConfig *globalValgrindFactory()
{
return new ValgrindGlobalSettings();
}
static AbstractAnalyzerSubConfig *projectValgrindFactory()
{
return new ValgrindProjectSettings();
}
bool ValgrindPlugin::initialize(const QStringList &, QString *)
{
AnalyzerGlobalSettings::instance()->registerSubConfigs(&globalValgrindFactory, &projectValgrindFactory);
StartModes modes;
#ifndef Q_OS_WIN
modes.append(StartMode(StartLocal));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment