Commit 5fa7b60b authored by hjk's avatar hjk

Analyzer: Cleanup settings handling

More flexible, less over-engineered this way.

Change-Id: I3e224a6be85d3a187056d79fd506e8cf6a32c8a9
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 2d4afd04
......@@ -12,7 +12,6 @@ SOURCES += \
analyzerruncontrol.cpp \
analyzermanager.cpp \
analyzersettings.cpp \
analyzeroptionspage.cpp \
analyzerrunconfigwidget.cpp \
analyzerutils.cpp \
startremotedialog.cpp
......@@ -26,7 +25,6 @@ HEADERS += \
analyzermanager.h \
analyzersettings.h \
analyzerstartparameters.h \
analyzeroptionspage.h \
analyzerrunconfigwidget.h \
analyzerutils.h \
startremotedialog.h
......
......@@ -18,8 +18,6 @@ QtcPlugin {
"analyzerconstants.h",
"analyzermanager.cpp",
"analyzermanager.h",
"analyzeroptionspage.cpp",
"analyzeroptionspage.h",
"analyzerplugin.cpp",
"analyzerplugin.h",
"analyzerrunconfigwidget.cpp",
......
......@@ -632,8 +632,8 @@ void AnalyzerManager::extensionsInitialized()
void AnalyzerManager::shutdown()
{
QTC_ASSERT(d->m_currentAction, return);
d->saveToolSettings(d->m_currentAction);
if (d->m_currentAction)
d->saveToolSettings(d->m_currentAction);
}
void AnalyzerManager::addAction(AnalyzerAction *action)
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "analyzeroptionspage.h"
#include "analyzersettings.h"
#include <QCoreApplication>
#include <QDebug>
#include <QWidget>
using namespace Analyzer;
using namespace Analyzer::Internal;
AnalyzerOptionsPage::AnalyzerOptionsPage(AbstractAnalyzerSubConfig *config, QObject *parent) :
Core::IOptionsPage(parent),
m_config(config)
{
setId(m_config->id());
setDisplayName(m_config->displayName());
setCategory("T.Analyzer");
setDisplayCategory(QCoreApplication::translate("Analyzer", "Analyzer"));
setCategoryIcon(QLatin1String(":/images/analyzer_category.png"));
}
QWidget *AnalyzerOptionsPage::createPage(QWidget *parent)
{
return m_config->createConfigWidget(parent);
}
void AnalyzerOptionsPage::apply()
{
AnalyzerGlobalSettings::instance()->writeSettings();
}
void AnalyzerOptionsPage::finish()
{
}
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef ANALYZER_INTERNAL_ANALYZEROPTIONSPAGE_H
#define ANALYZER_INTERNAL_ANALYZEROPTIONSPAGE_H
#include <coreplugin/dialogs/ioptionspage.h>
namespace Analyzer {
class AbstractAnalyzerSubConfig;
namespace Internal {
class AnalyzerOptionsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
explicit AnalyzerOptionsPage(AbstractAnalyzerSubConfig *config, QObject *parent = 0);
QWidget *createPage(QWidget *parent);
void apply();
void finish();
private:
AbstractAnalyzerSubConfig *m_config;
};
} // namespace Internal
} // namespace Analyzer
#endif // ANALYZER_INTERNAL_ANALYZEROPTIONSPAGE_H
......@@ -30,6 +30,7 @@
#include "analyzerrunconfigwidget.h"
#include <utils/detailswidget.h>
#include <utils/qtcassert.h>
#include <QDebug>
......@@ -42,30 +43,15 @@
namespace Analyzer {
namespace Internal {
AnalyzerToolDetailWidget::AnalyzerToolDetailWidget(AbstractAnalyzerSubConfig *config, QWidget *parent)
: Utils::DetailsWidget(parent)
AnalyzerRunConfigWidget::AnalyzerRunConfigWidget(AnalyzerRunConfigurationAspect *aspect)
{
QTC_ASSERT(config!=0, return);
// update summary text
setSummaryText(tr("<strong>%1</strong> settings").arg(config->displayName()));
// create config widget
QWidget *configWidget = config->createConfigWidget(this);
setWidget(configWidget);
}
AnalyzerRunConfigWidget::AnalyzerRunConfigWidget()
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_aspect = aspect;
m_config = aspect->customSubConfig();
QWidget *globalSetting = new QWidget(this);
QWidget *globalSetting = new QWidget;
QHBoxLayout *globalSettingLayout = new QHBoxLayout(globalSetting);
globalSettingLayout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(globalSetting);
QLabel *label = new QLabel(tr("Analyzer settings:"), globalSetting);
globalSettingLayout->addWidget(label);
m_settingsCombo = new QComboBox(globalSetting);
m_settingsCombo->addItems(QStringList()
<< QApplication::translate("ProjectExplorer::Internal::EditorSettingsPropertiesPage", "Global")
......@@ -80,45 +66,41 @@ AnalyzerRunConfigWidget::AnalyzerRunConfigWidget()
connect(m_restoreButton, SIGNAL(clicked()), this, SLOT(restoreGlobal()));
globalSettingLayout->addStretch(2);
m_subConfigWidget = new QWidget(this);
QVBoxLayout *subConfigLayout = new QVBoxLayout(m_subConfigWidget);
subConfigLayout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_subConfigWidget);
}
QWidget *innerPane = new QWidget;
m_configWidget = m_config->createConfigWidget(innerPane);
QString AnalyzerRunConfigWidget::displayName() const
{
return tr("Analyzer Settings");
}
QVBoxLayout *layout = new QVBoxLayout(innerPane);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(globalSetting);
layout->addWidget(m_configWidget);
void AnalyzerRunConfigWidget::setRunConfigurationAspect(AnalyzerRunConfigurationAspect *aspect)
{
QTC_ASSERT(aspect, return);
m_aspect = aspect;
m_details = new Utils::DetailsWidget;
m_details->setWidget(innerPane);
// add config widget for each sub config
foreach (AbstractAnalyzerSubConfig *config, m_aspect->customSubConfigs()) {
QWidget *widget = new AnalyzerToolDetailWidget(config);
m_subConfigWidget->layout()->addWidget(widget);
}
setDetailEnabled(!m_aspect->isUsingGlobalSettings());
m_settingsCombo->setCurrentIndex(m_aspect->isUsingGlobalSettings() ? 0 : 1);
m_restoreButton->setEnabled(!m_aspect->isUsingGlobalSettings());
QVBoxLayout *outerLayout = new QVBoxLayout(this);
outerLayout->addWidget(m_details);
outerLayout->setContentsMargins(0, 0, 0, 0);
chooseSettings(m_aspect->isUsingGlobalSettings() ? 0 : 1);
}
void AnalyzerRunConfigWidget::setDetailEnabled(bool value)
QString AnalyzerRunConfigWidget::displayName() const
{
QList<AnalyzerToolDetailWidget*> details = findChildren<AnalyzerToolDetailWidget*>();
foreach (AnalyzerToolDetailWidget *detail, details)
detail->widget()->setEnabled(value);
return m_aspect->displayName();
}
void AnalyzerRunConfigWidget::chooseSettings(int setting)
{
QTC_ASSERT(m_aspect, return);
setDetailEnabled(setting != 0);
m_aspect->setUsingGlobalSettings(setting == 0);
m_restoreButton->setEnabled(!m_aspect->isUsingGlobalSettings());
bool isCustom = (setting == 1);
m_settingsCombo->setCurrentIndex(setting);
m_aspect->setUsingGlobalSettings(!isCustom);
m_configWidget->setEnabled(isCustom);
m_restoreButton->setEnabled(isCustom);
m_details->setSummaryText(isCustom
? tr("Use <strong>Customized Settings<strong>")
: tr("Use <strong>Global Settings<strong>"));
}
void AnalyzerRunConfigWidget::restoreGlobal()
......
......@@ -33,54 +33,36 @@
#include "analyzersettings.h"
#include <utils/detailswidget.h>
QT_BEGIN_NAMESPACE
class QComboBox;
class QPushButton;
QT_END_NAMESPACE
namespace Utils {
class DetailsWidget;
}
namespace Utils { class DetailsWidget; }
namespace Analyzer {
class AbstractAnalyzerSubConfig;
namespace Internal {
class AnalyzerToolDetailWidget : public Utils::DetailsWidget
{
Q_OBJECT
public:
explicit AnalyzerToolDetailWidget(AbstractAnalyzerSubConfig *config, QWidget *parent=0);
};
class AnalyzerRunConfigWidget : public ProjectExplorer::RunConfigWidget
{
Q_OBJECT
public:
AnalyzerRunConfigWidget();
AnalyzerRunConfigWidget(AnalyzerRunConfigurationAspect *aspect);
virtual QString displayName() const;
void setRunConfigurationAspect(AnalyzerRunConfigurationAspect *aspect);
private:
void setDetailEnabled(bool value);
QString displayName() const;
private slots:
void chooseSettings(int setting);
void restoreGlobal();
private:
QWidget *m_subConfigWidget;
QWidget *m_configWidget;
AnalyzerRunConfigurationAspect *m_aspect;
AbstractAnalyzerSubConfig *m_config;
QComboBox *m_settingsCombo;
QPushButton *m_restoreButton;
Utils::DetailsWidget *m_details;
};
} // namespace Internal
......
......@@ -34,7 +34,6 @@
#include "analyzerrunconfigwidget.h"
#include "ianalyzertool.h"
#include "analyzerplugin.h"
#include "analyzeroptionspage.h"
#include <coreplugin/icore.h>
#include <utils/qtcassert.h>
......@@ -43,168 +42,38 @@
using namespace Analyzer::Internal;
static const char groupC[] = "Analyzer";
static const char useGlobalC[] = "Analyzer.Project.UseGlobal";
namespace Analyzer {
AnalyzerGlobalSettings *AnalyzerGlobalSettings::m_instance = 0;
AnalyzerSettings::AnalyzerSettings(QObject *parent)
: QObject(parent)
{
}
AnalyzerSettings::AnalyzerSettings(const AnalyzerSettings *other)
{
Q_UNUSED(other);
}
QVariantMap AnalyzerSettings::defaults() const
{
QVariantMap map;
foreach (AbstractAnalyzerSubConfig *config, subConfigs()) {
map.unite(config->defaults());
}
return map;
}
void AnalyzerSettings::fromMap(const QVariantMap &map)
{
fromMap(map, &m_subConfigs);
}
void AnalyzerSettings::fromMap(const QVariantMap &map, QList<AbstractAnalyzerSubConfig *> *subConfigs)
{
foreach (AbstractAnalyzerSubConfig *config, *subConfigs)
config->fromMap(map);
}
QVariantMap AnalyzerSettings::toMap() const
{
return toMap(m_subConfigs);
}
QVariantMap AnalyzerSettings::toMap(const QList<AbstractAnalyzerSubConfig *> &subConfigs) const
{
QVariantMap map;
foreach (AbstractAnalyzerSubConfig *config, subConfigs) {
map.unite(config->toMap());
}
return map;
}
AnalyzerGlobalSettings::AnalyzerGlobalSettings(QObject *parent)
: AnalyzerSettings(parent)
{
QTC_ASSERT(!m_instance, return);
m_instance = this;
}
AnalyzerGlobalSettings *AnalyzerGlobalSettings::instance()
{
if (!m_instance)
m_instance = new AnalyzerGlobalSettings(AnalyzerPlugin::instance());
return m_instance;
}
AnalyzerGlobalSettings::~AnalyzerGlobalSettings()
{
m_instance = 0;
qDeleteAll(m_subConfigs);
}
void AnalyzerGlobalSettings::readSettings()
{
QSettings *settings = Core::ICore::settings();
QVariantMap map;
settings->beginGroup(QLatin1String(groupC));
// 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
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(groupC));
const QVariantMap map = toMap();
for (QVariantMap::ConstIterator it = map.begin(); it != map.end(); ++it)
settings->setValue(it.key(), it.value());
settings->endGroup();
}
void AnalyzerGlobalSettings::registerConfig(AbstractAnalyzerSubConfig *config)
{
instance()->m_subConfigs.append(config);
AnalyzerPlugin::instance()->addAutoReleasedObject(new AnalyzerOptionsPage(config));
m_instance->readSettings();
}
static QList<AnalyzerSubConfigFactory *> &theAnalyzerSubConfigFactories()
AnalyzerRunConfigurationAspect::AnalyzerRunConfigurationAspect(
AbstractAnalyzerSubConfig *customConfiguration,
AbstractAnalyzerSubConfig *globalConfiguration)
{
static QList<AnalyzerSubConfigFactory *> theFactories;
return theFactories;
m_useGlobalSettings = true;
m_customConfiguration = customConfiguration;
m_globalConfiguration = globalConfiguration;
}
AnalyzerRunConfigurationAspect::AnalyzerRunConfigurationAspect()
: AnalyzerSettings((QObject *)0), m_useGlobalSettings(true)
AbstractAnalyzerSubConfig *AnalyzerRunConfigurationAspect::currentConfig() const
{
// add sub configs
foreach (AnalyzerSubConfigFactory *factory, theAnalyzerSubConfigFactories())
m_customConfigurations.append(factory->createProjectSettings());
m_subConfigs = AnalyzerGlobalSettings::instance()->subConfigs();
resetCustomToGlobalSettings();
}
AnalyzerRunConfigurationAspect::AnalyzerRunConfigurationAspect(const 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;
return m_useGlobalSettings ? m_globalConfiguration : m_customConfiguration;
}
AnalyzerRunConfigurationAspect::~AnalyzerRunConfigurationAspect()
{
qDeleteAll(m_customConfigurations);
}
void AnalyzerRunConfigurationAspect::registerConfigFactory(AnalyzerSubConfigFactory *factory)
{
theAnalyzerSubConfigFactories().append(factory);
}
QString AnalyzerRunConfigurationAspect::displayName() const
{
return tr("Analyzer Settings");
delete m_customConfiguration;
}
void AnalyzerRunConfigurationAspect::fromMap(const QVariantMap &map)
{
AnalyzerSettings::fromMap(map, &m_customConfigurations);
m_customConfiguration->fromMap(map);
m_useGlobalSettings = map.value(QLatin1String(useGlobalC), true).toBool();
}
QVariantMap AnalyzerRunConfigurationAspect::toMap() const
{
QVariantMap map = AnalyzerSettings::toMap(m_customConfigurations);
QVariantMap map = m_customConfiguration->toMap();
map.insert(QLatin1String(useGlobalC), m_useGlobalSettings);
return map;
}
......@@ -213,31 +82,27 @@ AnalyzerRunConfigurationAspect *AnalyzerRunConfigurationAspect::clone(
ProjectExplorer::RunConfiguration *parent) const
{
Q_UNUSED(parent)
return new AnalyzerRunConfigurationAspect(this);
AnalyzerRunConfigurationAspect *other
= new AnalyzerRunConfigurationAspect(m_customConfiguration->clone(), m_globalConfiguration);
other->m_useGlobalSettings = m_useGlobalSettings;
return other;
}
void AnalyzerRunConfigurationAspect::setUsingGlobalSettings(bool value)
{
if (value == m_useGlobalSettings)
return;
m_useGlobalSettings = value;
if (m_useGlobalSettings)
m_subConfigs = AnalyzerGlobalSettings::instance()->subConfigs();
else
m_subConfigs = m_customConfigurations;
}
void AnalyzerRunConfigurationAspect::resetCustomToGlobalSettings()
{
AnalyzerGlobalSettings *gs = AnalyzerGlobalSettings::instance();
AnalyzerSettings::fromMap(gs->toMap(), &m_customConfigurations);
AbstractAnalyzerSubConfig *global = globalSubConfig();
QTC_ASSERT(global, return);
m_customConfiguration->fromMap(global->toMap());
}
ProjectExplorer::RunConfigWidget *AnalyzerRunConfigurationAspect::createConfigurationWidget()
{
AnalyzerRunConfigWidget *ret = new AnalyzerRunConfigWidget;
ret->setRunConfigurationAspect(this);
return ret;
return new AnalyzerRunConfigWidget(this);
}
} // namespace Analyzer
......@@ -62,101 +62,17 @@ class ANALYZER_EXPORT AbstractAnalyzerSubConfig : public QObject
public:
AbstractAnalyzerSubConfig() {}
/// return a list of default values
virtual QVariantMap defaults() const = 0;
/// convert current configuration into map for storage
virtual QVariantMap toMap() const = 0;
/// read configuration from @p map
virtual void fromMap(const QVariantMap &map) = 0;
/// unique ID for this configuration
virtual Core::Id id() const = 0;
/// user readable display name for this configuration
virtual QString displayName() const = 0;
/// create a configuration widget for this configuration
virtual QWidget *createConfigWidget(QWidget *parent) = 0;
/// clones s AbstractAnalyzerSubConfig
virtual AbstractAnalyzerSubConfig *clone() = 0;
};
class ANALYZER_EXPORT AnalyzerSubConfigFactory : public QObject
{
Q_OBJECT
public:
AnalyzerSubConfigFactory() {}
/// Factory method to create the project tool setting
virtual AbstractAnalyzerSubConfig *createProjectSettings() = 0;
};
/**
* Shared interface for the global and per-project settings.
*
* Use this to get the subConfig for your tool.
*/
class ANALYZER_EXPORT AnalyzerSettings : public QObject
{
Q_OBJECT
public:
template<class T>
T *subConfig() const
{
foreach (AbstractAnalyzerSubConfig *subConfig, subConfigs()) {
if (T *config = qobject_cast<T *>(subConfig))
return config;
}
return 0;
}
QList<AbstractAnalyzerSubConfig *> subConfigs() const