diff options
Diffstat (limited to 'src')
32 files changed, 279 insertions, 629 deletions
diff --git a/src/plugins/analyzerbase/analyzerbase.pro b/src/plugins/analyzerbase/analyzerbase.pro index 984d96ac51..d47654ea8c 100644 --- a/src/plugins/analyzerbase/analyzerbase.pro +++ b/src/plugins/analyzerbase/analyzerbase.pro @@ -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 diff --git a/src/plugins/analyzerbase/analyzerbase.qbs b/src/plugins/analyzerbase/analyzerbase.qbs index f981904132..d7db75e19a 100644 --- a/src/plugins/analyzerbase/analyzerbase.qbs +++ b/src/plugins/analyzerbase/analyzerbase.qbs @@ -18,8 +18,6 @@ QtcPlugin { "analyzerconstants.h", "analyzermanager.cpp", "analyzermanager.h", - "analyzeroptionspage.cpp", - "analyzeroptionspage.h", "analyzerplugin.cpp", "analyzerplugin.h", "analyzerrunconfigwidget.cpp", diff --git a/src/plugins/analyzerbase/analyzermanager.cpp b/src/plugins/analyzerbase/analyzermanager.cpp index 2abc7cfeea..189afb3560 100644 --- a/src/plugins/analyzerbase/analyzermanager.cpp +++ b/src/plugins/analyzerbase/analyzermanager.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) diff --git a/src/plugins/analyzerbase/analyzeroptionspage.cpp b/src/plugins/analyzerbase/analyzeroptionspage.cpp deleted file mode 100644 index a38da98f38..0000000000 --- a/src/plugins/analyzerbase/analyzeroptionspage.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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() -{ -} diff --git a/src/plugins/analyzerbase/analyzeroptionspage.h b/src/plugins/analyzerbase/analyzeroptionspage.h deleted file mode 100644 index e001148795..0000000000 --- a/src/plugins/analyzerbase/analyzeroptionspage.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** 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 diff --git a/src/plugins/analyzerbase/analyzerrunconfigwidget.cpp b/src/plugins/analyzerbase/analyzerrunconfigwidget.cpp index 196cb41c41..9b107672d1 100644 --- a/src/plugins/analyzerbase/analyzerrunconfigwidget.cpp +++ b/src/plugins/analyzerbase/analyzerrunconfigwidget.cpp @@ -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() diff --git a/src/plugins/analyzerbase/analyzerrunconfigwidget.h b/src/plugins/analyzerbase/analyzerrunconfigwidget.h index 43d3f89cb2..8224ce8fdc 100644 --- a/src/plugins/analyzerbase/analyzerrunconfigwidget.h +++ b/src/plugins/analyzerbase/analyzerrunconfigwidget.h @@ -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 diff --git a/src/plugins/analyzerbase/analyzersettings.cpp b/src/plugins/analyzerbase/analyzersettings.cpp index fc46b71172..d9cdd0163b 100644 --- a/src/plugins/analyzerbase/analyzersettings.cpp +++ b/src/plugins/analyzerbase/analyzersettings.cpp @@ -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 diff --git a/src/plugins/analyzerbase/analyzersettings.h b/src/plugins/analyzerbase/analyzersettings.h index 4562f806bd..04d7999072 100644 --- a/src/plugins/analyzerbase/analyzersettings.h +++ b/src/plugins/analyzerbase/analyzersettings.h @@ -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 - { - return m_subConfigs; - } - - QVariantMap defaults() const; - virtual QVariantMap toMap() const; - -protected: - virtual void fromMap(const QVariantMap &map); - - QVariantMap toMap(const QList<AbstractAnalyzerSubConfig *> &subConfigs) const; - void fromMap(const QVariantMap &map, QList<AbstractAnalyzerSubConfig *> *subConfigs); - - AnalyzerSettings(QObject *parent); - AnalyzerSettings(const AnalyzerSettings *other); - QList<AbstractAnalyzerSubConfig *> m_subConfigs; -}; - - -// global and local settings are loaded and saved differently, and they also handle suppressions -// differently. -/** - * Global settings - * - * To access your custom configuration use: - * @code - * AnalyzerGlobalSettings::instance()->subConfig<YourGlobalConfig>()->... - * @endcode - */ -class ANALYZER_EXPORT AnalyzerGlobalSettings : public AnalyzerSettings -{ - Q_OBJECT - -public: - static AnalyzerGlobalSettings *instance(); - ~AnalyzerGlobalSettings(); - - void writeSettings() const; - void readSettings(); - - static void registerConfig(AbstractAnalyzerSubConfig *config); - -private: - AnalyzerGlobalSettings(QObject *parent); - static AnalyzerGlobalSettings *m_instance; -}; /** * Settings associated with a single project/run configuration @@ -168,18 +84,16 @@ private: * @endcode */ class ANALYZER_EXPORT AnalyzerRunConfigurationAspect - : public AnalyzerSettings, public ProjectExplorer::IRunConfigurationAspect + : public ProjectExplorer::IRunConfigurationAspect { Q_OBJECT public: - AnalyzerRunConfigurationAspect(); - AnalyzerRunConfigurationAspect(const AnalyzerRunConfigurationAspect *other); - ~AnalyzerRunConfigurationAspect(); + AnalyzerRunConfigurationAspect(AbstractAnalyzerSubConfig *customConfiguration, + AbstractAnalyzerSubConfig *globalConfiguration); - static void registerConfigFactory(AnalyzerSubConfigFactory *factory); + ~AnalyzerRunConfigurationAspect(); - QString displayName() const; virtual QVariantMap toMap() const; AnalyzerRunConfigurationAspect *clone(ProjectExplorer::RunConfiguration *parent) const; @@ -187,7 +101,9 @@ public: void setUsingGlobalSettings(bool value); void resetCustomToGlobalSettings(); - QList<AbstractAnalyzerSubConfig *> customSubConfigs() const { return m_customConfigurations; } + AbstractAnalyzerSubConfig *customSubConfig() const { return m_customConfiguration; } + AbstractAnalyzerSubConfig *globalSubConfig() const { return m_globalConfiguration; } + AbstractAnalyzerSubConfig *currentConfig() const; ProjectExplorer::RunConfigWidget *createConfigurationWidget(); protected: @@ -195,7 +111,8 @@ protected: private: bool m_useGlobalSettings; - QList<AbstractAnalyzerSubConfig *> m_customConfigurations; + AbstractAnalyzerSubConfig *m_customConfiguration; + AbstractAnalyzerSubConfig *m_globalConfiguration; }; } // namespace Analyzer diff --git a/src/plugins/analyzerbase/ianalyzertool.h b/src/plugins/analyzerbase/ianalyzertool.h index 8a433c208f..f9ac4bf932 100644 --- a/src/plugins/analyzerbase/ianalyzertool.h +++ b/src/plugins/analyzerbase/ianalyzertool.h @@ -46,9 +46,7 @@ class RunConfiguration; namespace Analyzer { -class IAnalyzerOutputPaneAdapter; class AnalyzerRunControl; -class AbstractAnalyzerSubConfig; /** diff --git a/src/plugins/debugger/debuggerrunconfigurationaspect.cpp b/src/plugins/debugger/debuggerrunconfigurationaspect.cpp index bdafb8c80a..8bd6d7100a 100644 --- a/src/plugins/debugger/debuggerrunconfigurationaspect.cpp +++ b/src/plugins/debugger/debuggerrunconfigurationaspect.cpp @@ -277,11 +277,6 @@ bool DebuggerRunConfigurationAspect::isQmlDebuggingSpinboxSuppressed() const return dev->canAutoDetectPorts(); } -QString DebuggerRunConfigurationAspect::displayName() const -{ - return tr("Debugger settings"); -} - QVariantMap DebuggerRunConfigurationAspect::toMap() const { QVariantMap map; @@ -324,6 +319,9 @@ ProjectExplorer::RunConfigWidget *DebuggerRunConfigurationAspect::createConfigur void DebuggerRunConfigurationAspect::ctor() { + setId("DebuggerAspect"); + setDisplayName(tr("Debugger settings")); + connect(this, SIGNAL(debuggersChanged()), m_runConfiguration, SIGNAL(requestRunActionsUpdate())); } diff --git a/src/plugins/debugger/debuggerrunconfigurationaspect.h b/src/plugins/debugger/debuggerrunconfigurationaspect.h index 0dcbb18fc1..a5f53fdd46 100644 --- a/src/plugins/debugger/debuggerrunconfigurationaspect.h +++ b/src/plugins/debugger/debuggerrunconfigurationaspect.h @@ -39,7 +39,7 @@ namespace Debugger { namespace Internal { class DebuggerRunConfigWidget; } class DEBUGGER_EXPORT DebuggerRunConfigurationAspect - : public QObject, public ProjectExplorer::IRunConfigurationAspect + : public ProjectExplorer::IRunConfigurationAspect { Q_OBJECT @@ -60,8 +60,6 @@ public: DebuggerRunConfigurationAspect *clone(ProjectExplorer::RunConfiguration *parent) const; ProjectExplorer::RunConfigWidget *createConfigurationWidget(); - QString displayName() const; - bool useCppDebugger() const; void setUseCppDebugger(bool value); bool useQmlDebugger() const; diff --git a/src/plugins/projectexplorer/environmentaspect.cpp b/src/plugins/projectexplorer/environmentaspect.cpp index f8648c1b17..ffdcc7fceb 100644 --- a/src/plugins/projectexplorer/environmentaspect.cpp +++ b/src/plugins/projectexplorer/environmentaspect.cpp @@ -48,6 +48,8 @@ EnvironmentAspect::EnvironmentAspect(RunConfiguration *rc) : m_runConfiguration(rc) { QTC_CHECK(m_runConfiguration); + setDisplayName(tr("Run Environment")); + setId("EnvironmentAspect"); } EnvironmentAspect::EnvironmentAspect(const EnvironmentAspect *other, RunConfiguration *parent) : @@ -64,11 +66,6 @@ QVariantMap EnvironmentAspect::toMap() const return data; } -QString EnvironmentAspect::displayName() const -{ - return tr("Run Environment"); -} - RunConfigWidget *EnvironmentAspect::createConfigurationWidget() { return new EnvironmentAspectWidget(this); diff --git a/src/plugins/projectexplorer/environmentaspect.h b/src/plugins/projectexplorer/environmentaspect.h index 604d253d1c..ab094537ee 100644 --- a/src/plugins/projectexplorer/environmentaspect.h +++ b/src/plugins/projectexplorer/environmentaspect.h @@ -41,15 +41,13 @@ namespace ProjectExplorer { -class PROJECTEXPLORER_EXPORT EnvironmentAspect : public QObject, public IRunConfigurationAspect +class PROJECTEXPLORER_EXPORT EnvironmentAspect : public IRunConfigurationAspect { Q_OBJECT public: - // from IRunConfigurationAspect: + // IRunConfigurationAspect: QVariantMap toMap() const; - QString displayName() const; - RunConfigWidget *createConfigurationWidget(); virtual RunConfiguration *runConfiguration() const { return m_runConfiguration; } diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index f51f8006b3..f7ee9ef87b 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -72,19 +72,29 @@ private: inline bool operator==(const ProcessHandle &p1, const ProcessHandle &p2) { return p1.equals(p2); } inline bool operator!=(const ProcessHandle &p1, const ProcessHandle &p2) { return !p1.equals(p2); } -class PROJECTEXPLORER_EXPORT IRunConfigurationAspect +class PROJECTEXPLORER_EXPORT IRunConfigurationAspect : public QObject { + Q_OBJECT + public: virtual ~IRunConfigurationAspect() {} virtual QVariantMap toMap() const = 0; - virtual QString displayName() const = 0; - virtual IRunConfigurationAspect *clone(RunConfiguration *parent) const = 0; virtual RunConfigWidget *createConfigurationWidget(); + QString displayName() const { return m_displayName; } + void setDisplayName(const QString &displayName) { m_displayName = displayName; } + + void setId(Core::Id id) { m_id = id; } + Core::Id id() const { return m_id; } + protected: friend class RunConfiguration; virtual void fromMap(const QVariantMap &map) = 0; + +private: + QString m_displayName; + Core::Id m_id; }; // Documentation inside. @@ -110,17 +120,23 @@ public: QVariantMap toMap() const; QList<IRunConfigurationAspect *> extraAspects() const; + template <typename T> T *extraAspect() const { QTC_ASSERT(m_aspectsInitialized, return 0); - IRunConfigurationAspect *typeCheck = static_cast<T *>(0); - Q_UNUSED(typeCheck); - T *result = 0; - foreach (IRunConfigurationAspect *a, m_aspects) { - if ((result = dynamic_cast<T *>(a)) != 0) - break; - } - return result; + foreach (IRunConfigurationAspect *aspect, m_aspects) + if (T *result = qobject_cast<T *>(aspect)) + return result; + return 0; + } + + template <typename T> T *extraAspect(Core::Id id) const + { + QTC_ASSERT(m_aspectsInitialized, return 0); + foreach (IRunConfigurationAspect *aspect, m_aspects) + if (aspect->id() == id) + return qobject_cast<T *>(aspect); + return 0; } virtual ProjectExplorer::Abi abi() const; diff --git a/src/plugins/valgrind/callgrindengine.cpp b/src/plugins/valgrind/callgrindengine.cpp index ec886c7dfe..d5bacdef50 100644 --- a/src/plugins/valgrind/callgrindengine.cpp +++ b/src/plugins/valgrind/callgrindengine.cpp @@ -64,19 +64,18 @@ QStringList CallgrindRunControl::toolArguments() const { QStringList arguments; - ValgrindBaseSettings *callgrindSettings = m_settings->subConfig<ValgrindBaseSettings>(); - QTC_ASSERT(callgrindSettings, return arguments); + QTC_ASSERT(m_settings, return arguments); - if (callgrindSettings->enableCacheSim()) + if (m_settings->enableCacheSim()) arguments << QLatin1String("--cache-sim=yes"); - if (callgrindSettings->enableBranchSim()) + if (m_settings->enableBranchSim()) arguments << QLatin1String("--branch-sim=yes"); - if (callgrindSettings->collectBusEvents()) + if (m_settings->collectBusEvents()) arguments << QLatin1String("--collect-bus=yes"); - if (callgrindSettings->collectSystime()) + if (m_settings->collectSystime()) arguments << QLatin1String("--collect-systime=yes"); if (m_markAsPaused) diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp index 02b1ce74f1..48f77fed32 100644 --- a/src/plugins/valgrind/callgrindtool.cpp +++ b/src/plugins/valgrind/callgrindtool.cpp @@ -213,12 +213,6 @@ public: }; -static ValgrindGlobalSettings *globalSettings() -{ - return AnalyzerGlobalSettings::instance()->subConfig<ValgrindGlobalSettings>(); -} - - CallgrindToolPrivate::CallgrindToolPrivate(CallgrindTool *parent) : q(parent) , m_dataModel(new DataModel(this)) @@ -399,7 +393,7 @@ void CallgrindToolPrivate::updateCostFormat() m_calleesView->setCostFormat(format); m_callersView->setCostFormat(format); } - if (ValgrindGlobalSettings *settings = globalSettings()) + if (ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings()) settings->setCostFormat(format); } @@ -583,8 +577,9 @@ AnalyzerRunControl *CallgrindToolPrivate::createRunControl(const AnalyzerStartPa // apply project settings if (runConfiguration) { - if (const AnalyzerRunConfigurationAspect *analyzerSettings = runConfiguration->extraAspect<AnalyzerRunConfigurationAspect>()) { - if (const ValgrindProjectSettings *settings = analyzerSettings->subConfig<ValgrindProjectSettings>()) { + if (AnalyzerRunConfigurationAspect *analyzerAspect + = runConfiguration->extraAspect<AnalyzerRunConfigurationAspect>(ANALYZER_VALGRIND_SETTINGS)) { + if (const ValgrindBaseSettings *settings = qobject_cast<ValgrindBaseSettings *>(analyzerAspect->currentConfig())) { m_visualisation->setMinimumInclusiveCostRatio(settings->visualisationMinimumInclusiveCostRatio() / 100.0); m_proxyModel->setMinimumInclusiveCostRatio(settings->minimumInclusiveCostRatio() / 100.0); m_dataModel->setVerboseToolTipsEnabled(settings->enableEventToolTips()); @@ -785,7 +780,7 @@ QWidget *CallgrindToolPrivate::createWidgets() } - ValgrindGlobalSettings *settings = globalSettings(); + ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings(); // cycle detection //action = new QAction(QLatin1String("Cycle Detection"), this); ///FIXME: icon diff --git a/src/plugins/valgrind/memcheckengine.cpp b/src/plugins/valgrind/memcheckengine.cpp index c29052271f..a5d2209be5 100644 --- a/src/plugins/valgrind/memcheckengine.cpp +++ b/src/plugins/valgrind/memcheckengine.cpp @@ -99,22 +99,21 @@ QStringList MemcheckRunControl::toolArguments() const QStringList arguments; arguments << QLatin1String("--gen-suppressions=all"); - ValgrindBaseSettings *memcheckSettings = m_settings->subConfig<ValgrindBaseSettings>(); - QTC_ASSERT(memcheckSettings, return arguments); + QTC_ASSERT(m_settings, return arguments); - if (memcheckSettings->trackOrigins()) + if (m_settings->trackOrigins()) arguments << QLatin1String("--track-origins=yes"); - foreach (const QString &file, memcheckSettings->suppressionFiles()) + foreach (const QString &file, m_settings->suppressionFiles()) arguments << QString::fromLatin1("--suppressions=%1").arg(file); - arguments << QString::fromLatin1("--num-callers=%1").arg(memcheckSettings->numCallers()); + arguments << QString::fromLatin1("--num-callers=%1").arg(m_settings->numCallers()); return arguments; } QStringList MemcheckRunControl::suppressionFiles() const { - return m_settings->subConfig<ValgrindBaseSettings>()->suppressionFiles(); + return m_settings->suppressionFiles(); } void MemcheckRunControl::status(const Status &status) diff --git a/src/plugins/valgrind/memcheckerrorview.cpp b/src/plugins/valgrind/memcheckerrorview.cpp index 3f421b280a..adf38c7e12 100644 --- a/src/plugins/valgrind/memcheckerrorview.cpp +++ b/src/plugins/valgrind/memcheckerrorview.cpp @@ -494,7 +494,7 @@ QString MemcheckErrorView::defaultSuppressionFile() const // slot, can (for now) be invoked either when the settings were modified *or* when the active // settings object has changed. -void MemcheckErrorView::settingsChanged(Analyzer::AnalyzerSettings *settings) +void MemcheckErrorView::settingsChanged(ValgrindBaseSettings *settings) { QTC_ASSERT(settings, return); m_settings = settings; diff --git a/src/plugins/valgrind/memcheckerrorview.h b/src/plugins/valgrind/memcheckerrorview.h index 3ba9c84def..24ce06c859 100644 --- a/src/plugins/valgrind/memcheckerrorview.h +++ b/src/plugins/valgrind/memcheckerrorview.h @@ -33,11 +33,11 @@ #include <QListView> -namespace Analyzer { class AnalyzerSettings; } - namespace Valgrind { namespace Internal { +class ValgrindBaseSettings; + class MemcheckErrorView : public QListView { Q_OBJECT @@ -52,10 +52,10 @@ public: void setDefaultSuppressionFile(const QString &suppFile); QString defaultSuppressionFile() const; - Analyzer::AnalyzerSettings *settings() const { return m_settings; } + ValgrindBaseSettings *settings() const { return m_settings; } public slots: - void settingsChanged(Analyzer::AnalyzerSettings *settings); + void settingsChanged(ValgrindBaseSettings *settings); void goNext(); void goBack(); @@ -75,7 +75,7 @@ private: QAction *m_copyAction; QAction *m_suppressAction; QString m_defaultSuppFile; - Analyzer::AnalyzerSettings *m_settings; + ValgrindBaseSettings *m_settings; }; } // namespace Internal diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index 17b4baf339..8b392c3b8d 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -37,6 +37,7 @@ #include <analyzerbase/analyzermanager.h> #include <analyzerbase/analyzerconstants.h> +#include <valgrind/valgrindsettings.h> #include <valgrind/xmlprotocol/errorlistmodel.h> #include <valgrind/xmlprotocol/stackmodel.h> #include <valgrind/xmlprotocol/error.h> @@ -220,20 +221,21 @@ MemcheckTool::MemcheckTool(QObject *parent) void MemcheckTool::settingsDestroyed(QObject *settings) { QTC_ASSERT(m_settings == settings, return); - m_settings = AnalyzerGlobalSettings::instance(); + m_settings = ValgrindPlugin::globalSettings(); } void MemcheckTool::maybeActiveRunConfigurationChanged() { - AnalyzerSettings *settings = 0; + ValgrindBaseSettings *settings = 0; ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance(); if (Project *project = pe->startupProject()) if (Target *target = project->activeTarget()) if (RunConfiguration *rc = target->activeRunConfiguration()) - settings = rc->extraAspect<AnalyzerRunConfigurationAspect>(); + if (AnalyzerRunConfigurationAspect *aspect = rc->extraAspect<AnalyzerRunConfigurationAspect>(ANALYZER_VALGRIND_SETTINGS)) + settings = qobject_cast<ValgrindBaseSettings *>(aspect->customSubConfig()); if (!settings) // fallback to global settings - settings = AnalyzerGlobalSettings::instance(); + settings = ValgrindPlugin::globalSettings(); if (m_settings == settings) return; @@ -247,33 +249,29 @@ void MemcheckTool::maybeActiveRunConfigurationChanged() // now make the new settings current, update and connect input widgets m_settings = settings; QTC_ASSERT(m_settings, return); - connect(m_settings, SIGNAL(destroyed(QObject*)), SLOT(settingsDestroyed(QObject*))); - ValgrindBaseSettings *memcheckSettings = m_settings->subConfig<ValgrindBaseSettings>(); - QTC_ASSERT(memcheckSettings, return); - foreach (QAction *action, m_errorFilterActions) { bool contained = true; foreach (const QVariant &v, action->data().toList()) { bool ok; int kind = v.toInt(&ok); - if (ok && !memcheckSettings->visibleErrorKinds().contains(kind)) + if (ok && !m_settings->visibleErrorKinds().contains(kind)) contained = false; } action->setChecked(contained); } - m_filterProjectAction->setChecked(!memcheckSettings->filterExternalIssues()); + m_filterProjectAction->setChecked(!m_settings->filterExternalIssues()); m_errorView->settingsChanged(m_settings); - connect(memcheckSettings, SIGNAL(visibleErrorKindsChanged(QList<int>)), + connect(m_settings, SIGNAL(visibleErrorKindsChanged(QList<int>)), m_errorProxyModel, SLOT(setAcceptedKinds(QList<int>))); - m_errorProxyModel->setAcceptedKinds(memcheckSettings->visibleErrorKinds()); + m_errorProxyModel->setAcceptedKinds(m_settings->visibleErrorKinds()); - connect(memcheckSettings, SIGNAL(filterExternalIssuesChanged(bool)), + connect(m_settings, SIGNAL(filterExternalIssuesChanged(bool)), m_errorProxyModel, SLOT(setFilterExternalIssues(bool))); - m_errorProxyModel->setFilterExternalIssues(memcheckSettings->filterExternalIssues()); + m_errorProxyModel->setFilterExternalIssues(m_settings->filterExternalIssues()); } RunMode MemcheckTool::runMode() const @@ -498,9 +496,7 @@ void MemcheckTool::updateErrorFilter() QTC_ASSERT(m_errorView, return); QTC_ASSERT(m_settings, return); - ValgrindBaseSettings *memcheckSettings = m_settings->subConfig<ValgrindBaseSettings>(); - QTC_ASSERT(memcheckSettings, return); - memcheckSettings->setFilterExternalIssues(!m_filterProjectAction->isChecked()); + m_settings->setFilterExternalIssues(!m_filterProjectAction->isChecked()); QList<int> errorKinds; foreach (QAction *a, m_errorFilterActions) { @@ -513,7 +509,7 @@ void MemcheckTool::updateErrorFilter() errorKinds << kind; } } - memcheckSettings->setVisibleErrorKinds(errorKinds); + m_settings->setVisibleErrorKinds(errorKinds); } void MemcheckTool::finished() diff --git a/src/plugins/valgrind/memchecktool.h b/src/plugins/valgrind/memchecktool.h index 31db52f60c..e12120077a 100644 --- a/src/plugins/valgrind/memchecktool.h +++ b/src/plugins/valgrind/memchecktool.h @@ -48,15 +48,12 @@ class Error; } } -namespace Analyzer { -class AnalyzerSettings; -} - namespace Valgrind { namespace Internal { -class MemcheckErrorView; class FrameFinder; +class MemcheckErrorView; +class ValgrindBaseSettings; class MemcheckErrorFilterProxyModel : public QSortFilterProxyModel { @@ -109,7 +106,7 @@ private: void clearErrorView(); private: - Analyzer::AnalyzerSettings *m_settings; + ValgrindBaseSettings *m_settings; QMenu *m_filterMenu; FrameFinder *m_frameFinder; diff --git a/src/plugins/valgrind/suppressiondialog.cpp b/src/plugins/valgrind/suppressiondialog.cpp index e4ff3184e6..e601f2d0fc 100644 --- a/src/plugins/valgrind/suppressiondialog.cpp +++ b/src/plugins/valgrind/suppressiondialog.cpp @@ -222,7 +222,7 @@ void SuppressionDialog::accept() } } - m_settings->subConfig<ValgrindBaseSettings>()->addSuppressionFiles(QStringList(path)); + m_settings->addSuppressionFiles(QStringList(path)); QModelIndexList indices = m_view->selectionModel()->selectedRows(); qSort(indices.begin(), indices.end(), sortIndizesReverse); diff --git a/src/plugins/valgrind/suppressiondialog.h b/src/plugins/valgrind/suppressiondialog.h index cecbb6afe7..5c0c25535d 100644 --- a/src/plugins/valgrind/suppressiondialog.h +++ b/src/plugins/valgrind/suppressiondialog.h @@ -42,12 +42,11 @@ class QPlainTextEdit; class QDialogButtonBox; QT_END_NAMESPACE -namespace Analyzer { class AnalyzerSettings; } - namespace Valgrind { namespace Internal { class MemcheckErrorView; +class ValgrindBaseSettings; class SuppressionDialog : public QDialog { @@ -66,7 +65,7 @@ private: void reject(); MemcheckErrorView *m_view; - Analyzer::AnalyzerSettings *m_settings; + ValgrindBaseSettings *m_settings; bool m_cleanupIfCanceled; QList<XmlProtocol::Error> m_errors; diff --git a/src/plugins/valgrind/valgrindconfigwidget.cpp b/src/plugins/valgrind/valgrindconfigwidget.cpp index e39eff145c..1817ab1ca9 100644 --- a/src/plugins/valgrind/valgrindconfigwidget.cpp +++ b/src/plugins/valgrind/valgrindconfigwidget.cpp @@ -30,6 +30,7 @@ #include "valgrindconfigwidget.h" #include "valgrindsettings.h" +#include "valgrindplugin.h" #include "ui_valgrindconfigwidget.h" @@ -173,7 +174,7 @@ void ValgrindConfigWidget::updateUi() void ValgrindConfigWidget::slotAddSuppression() { - ValgrindGlobalSettings *conf = Analyzer::AnalyzerGlobalSettings::instance()->subConfig<ValgrindGlobalSettings>(); + ValgrindGlobalSettings *conf = ValgrindPlugin::globalSettings(); QTC_ASSERT(conf, return); QStringList files = QFileDialog::getOpenFileNames(this, tr("Valgrind Suppression Files"), diff --git a/src/plugins/valgrind/valgrindengine.cpp b/src/plugins/valgrind/valgrindengine.cpp index 173c9fe6fa..146e372dbe 100644 --- a/src/plugins/valgrind/valgrindengine.cpp +++ b/src/plugins/valgrind/valgrindengine.cpp @@ -30,13 +30,14 @@ #include "valgrindengine.h" #include "valgrindsettings.h" +#include "valgrindplugin.h" #include <coreplugin/icore.h> #include <coreplugin/ioutputpane.h> #include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/futureprogress.h> #include <extensionsystem/pluginmanager.h> -#include <projectexplorer/localapplicationrunconfiguration.h> +#include <projectexplorer/runconfiguration.h> #include <analyzerbase/analyzermanager.h> #include <QApplication> @@ -47,6 +48,7 @@ using namespace Analyzer; using namespace Core; using namespace Utils; +using namespace ProjectExplorer; namespace Valgrind { namespace Internal { @@ -62,10 +64,11 @@ ValgrindRunControl::ValgrindRunControl(const AnalyzerStartParameters &sp, m_isStopping(false) { if (runConfiguration) - m_settings = runConfiguration->extraAspect<AnalyzerRunConfigurationAspect>(); + if (AnalyzerRunConfigurationAspect *aspect = runConfiguration->extraAspect<AnalyzerRunConfigurationAspect>(ANALYZER_VALGRIND_SETTINGS)) + m_settings = qobject_cast<ValgrindBaseSettings *>(aspect->customSubConfig()); - if (!m_settings) - m_settings = AnalyzerGlobalSettings::instance(); + if (!m_settings) + m_settings = ValgrindPlugin::globalSettings(); connect(m_progressWatcher, SIGNAL(canceled()), this, SLOT(handleProgressCanceled())); @@ -99,7 +102,7 @@ bool ValgrindRunControl::startEngine() ValgrindRunner *run = runner(); run->setWorkingDirectory(sp.workingDirectory); - QString valgrindExe = m_settings->subConfig<ValgrindBaseSettings>()->valgrindExecutable(); + QString valgrindExe = m_settings->valgrindExecutable(); if (!sp.analyzerCmdPrefix.isEmpty()) valgrindExe = sp.analyzerCmdPrefix + QLatin1Char(' ') + valgrindExe; run->setValgrindExecutable(valgrindExe); @@ -173,7 +176,7 @@ void ValgrindRunControl::receiveProcessOutput(const QByteArray &output, OutputFo void ValgrindRunControl::receiveProcessError(const QString &message, QProcess::ProcessError error) { if (error == QProcess::FailedToStart) { - const QString &valgrind = m_settings->subConfig<ValgrindBaseSettings>()->valgrindExecutable(); + const QString valgrind = m_settings->valgrindExecutable(); if (!valgrind.isEmpty()) appendMessage(tr("** Error: \"%1\" could not be started: %2 **\n").arg(valgrind).arg(message), ErrorMessageFormat); else diff --git a/src/plugins/valgrind/valgrindengine.h b/src/plugins/valgrind/valgrindengine.h index 68313cd487..03c284630a 100644 --- a/src/plugins/valgrind/valgrindengine.h +++ b/src/plugins/valgrind/valgrindengine.h @@ -34,12 +34,11 @@ #include <analyzerbase/analyzerruncontrol.h> #include <utils/environment.h> #include <valgrind/valgrindrunner.h> +#include <valgrind/valgrindsettings.h> #include <QFutureInterface> #include <QFutureWatcher> -namespace Analyzer { class AnalyzerSettings; } - namespace Valgrind { namespace Internal { @@ -62,7 +61,7 @@ protected: virtual QStringList toolArguments() const = 0; virtual Valgrind::ValgrindRunner *runner() = 0; - Analyzer::AnalyzerSettings *m_settings; + ValgrindBaseSettings *m_settings; QFutureInterface<void> *m_progress; QFutureWatcher<void> *m_progressWatcher; diff --git a/src/plugins/valgrind/valgrindplugin.cpp b/src/plugins/valgrind/valgrindplugin.cpp index 1bc8416b04..8b4a4499a4 100644 --- a/src/plugins/valgrind/valgrindplugin.cpp +++ b/src/plugins/valgrind/valgrindplugin.cpp @@ -37,23 +37,42 @@ #include <analyzerbase/analyzermanager.h> #include <analyzerbase/analyzersettings.h> +#include <coreplugin/dialogs/ioptionspage.h> + #include <valgrind/valgrindsettings.h> #include <utils/hostosinfo.h> #include <QtPlugin> +#include <QCoreApplication> using namespace Analyzer; namespace Valgrind { namespace Internal { -class ProjectSettingsFactory : public AnalyzerSubConfigFactory +static ValgrindGlobalSettings *theGlobalSettings = 0; + +class ValgrindOptionsPage : public Core::IOptionsPage { - AbstractAnalyzerSubConfig *createProjectSettings() +public: + explicit ValgrindOptionsPage() { - return new ValgrindProjectSettings(); + setId(ANALYZER_VALGRIND_SETTINGS); + setDisplayName(tr("Valgrind")); + setCategory("T.Analyzer"); + setDisplayCategory(QCoreApplication::translate("Analyzer", "Analyzer")); + setCategoryIcon(QLatin1String(":/images/analyzer_category.png")); + } + + QWidget *createPage(QWidget *parent) { + return theGlobalSettings->createConfigWidget(parent); + } + + void apply() { + theGlobalSettings->writeSettings(); } + void finish() {} }; class ValgrindAction : public AnalyzerAction @@ -62,10 +81,19 @@ public: ValgrindAction() {} }; + +ValgrindPlugin::~ValgrindPlugin() +{ + delete theGlobalSettings; + theGlobalSettings = 0; +} + bool ValgrindPlugin::initialize(const QStringList &, QString *) { - AnalyzerGlobalSettings::registerConfig(new ValgrindGlobalSettings()); - AnalyzerRunConfigurationAspect::registerConfigFactory(new ProjectSettingsFactory()); + theGlobalSettings = new ValgrindGlobalSettings(); + theGlobalSettings->readSettings(); + + addAutoReleasedObject(new ValgrindOptionsPage()); IAnalyzerTool *memcheckTool = new MemcheckTool(this); IAnalyzerTool *callgrindTool = new CallgrindTool(this); @@ -122,6 +150,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *) return true; } +ValgrindGlobalSettings *ValgrindPlugin::globalSettings() +{ + return theGlobalSettings; +} + } // namespace Internal } // namespace Valgrind diff --git a/src/plugins/valgrind/valgrindplugin.h b/src/plugins/valgrind/valgrindplugin.h index a05b9ea034..e5dd4b1056 100644 --- a/src/plugins/valgrind/valgrindplugin.h +++ b/src/plugins/valgrind/valgrindplugin.h @@ -37,6 +37,8 @@ namespace Valgrind { namespace Internal { +class ValgrindGlobalSettings; + class ValgrindPlugin : public ExtensionSystem::IPlugin { Q_OBJECT @@ -44,9 +46,12 @@ class ValgrindPlugin : public ExtensionSystem::IPlugin public: ValgrindPlugin() {} + ~ValgrindPlugin(); + + bool initialize(const QStringList &arguments, QString *errorString); + void extensionsInitialized() {} - virtual bool initialize(const QStringList &arguments, QString *errorString); - virtual void extensionsInitialized() {} + static ValgrindGlobalSettings *globalSettings(); }; } // namespace Internal diff --git a/src/plugins/valgrind/valgrindruncontrolfactory.cpp b/src/plugins/valgrind/valgrindruncontrolfactory.cpp index b9e3cacca8..e0eb4fb802 100644 --- a/src/plugins/valgrind/valgrindruncontrolfactory.cpp +++ b/src/plugins/valgrind/valgrindruncontrolfactory.cpp @@ -28,6 +28,8 @@ ****************************************************************************/ #include "valgrindruncontrolfactory.h" +#include "valgrindsettings.h" +#include "valgrindplugin.h" #include <analyzerbase/ianalyzertool.h> #include <analyzerbase/analyzermanager.h> @@ -109,7 +111,11 @@ RunControl *ValgrindRunControlFactory::create(RunConfiguration *runConfiguration IRunConfigurationAspect *ValgrindRunControlFactory::createRunConfigurationAspect(RunConfiguration *rc) { Q_UNUSED(rc); - return new AnalyzerRunConfigurationAspect; + IRunConfigurationAspect *aspect + = new AnalyzerRunConfigurationAspect(new ValgrindProjectSettings(), ValgrindPlugin::globalSettings()); + aspect->setId(ANALYZER_VALGRIND_SETTINGS); + aspect->setDisplayName(tr("Valgrind Settings")); + return aspect; } } // namespace Internal diff --git a/src/plugins/valgrind/valgrindsettings.cpp b/src/plugins/valgrind/valgrindsettings.cpp index 7d89a79e8e..5cf6981f3b 100644 --- a/src/plugins/valgrind/valgrindsettings.cpp +++ b/src/plugins/valgrind/valgrindsettings.cpp @@ -29,6 +29,7 @@ ****************************************************************************/ #include "valgrindsettings.h" +#include "valgrindplugin.h" #include "valgrindconfigwidget.h" #include <coreplugin/icore.h> @@ -75,34 +76,6 @@ namespace Internal { // ////////////////////////////////////////////////////////////////// -QVariantMap ValgrindBaseSettings::defaults() const -{ - QVariantMap map; - - // General - map.insert(QLatin1String(valgrindExeC), QLatin1String("valgrind")); - - // Memcheck - map.insert(QLatin1String(numCallersC), 25); - map.insert(QLatin1String(trackOriginsC), true); - map.insert(QLatin1String(filterExternalIssuesC), true); - QVariantList defaultErrorKinds; - for (int i = 0; i < Valgrind::XmlProtocol::MemcheckErrorKindCount; ++i) - defaultErrorKinds << i; - map.insert(QLatin1String(visibleErrorKindsC), defaultErrorKinds); - - // Callgrind - map.insert(QLatin1String(callgrindEnableCacheSimC), false); - map.insert(QLatin1String(callgrindEnableBranchSimC), false); - map.insert(QLatin1String(callgrindCollectSystimeC), false); - map.insert(QLatin1String(callgrindCollectBusEventsC), false); - map.insert(QLatin1String(callgrindEnableEventToolTipsC), true); - map.insert(QLatin1String(callgrindMinimumCostRatioC), 0.01); - map.insert(QLatin1String(callgrindVisualisationMinimumCostRatioC), 10.0); - - return map; -} - void ValgrindBaseSettings::fromMap(const QVariantMap &map) { // General @@ -172,11 +145,6 @@ QString ValgrindBaseSettings::valgrindExecutable() const return m_valgrindExecutable; } -Core::Id ValgrindBaseSettings::id() const -{ - return "Analyzer.Valgrind.Settings"; -} - QString ValgrindBaseSettings::displayName() const { return tr("Valgrind"); @@ -286,25 +254,14 @@ void ValgrindBaseSettings::setVisualisationMinimumInclusiveCostRatio( // ////////////////////////////////////////////////////////////////// -QWidget *ValgrindGlobalSettings::createConfigWidget(QWidget *parent) +ValgrindGlobalSettings::ValgrindGlobalSettings() { - return new ValgrindConfigWidget(this, parent, true); + readSettings(); } -QVariantMap ValgrindGlobalSettings::defaults() const +QWidget *ValgrindGlobalSettings::createConfigWidget(QWidget *parent) { - QVariantMap map = ValgrindBaseSettings::defaults(); - - // Memcheck - map.insert(QLatin1String(suppressionFilesC), QStringList()); - map.insert(QLatin1String(lastSuppressionDirectoryC), QString()); - map.insert(QLatin1String(lastSuppressionHistoryC), QStringList()); - - // Callgrind - map.insert(QLatin1String(callgrindCostFormatC), CostDelegate::FormatRelative); - map.insert(QLatin1String(callgrindCycleDetectionC), true); - - return map; + return new ValgrindConfigWidget(this, parent, true); } void ValgrindGlobalSettings::fromMap(const QVariantMap &map) @@ -390,6 +347,61 @@ void ValgrindGlobalSettings::setLastSuppressionDialogHistory(const QStringList & m_lastSuppressionHistory = history; } +static const char groupC[] = "Analyzer"; + +void ValgrindGlobalSettings::readSettings() +{ + QVariantMap defaults; + + // General + defaults.insert(QLatin1String(valgrindExeC), QLatin1String("valgrind")); + + // Memcheck + defaults.insert(QLatin1String(numCallersC), 25); + defaults.insert(QLatin1String(trackOriginsC), true); + defaults.insert(QLatin1String(filterExternalIssuesC), true); + QVariantList defaultErrorKinds; + for (int i = 0; i < Valgrind::XmlProtocol::MemcheckErrorKindCount; ++i) + defaultErrorKinds << i; + defaults.insert(QLatin1String(visibleErrorKindsC), defaultErrorKinds); + + defaults.insert(QLatin1String(suppressionFilesC), QStringList()); + defaults.insert(QLatin1String(lastSuppressionDirectoryC), QString()); + defaults.insert(QLatin1String(lastSuppressionHistoryC), QStringList()); + + // Callgrind + defaults.insert(QLatin1String(callgrindEnableCacheSimC), false); + defaults.insert(QLatin1String(callgrindEnableBranchSimC), false); + defaults.insert(QLatin1String(callgrindCollectSystimeC), false); + defaults.insert(QLatin1String(callgrindCollectBusEventsC), false); + defaults.insert(QLatin1String(callgrindEnableEventToolTipsC), true); + defaults.insert(QLatin1String(callgrindMinimumCostRatioC), 0.01); + defaults.insert(QLatin1String(callgrindVisualisationMinimumCostRatioC), 10.0); + + defaults.insert(QLatin1String(callgrindCostFormatC), CostDelegate::FormatRelative); + defaults.insert(QLatin1String(callgrindCycleDetectionC), true); + + // Read stored values + QSettings *settings = Core::ICore::settings(); + settings->beginGroup(QLatin1String(groupC)); + QVariantMap map = defaults; + for (QVariantMap::ConstIterator it = defaults.constBegin(); it != defaults.constEnd(); ++it) + map.insert(it.key(), settings->value(it.key(), it.value())); + settings->endGroup(); + + fromMap(map); +} + +void ValgrindGlobalSettings::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(); +} + // // Callgrind // @@ -401,7 +413,7 @@ CostDelegate::CostFormat ValgrindGlobalSettings::costFormat() const void ValgrindGlobalSettings::setCostFormat(CostDelegate::CostFormat format) { m_costFormat = format; - AnalyzerGlobalSettings::instance()->writeSettings(); + writeSettings(); } bool ValgrindGlobalSettings::detectCycles() const @@ -412,7 +424,7 @@ bool ValgrindGlobalSettings::detectCycles() const void ValgrindGlobalSettings::setDetectCycles(bool on) { m_detectCycles = on; - AnalyzerGlobalSettings::instance()->writeSettings(); + writeSettings(); } bool ValgrindGlobalSettings::shortenTemplates() const @@ -423,15 +435,9 @@ bool ValgrindGlobalSettings::shortenTemplates() const void ValgrindGlobalSettings::setShortenTemplates(bool on) { m_shortenTemplates = on; - AnalyzerGlobalSettings::instance()->writeSettings(); + writeSettings(); } -ValgrindGlobalSettings *globalValgrindSettings() -{ - ValgrindGlobalSettings *ret = AnalyzerGlobalSettings::instance()->subConfig<ValgrindGlobalSettings>(); - QTC_ASSERT(ret, return 0); - return ret; -} ////////////////////////////////////////////////////////////////// // @@ -444,17 +450,6 @@ QWidget *ValgrindProjectSettings::createConfigWidget(QWidget *parent) return new ValgrindConfigWidget(this, parent, false); } -QVariantMap ValgrindProjectSettings::defaults() const -{ - QVariantMap map = ValgrindBaseSettings::defaults(); - - // Memcheck - map.insert(QLatin1String(addedSuppressionFilesC), QStringList()); - map.insert(QLatin1String(removedSuppressionFilesC), QStringList()); - - return map; -} - void ValgrindProjectSettings::fromMap(const QVariantMap &map) { ValgrindBaseSettings::fromMap(map); @@ -488,7 +483,7 @@ QVariantMap ValgrindProjectSettings::toMap() const void ValgrindProjectSettings::addSuppressionFiles(const QStringList &suppressions) { - QStringList globalSuppressions = globalValgrindSettings()->suppressionFiles(); + QStringList globalSuppressions = ValgrindPlugin::globalSettings()->suppressionFiles(); foreach (const QString &s, suppressions) { if (m_addedSuppressionFiles.contains(s)) continue; @@ -500,7 +495,7 @@ void ValgrindProjectSettings::addSuppressionFiles(const QStringList &suppression void ValgrindProjectSettings::removeSuppressionFiles(const QStringList &suppressions) { - QStringList globalSuppressions = globalValgrindSettings()->suppressionFiles(); + QStringList globalSuppressions = ValgrindPlugin::globalSettings()->suppressionFiles(); foreach (const QString &s, suppressions) { m_addedSuppressionFiles.removeAll(s); if (globalSuppressions.contains(s)) @@ -510,7 +505,7 @@ void ValgrindProjectSettings::removeSuppressionFiles(const QStringList &suppress QStringList ValgrindProjectSettings::suppressionFiles() const { - QStringList ret = globalValgrindSettings()->suppressionFiles(); + QStringList ret = ValgrindPlugin::globalSettings()->suppressionFiles(); foreach (const QString &s, m_disabledGlobalSuppressionFiles) ret.removeAll(s); ret.append(m_addedSuppressionFiles); diff --git a/src/plugins/valgrind/valgrindsettings.h b/src/plugins/valgrind/valgrindsettings.h index b7d56d06b8..ec97e42279 100644 --- a/src/plugins/valgrind/valgrindsettings.h +++ b/src/plugins/valgrind/valgrindsettings.h @@ -41,6 +41,8 @@ namespace Valgrind { namespace Internal { +const char ANALYZER_VALGRIND_SETTINGS[] = "Analyzer.Valgrind.Settings"; + /** * Valgrind settings shared for global and per-project. */ @@ -52,10 +54,7 @@ public: ValgrindBaseSettings() {} virtual QVariantMap toMap() const; - virtual QVariantMap defaults() const; virtual void fromMap(const QVariantMap &map); - - virtual Core::Id id() const; virtual QString displayName() const; signals: @@ -167,11 +166,10 @@ class ValgrindGlobalSettings : public ValgrindBaseSettings Q_OBJECT public: - ValgrindGlobalSettings() {} + ValgrindGlobalSettings(); QWidget *createConfigWidget(QWidget *parent); QVariantMap toMap() const; - QVariantMap defaults() const; void fromMap(const QVariantMap &map); virtual AbstractAnalyzerSubConfig *clone(); @@ -191,6 +189,9 @@ public: void setLastSuppressionDialogHistory(const QStringList &history); QStringList lastSuppressionDialogHistory() const; + void writeSettings() const; + void readSettings(); + private: QStringList m_suppressionFiles; QString m_lastSuppressionDirectory; @@ -229,7 +230,6 @@ public: QWidget *createConfigWidget(QWidget *parent); QVariantMap toMap() const; - QVariantMap defaults() const; void fromMap(const QVariantMap &map); virtual AbstractAnalyzerSubConfig *clone(); |