2011-03-04 12:15:18 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator Instrumentation Tools
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
** Author: Milian Wolff, KDAB (milian.wolff@kdab.com)
|
|
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-03-04 12:15:18 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "analyzersettings.h"
|
|
|
|
|
|
|
|
|
|
#include "analyzermanager.h"
|
|
|
|
|
#include "ianalyzertool.h"
|
|
|
|
|
#include "analyzerplugin.h"
|
|
|
|
|
#include "analyzeroptionspage.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
using namespace Analyzer::Internal;
|
|
|
|
|
|
2011-04-19 15:42:14 +02:00
|
|
|
static const char groupC[] = "Analyzer";
|
2011-07-25 20:16:29 +02:00
|
|
|
static const char useGlobalC[] = "Analyzer.Project.UseGlobal";
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2011-05-18 15:56:01 +02:00
|
|
|
namespace Analyzer {
|
|
|
|
|
|
2011-03-04 12:15:18 +01:00
|
|
|
AnalyzerGlobalSettings *AnalyzerGlobalSettings::m_instance = 0;
|
|
|
|
|
|
2011-03-04 16:00:01 +01:00
|
|
|
AnalyzerSettings::AnalyzerSettings(QObject *parent)
|
2011-05-18 15:56:01 +02:00
|
|
|
: QObject(parent)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-20 14:42:57 +02:00
|
|
|
AnalyzerSettings::AnalyzerSettings(AnalyzerSettings *other)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-25 20:16:29 +02:00
|
|
|
QVariantMap AnalyzerSettings::defaults() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map;
|
|
|
|
|
foreach (AbstractAnalyzerSubConfig *config, subConfigs()) {
|
|
|
|
|
map.unite(config->defaults());
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-22 12:36:39 +01:00
|
|
|
void AnalyzerSettings::fromMap(const QVariantMap &map)
|
2011-07-25 20:16:29 +02:00
|
|
|
{
|
2012-02-22 12:36:39 +01:00
|
|
|
fromMap(map, &m_subConfigs);
|
2011-07-25 20:16:29 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-22 12:36:39 +01:00
|
|
|
void AnalyzerSettings::fromMap(const QVariantMap &map, QList<AbstractAnalyzerSubConfig *> *subConfigs)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2012-02-22 12:36:39 +01:00
|
|
|
foreach (AbstractAnalyzerSubConfig *config, *subConfigs)
|
|
|
|
|
config->fromMap(map);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2011-07-25 20:16:29 +02:00
|
|
|
QVariantMap AnalyzerSettings::toMap() const
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2011-07-25 20:16:29 +02:00
|
|
|
return toMap(m_subConfigs);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2011-07-25 20:16:29 +02:00
|
|
|
QVariantMap AnalyzerSettings::toMap(const QList<AbstractAnalyzerSubConfig *> &subConfigs) const
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
QVariantMap map;
|
2011-07-25 20:16:29 +02:00
|
|
|
foreach (AbstractAnalyzerSubConfig *config, subConfigs) {
|
2011-03-04 12:15:18 +01:00
|
|
|
map.unite(config->toMap());
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 11:15:23 +01:00
|
|
|
|
2011-03-04 16:00:01 +01:00
|
|
|
AnalyzerGlobalSettings::AnalyzerGlobalSettings(QObject *parent)
|
|
|
|
|
: AnalyzerSettings(parent)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!m_instance, return);
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AnalyzerGlobalSettings *AnalyzerGlobalSettings::instance()
|
|
|
|
|
{
|
|
|
|
|
if (!m_instance)
|
2011-03-04 16:00:01 +01:00
|
|
|
m_instance = new AnalyzerGlobalSettings(AnalyzerPlugin::instance());
|
|
|
|
|
|
2011-03-04 12:15:18 +01:00
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AnalyzerGlobalSettings::~AnalyzerGlobalSettings()
|
|
|
|
|
{
|
|
|
|
|
m_instance = 0;
|
2011-07-25 20:16:29 +02:00
|
|
|
qDeleteAll(m_subConfigs);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnalyzerGlobalSettings::readSettings()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
QVariantMap map;
|
|
|
|
|
|
2011-04-19 15:42:14 +02:00
|
|
|
settings->beginGroup(QLatin1String(groupC));
|
2011-03-04 12:15:18 +01:00
|
|
|
// read the values from config, using the keys from the defaults value map
|
|
|
|
|
const QVariantMap def = defaults();
|
|
|
|
|
for (QVariantMap::ConstIterator it = def.constBegin(); it != def.constEnd(); ++it)
|
|
|
|
|
map.insert(it.key(), settings->value(it.key(), it.value()));
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
|
|
|
|
|
// apply the values to our member variables
|
|
|
|
|
fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnalyzerGlobalSettings::writeSettings() const
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2011-04-19 15:42:14 +02:00
|
|
|
settings->beginGroup(QLatin1String(groupC));
|
2011-03-04 12:15:18 +01:00
|
|
|
const QVariantMap map = toMap();
|
|
|
|
|
for (QVariantMap::ConstIterator it = map.begin(); it != map.end(); ++it)
|
|
|
|
|
settings->setValue(it.key(), it.value());
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 11:15:23 +01:00
|
|
|
void AnalyzerGlobalSettings::registerTool(IAnalyzerTool *tool)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2011-12-28 11:15:23 +01:00
|
|
|
AbstractAnalyzerSubConfig *config = tool->createGlobalSettings();
|
|
|
|
|
if (config) {
|
|
|
|
|
m_subConfigs.append(config);
|
|
|
|
|
AnalyzerPlugin::instance()->addAutoReleasedObject(new AnalyzerOptionsPage(config));
|
|
|
|
|
readSettings();
|
|
|
|
|
}
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-09-20 18:18:44 +02:00
|
|
|
AnalyzerRunConfigurationAspect::AnalyzerRunConfigurationAspect()
|
2012-09-20 14:42:57 +02:00
|
|
|
: AnalyzerSettings((QObject *)0), m_useGlobalSettings(true)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2011-12-28 11:15:23 +01:00
|
|
|
QList<IAnalyzerTool*> tools = AnalyzerManager::tools();
|
2011-03-04 12:15:18 +01:00
|
|
|
// add sub configs
|
2011-12-28 11:15:23 +01:00
|
|
|
foreach (IAnalyzerTool *tool, tools) {
|
|
|
|
|
AbstractAnalyzerSubConfig *config = tool->createProjectSettings();
|
|
|
|
|
if (config)
|
|
|
|
|
m_customConfigurations.append(config);
|
2011-07-25 20:16:29 +02:00
|
|
|
}
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2011-07-25 20:16:29 +02:00
|
|
|
m_subConfigs = AnalyzerGlobalSettings::instance()->subConfigs();
|
|
|
|
|
resetCustomToGlobalSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-20 14:42:57 +02:00
|
|
|
AnalyzerRunConfigurationAspect::AnalyzerRunConfigurationAspect(AnalyzerRunConfigurationAspect *other)
|
|
|
|
|
: AnalyzerSettings(other), m_useGlobalSettings(other->m_useGlobalSettings)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (AbstractAnalyzerSubConfig *config, other->m_customConfigurations)
|
|
|
|
|
m_customConfigurations.append(config->clone());
|
|
|
|
|
|
|
|
|
|
if (m_useGlobalSettings)
|
|
|
|
|
m_subConfigs = AnalyzerGlobalSettings::instance()->subConfigs();
|
|
|
|
|
else
|
|
|
|
|
m_subConfigs = m_customConfigurations;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-23 14:41:28 +01:00
|
|
|
AnalyzerRunConfigurationAspect::~AnalyzerRunConfigurationAspect()
|
2011-07-25 20:16:29 +02:00
|
|
|
{
|
|
|
|
|
qDeleteAll(m_customConfigurations);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-23 14:41:28 +01:00
|
|
|
QString AnalyzerRunConfigurationAspect::displayName() const
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
return tr("Analyzer Settings");
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-23 14:41:28 +01:00
|
|
|
void AnalyzerRunConfigurationAspect::fromMap(const QVariantMap &map)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2012-02-22 12:36:39 +01:00
|
|
|
AnalyzerSettings::fromMap(map, &m_customConfigurations);
|
2011-07-25 20:16:29 +02:00
|
|
|
m_useGlobalSettings = map.value(QLatin1String(useGlobalC), true).toBool();
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-23 14:41:28 +01:00
|
|
|
QVariantMap AnalyzerRunConfigurationAspect::toMap() const
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2011-07-25 20:16:29 +02:00
|
|
|
QVariantMap map = AnalyzerSettings::toMap(m_customConfigurations);
|
|
|
|
|
map.insert(QLatin1String(useGlobalC), m_useGlobalSettings);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-23 14:41:28 +01:00
|
|
|
void AnalyzerRunConfigurationAspect::setUsingGlobalSettings(bool value)
|
2011-07-25 20:16:29 +02:00
|
|
|
{
|
|
|
|
|
if (value == m_useGlobalSettings)
|
|
|
|
|
return;
|
|
|
|
|
m_useGlobalSettings = value;
|
|
|
|
|
if (m_useGlobalSettings) {
|
|
|
|
|
m_subConfigs = AnalyzerGlobalSettings::instance()->subConfigs();
|
|
|
|
|
} else {
|
|
|
|
|
m_subConfigs = m_customConfigurations;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-23 14:41:28 +01:00
|
|
|
void AnalyzerRunConfigurationAspect::resetCustomToGlobalSettings()
|
2011-07-25 20:16:29 +02:00
|
|
|
{
|
|
|
|
|
AnalyzerGlobalSettings *gs = AnalyzerGlobalSettings::instance();
|
|
|
|
|
AnalyzerSettings::fromMap(gs->toMap(), &m_customConfigurations);
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
2011-05-18 15:56:01 +02:00
|
|
|
|
|
|
|
|
} // namespace Analyzer
|