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 += \ ...@@ -12,7 +12,6 @@ SOURCES += \
analyzerruncontrol.cpp \ analyzerruncontrol.cpp \
analyzermanager.cpp \ analyzermanager.cpp \
analyzersettings.cpp \ analyzersettings.cpp \
analyzeroptionspage.cpp \
analyzerrunconfigwidget.cpp \ analyzerrunconfigwidget.cpp \
analyzerutils.cpp \ analyzerutils.cpp \
startremotedialog.cpp startremotedialog.cpp
...@@ -26,7 +25,6 @@ HEADERS += \ ...@@ -26,7 +25,6 @@ HEADERS += \
analyzermanager.h \ analyzermanager.h \
analyzersettings.h \ analyzersettings.h \
analyzerstartparameters.h \ analyzerstartparameters.h \
analyzeroptionspage.h \
analyzerrunconfigwidget.h \ analyzerrunconfigwidget.h \
analyzerutils.h \ analyzerutils.h \
startremotedialog.h startremotedialog.h
......
...@@ -18,8 +18,6 @@ QtcPlugin { ...@@ -18,8 +18,6 @@ QtcPlugin {
"analyzerconstants.h", "analyzerconstants.h",
"analyzermanager.cpp", "analyzermanager.cpp",
"analyzermanager.h", "analyzermanager.h",
"analyzeroptionspage.cpp",
"analyzeroptionspage.h",
"analyzerplugin.cpp", "analyzerplugin.cpp",
"analyzerplugin.h", "analyzerplugin.h",
"analyzerrunconfigwidget.cpp", "analyzerrunconfigwidget.cpp",
......
...@@ -632,8 +632,8 @@ void AnalyzerManager::extensionsInitialized() ...@@ -632,8 +632,8 @@ void AnalyzerManager::extensionsInitialized()
void AnalyzerManager::shutdown() void AnalyzerManager::shutdown()
{ {
QTC_ASSERT(d->m_currentAction, return); if (d->m_currentAction)
d->saveToolSettings(d->m_currentAction); d->saveToolSettings(d->m_currentAction);
} }
void AnalyzerManager::addAction(AnalyzerAction *action) 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 @@ ...@@ -30,6 +30,7 @@
#include "analyzerrunconfigwidget.h" #include "analyzerrunconfigwidget.h"
#include <utils/detailswidget.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QDebug> #include <QDebug>
...@@ -42,30 +43,15 @@ ...@@ -42,30 +43,15 @@
namespace Analyzer { namespace Analyzer {
namespace Internal { namespace Internal {
AnalyzerToolDetailWidget::AnalyzerToolDetailWidget(AbstractAnalyzerSubConfig *config, QWidget *parent) AnalyzerRunConfigWidget::AnalyzerRunConfigWidget(AnalyzerRunConfigurationAspect *aspect)
: Utils::DetailsWidget(parent)
{ {
QTC_ASSERT(config!=0, return); m_aspect = aspect;
m_config = aspect->customSubConfig();
// 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);
QWidget *globalSetting = new QWidget(this); QWidget *globalSetting = new QWidget;
QHBoxLayout *globalSettingLayout = new QHBoxLayout(globalSetting); QHBoxLayout *globalSettingLayout = new QHBoxLayout(globalSetting);
globalSettingLayout->setContentsMargins(0, 0, 0, 0); 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 = new QComboBox(globalSetting);
m_settingsCombo->addItems(QStringList() m_settingsCombo->addItems(QStringList()
<< QApplication::translate("ProjectExplorer::Internal::EditorSettingsPropertiesPage", "Global") << QApplication::translate("ProjectExplorer::Internal::EditorSettingsPropertiesPage", "Global")
...@@ -80,45 +66,41 @@ AnalyzerRunConfigWidget::AnalyzerRunConfigWidget() ...@@ -80,45 +66,41 @@ AnalyzerRunConfigWidget::AnalyzerRunConfigWidget()
connect(m_restoreButton, SIGNAL(clicked()), this, SLOT(restoreGlobal())); connect(m_restoreButton, SIGNAL(clicked()), this, SLOT(restoreGlobal()));
globalSettingLayout->addStretch(2); globalSettingLayout->addStretch(2);
m_subConfigWidget = new QWidget(this); QWidget *innerPane = new QWidget;
QVBoxLayout *subConfigLayout = new QVBoxLayout(m_subConfigWidget); m_configWidget = m_config->createConfigWidget(innerPane);
subConfigLayout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_subConfigWidget);
}
QString AnalyzerRunConfigWidget::displayName() const QVBoxLayout *layout = new QVBoxLayout(innerPane);
{ layout->setContentsMargins(0, 0, 0, 0);
return tr("Analyzer Settings"); layout->addWidget(globalSetting);
} layout->addWidget(m_configWidget);
void AnalyzerRunConfigWidget::setRunConfigurationAspect(AnalyzerRunConfigurationAspect *aspect) m_details = new Utils::DetailsWidget;
{ m_details->setWidget(innerPane);
QTC_ASSERT(aspect, return);
m_aspect = aspect;
// add config widget for each sub config QVBoxLayout *outerLayout = new QVBoxLayout(this);
foreach (AbstractAnalyzerSubConfig *config, m_aspect->customSubConfigs()) { outerLayout->addWidget(m_details);
QWidget *widget = new AnalyzerToolDetailWidget(config); outerLayout->setContentsMargins(0, 0, 0, 0);
m_subConfigWidget->layout()->addWidget(widget);
} chooseSettings(m_aspect->isUsingGlobalSettings() ? 0 : 1);
setDetailEnabled(!m_aspect->isUsingGlobalSettings());
m_settingsCombo->setCurrentIndex(m_aspect->isUsingGlobalSettings() ? 0 : 1);
m_restoreButton->setEnabled(!m_aspect->isUsingGlobalSettings());
} }
void AnalyzerRunConfigWidget::setDetailEnabled(bool value) QString AnalyzerRunConfigWidget::displayName() const
{ {
QList<AnalyzerToolDetailWidget*> details = findChildren<AnalyzerToolDetailWidget*>(); return m_aspect->displayName();
foreach (AnalyzerToolDetailWidget *detail, details)
detail->widget()->setEnabled(value);
} }
void AnalyzerRunConfigWidget::chooseSettings(int setting) void AnalyzerRunConfigWidget::chooseSettings(int setting)
{ {
QTC_ASSERT(m_aspect, return); QTC_ASSERT(m_aspect, return);
setDetailEnabled(setting != 0); bool isCustom = (setting == 1);
m_aspect->setUsingGlobalSettings(setting == 0);
m_restoreButton->setEnabled(!m_aspect->isUsingGlobalSettings()); 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() void AnalyzerRunConfigWidget::restoreGlobal()
......
...@@ -33,54 +33,36 @@ ...@@ -33,54 +33,36 @@
#include "analyzersettings.h" #include "analyzersettings.h"
#include <utils/detailswidget.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QComboBox; class QComboBox;
class QPushButton; class QPushButton;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Utils { namespace Utils { class DetailsWidget; }
class DetailsWidget;
}
namespace Analyzer { namespace Analyzer {
class AbstractAnalyzerSubConfig;
namespace Internal { namespace Internal {
class AnalyzerToolDetailWidget : public Utils::DetailsWidget
{
Q_OBJECT
public:
explicit AnalyzerToolDetailWidget(AbstractAnalyzerSubConfig *config, QWidget *parent=0);
};
class AnalyzerRunConfigWidget : public ProjectExplorer::RunConfigWidget class AnalyzerRunConfigWidget : public ProjectExplorer::RunConfigWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
AnalyzerRunConfigWidget(); AnalyzerRunConfigWidget(AnalyzerRunConfigurationAspect *aspect);
virtual QString displayName() const; QString displayName() const;
void setRunConfigurationAspect(AnalyzerRunConfigurationAspect *aspect);
private:
void setDetailEnabled(bool value);
private slots: private slots:
void chooseSettings(int setting); void chooseSettings(int setting);
void restoreGlobal(); void restoreGlobal();
private: private:
QWidget *m_subConfigWidget; QWidget *m_configWidget;
AnalyzerRunConfigurationAspect *m_aspect; AnalyzerRunConfigurationAspect *m_aspect;
AbstractAnalyzerSubConfig *m_config;
QComboBox *m_settingsCombo; QComboBox *m_settingsCombo;
QPushButton *m_restoreButton; QPushButton *m_restoreButton;
Utils::DetailsWidget *m_details;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "analyzerrunconfigwidget.h" #include "analyzerrunconfigwidget.h"
#include "ianalyzertool.h" #include "ianalyzertool.h"
#include "analyzerplugin.h" #include "analyzerplugin.h"
#include "analyzeroptionspage.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
...@@ -43,168 +42,38 @@ ...@@ -43,168 +42,38 @@
using namespace Analyzer::Internal; using namespace Analyzer::Internal;
static const char groupC[] = "Analyzer";
static const char useGlobalC[] = "Analyzer.Project.UseGlobal"; static const char useGlobalC[] = "Analyzer.Project.UseGlobal";
namespace Analyzer { namespace Analyzer {
AnalyzerGlobalSettings *AnalyzerGlobalSettings::m_instance = 0; AnalyzerRunConfigurationAspect::AnalyzerRunConfigurationAspect(
AbstractAnalyzerSubConfig *customConfiguration,
AnalyzerSettings::AnalyzerSettings(QObject *parent) AbstractAnalyzerSubConfig *globalConfiguration)
: 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()
{ {
static QList<AnalyzerSubConfigFactory *> theFactories; m_useGlobalSettings = true;
return theFactories; m_customConfiguration = customConfiguration;
m_globalConfiguration = globalConfiguration;
} }
AnalyzerRunConfigurationAspect::AnalyzerRunConfigurationAspect() AbstractAnalyzerSubConfig *AnalyzerRunConfigurationAspect::currentConfig() const
: AnalyzerSettings((QObject *)0), m_useGlobalSettings(true)
{ {
// add sub configs return m_useGlobalSettings ? m_globalConfiguration : m_customConfiguration;
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;
} }
AnalyzerRunConfigurationAspect::~AnalyzerRunConfigurationAspect() AnalyzerRunConfigurationAspect::~AnalyzerRunConfigurationAspect()
{ {
qDeleteAll(m_customConfigurations); delete m_customConfiguration;
}
void AnalyzerRunConfigurationAspect::registerConfigFactory(AnalyzerSubConfigFactory *factory)
{
theAnalyzerSubConfigFactories().append(factory);
}
QString AnalyzerRunConfigurationAspect::displayName() const
{
return tr("Analyzer Settings");
} }
void AnalyzerRunConfigurationAspect::fromMap(const QVariantMap &map) void AnalyzerRunConfigurationAspect::fromMap(const QVariantMap &map)
{ {
AnalyzerSettings::fromMap(map, &m_customConfigurations); m_customConfiguration->fromMap(map);
m_useGlobalSettings = map.value(QLatin1String(useGlobalC), true).toBool(); m_useGlobalSettings = map.value(QLatin1String(useGlobalC), true).toBool();
} }
QVariantMap AnalyzerRunConfigurationAspect::toMap() const QVariantMap AnalyzerRunConfigurationAspect::toMap() const
{ {
QVariantMap map = AnalyzerSettings::toMap(m_customConfigurations); QVariantMap map = m_customConfiguration->toMap();
map.insert(QLatin1String(useGlobalC), m_useGlobalSettings); map.insert(QLatin1String(useGlobalC), m_useGlobalSettings);
return map; return map;
} }
...@@ -213,31 +82,27 @@ AnalyzerRunConfigurationAspect *AnalyzerRunConfigurationAspect::clone( ...@@ -213,31 +82,27 @@ AnalyzerRunConfigurationAspect *AnalyzerRunConfigurationAspect::clone(
ProjectExplorer::RunConfiguration *parent) const ProjectExplorer::RunConfiguration *parent) const
{ {
Q_UNUSED(parent) Q_UNUSED(parent)