Commit 81bb1c98 authored by Eike Ziller's avatar Eike Ziller Committed by hjk

Make sensible use of global analyzer settings

Project settings now have the option to use the global settings (on by
default), or custom ones.

Task-number: QTCREATORBUG-5445

Change-Id: I6602b53a6e7823150773e8461ef9db39b7546e98
Reviewed-on: http://codereview.qt.nokia.com/2163Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 46d29819
......@@ -34,13 +34,12 @@
#include "analyzerrunconfigwidget.h"
#include "analyzersettings.h"
#include <utils/detailswidget.h>
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
#include <QtGui/QGroupBox>
#include <QtGui/QApplication>
#include <QtGui/QLabel>
#include <QtGui/QVBoxLayout>
namespace Analyzer {
......@@ -52,6 +51,29 @@ AnalyzerRunConfigWidget::AnalyzerRunConfigWidget()
new QVBoxLayout(mainWidget);
m_detailsWidget->setWidget(mainWidget);
QWidget *globalSetting = new QWidget(mainWidget);
QHBoxLayout *globalSettingLayout = new QHBoxLayout(globalSetting);
mainWidget->layout()->addWidget(globalSetting);
QLabel *label = new QLabel(displayName(), globalSetting);
globalSettingLayout->addWidget(label);
m_settingsCombo = new QComboBox(globalSetting);
m_settingsCombo->addItems(QStringList()
<< QApplication::translate("ProjectExplorer::Internal::EditorSettingsPropertiesPage", "Global")
<< QApplication::translate("ProjectExplorer::Internal::EditorSettingsPropertiesPage", "Custom")
);
globalSettingLayout->addWidget(m_settingsCombo);
connect(m_settingsCombo, SIGNAL(activated(int)), this, SLOT(chooseSettings(int)));
m_restoreButton = new QPushButton(
QApplication::translate("ProjectExplorer::Internal::EditorSettingsPropertiesPage", "Restore Global"),
globalSetting);
globalSettingLayout->addWidget(m_restoreButton);
connect(m_restoreButton, SIGNAL(clicked()), this, SLOT(restoreGlobal()));
globalSettingLayout->addStretch(2);
m_subConfigWidget = new QWidget(mainWidget);
mainWidget->layout()->addWidget(m_subConfigWidget);
new QVBoxLayout(m_subConfigWidget);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_detailsWidget);
......@@ -66,23 +88,39 @@ void AnalyzerRunConfigWidget::setRunConfiguration(ProjectExplorer::RunConfigurat
{
QTC_ASSERT(rc, return);
AnalyzerProjectSettings *settings = rc->extraAspect<AnalyzerProjectSettings>();
QTC_ASSERT(settings, return);
m_settings = rc->extraAspect<AnalyzerProjectSettings>();
QTC_ASSERT(m_settings, return);
// update summary text
QStringList tools;
foreach (AbstractAnalyzerSubConfig *config, settings->subConfigs()) {
foreach (AbstractAnalyzerSubConfig *config, m_settings->subConfigs()) {
tools << QString("<strong>%1</strong>").arg(config->displayName());
}
m_detailsWidget->setSummaryText(tr("Available settings: %1").arg(tools.join(", ")));
// add group boxes for each sub config
QLayout *layout = m_detailsWidget->widget()->layout();
foreach (AbstractAnalyzerSubConfig *config, settings->subConfigs()) {
(void) new QGroupBox(config->displayName());
QLayout *layout = m_subConfigWidget->layout();
foreach (AbstractAnalyzerSubConfig *config, m_settings->customSubConfigs()) {
QWidget *widget = config->createConfigWidget(this);
layout->addWidget(widget);
}
m_subConfigWidget->setEnabled(!m_settings->isUsingGlobalSettings());
m_settingsCombo->setCurrentIndex(m_settings->isUsingGlobalSettings() ? 0 : 1);
m_restoreButton->setEnabled(!m_settings->isUsingGlobalSettings());
}
void AnalyzerRunConfigWidget::chooseSettings(int setting)
{
QTC_ASSERT(m_settings, return);
m_settings->setUsingGlobalSettings(setting == 0);
m_subConfigWidget->setEnabled(!m_settings->isUsingGlobalSettings());
m_restoreButton->setEnabled(!m_settings->isUsingGlobalSettings());
}
void AnalyzerRunConfigWidget::restoreGlobal()
{
QTC_ASSERT(m_settings, return);
m_settings->resetCustomToGlobalSettings();
}
} // namespace Analyzer
......@@ -35,8 +35,13 @@
#ifndef ANALYZER_INTERNAL_ANALYZERRUNCONFIGWIDGET_H
#define ANALYZER_INTERNAL_ANALYZERRUNCONFIGWIDGET_H
#include "analyzerbase_global.h"
#include "analyzersettings.h"
#include <projectexplorer/runconfiguration.h>
#include <analyzerbase/analyzerbase_global.h>
#include <QtGui/QComboBox>
#include <QtGui/QPushButton>
namespace Utils {
class DetailsWidget;
......@@ -57,8 +62,16 @@ public:
void setRunConfiguration(ProjectExplorer::RunConfiguration *rc);
private slots:
void chooseSettings(int setting);
void restoreGlobal();
private:
Utils::DetailsWidget *m_detailsWidget;
QWidget *m_subConfigWidget;
AnalyzerProjectSettings *m_settings;
QComboBox *m_settingsCombo;
QPushButton *m_restoreButton;
};
} // namespace Analyzer
......
......@@ -47,6 +47,7 @@
using namespace Analyzer::Internal;
static const char groupC[] = "Analyzer";
static const char useGlobalC[] = "Analyzer.Project.UseGlobal";
namespace Analyzer {
......@@ -57,28 +58,38 @@ AnalyzerSettings::AnalyzerSettings(QObject *parent)
{
}
QVariantMap AnalyzerSettings::defaults() const
{
QVariantMap map;
foreach (AbstractAnalyzerSubConfig *config, subConfigs()) {
map.unite(config->defaults());
}
return map;
}
bool AnalyzerSettings::fromMap(const QVariantMap &map)
{
return fromMap(map, &m_subConfigs);
}
bool AnalyzerSettings::fromMap(const QVariantMap &map, QList<AbstractAnalyzerSubConfig *> *subConfigs)
{
bool ret = true;
foreach (AbstractAnalyzerSubConfig *config, subConfigs()) {
foreach (AbstractAnalyzerSubConfig *config, *subConfigs) {
ret = ret && config->fromMap(map);
}
return ret;
}
QVariantMap AnalyzerSettings::defaults() const
QVariantMap AnalyzerSettings::toMap() const
{
QVariantMap map;
foreach (AbstractAnalyzerSubConfig *config, subConfigs()) {
map.unite(config->defaults());
}
return map;
return toMap(m_subConfigs);
}
QVariantMap AnalyzerSettings::toMap() const
QVariantMap AnalyzerSettings::toMap(const QList<AbstractAnalyzerSubConfig *> &subConfigs) const
{
QVariantMap map;
foreach (AbstractAnalyzerSubConfig *config, subConfigs()) {
foreach (AbstractAnalyzerSubConfig *config, subConfigs) {
map.unite(config->toMap());
}
return map;
......@@ -102,6 +113,7 @@ AnalyzerGlobalSettings *AnalyzerGlobalSettings::instance()
AnalyzerGlobalSettings::~AnalyzerGlobalSettings()
{
m_instance = 0;
qDeleteAll(m_subConfigs);
}
void AnalyzerGlobalSettings::readSettings()
......@@ -134,30 +146,36 @@ void AnalyzerGlobalSettings::writeSettings() const
void AnalyzerGlobalSettings::registerSubConfigs
(AnalyzerSubConfigFactory globalCreator, AnalyzerSubConfigFactory projectCreator)
{
m_projectSubConfigs.append(projectCreator);
m_projectSubConfigFactories.append(projectCreator);
AbstractAnalyzerSubConfig *config = globalCreator();
config->setParent(this);
m_subConfigs.append(config);
AnalyzerPlugin::instance()->addAutoReleasedObject(new AnalyzerOptionsPage(config));
readSettings();
}
QList<AnalyzerSubConfigFactory> AnalyzerGlobalSettings::projectSubConfigs() const
QList<AnalyzerSubConfigFactory> AnalyzerGlobalSettings::projectSubConfigFactories() const
{
return m_projectSubConfigs;
return m_projectSubConfigFactories;
}
AnalyzerProjectSettings::AnalyzerProjectSettings(QObject *parent)
: AnalyzerSettings(parent)
: AnalyzerSettings(parent), m_useGlobalSettings(true)
{
// add sub configs
foreach (AnalyzerSubConfigFactory factory, AnalyzerGlobalSettings::instance()->projectSubConfigs())
factory()->setParent(this);
foreach (AnalyzerSubConfigFactory factory, AnalyzerGlobalSettings::instance()->projectSubConfigFactories()) {
AbstractAnalyzerSubConfig *config = factory();
m_customConfigurations.append(config);
}
// take defaults from global settings
AnalyzerGlobalSettings *gs = AnalyzerGlobalSettings::instance();
fromMap(gs->toMap());
m_subConfigs = AnalyzerGlobalSettings::instance()->subConfigs();
resetCustomToGlobalSettings();
}
AnalyzerProjectSettings::~AnalyzerProjectSettings()
{
qDeleteAll(m_customConfigurations);
}
QString AnalyzerProjectSettings::displayName() const
......@@ -167,12 +185,35 @@ QString AnalyzerProjectSettings::displayName() const
bool AnalyzerProjectSettings::fromMap(const QVariantMap &map)
{
return AnalyzerSettings::fromMap(map);
if (!AnalyzerSettings::fromMap(map, &m_customConfigurations))
return false;
m_useGlobalSettings = map.value(QLatin1String(useGlobalC), true).toBool();
return true;
}
QVariantMap AnalyzerProjectSettings::toMap() const
{
return AnalyzerSettings::toMap();
QVariantMap map = AnalyzerSettings::toMap(m_customConfigurations);
map.insert(QLatin1String(useGlobalC), m_useGlobalSettings);
return map;
}
void AnalyzerProjectSettings::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 AnalyzerProjectSettings::resetCustomToGlobalSettings()
{
AnalyzerGlobalSettings *gs = AnalyzerGlobalSettings::instance();
AnalyzerSettings::fromMap(gs->toMap(), &m_customConfigurations);
}
} // namespace Analyzer
......@@ -95,12 +95,16 @@ public:
template<class T>
T *subConfig() const
{
return findChild<T *>();
foreach (AbstractAnalyzerSubConfig *subConfig, subConfigs()) {
if (T *config = qobject_cast<T *>(subConfig))
return config;
}
return 0;
}
QList<AbstractAnalyzerSubConfig *> subConfigs() const
{
return findChildren<AbstractAnalyzerSubConfig *>();
return m_subConfigs;
}
QVariantMap defaults() const;
......@@ -109,7 +113,11 @@ public:
protected:
virtual bool fromMap(const QVariantMap &map);
QVariantMap toMap(const QList<AbstractAnalyzerSubConfig *> &subConfigs) const;
bool fromMap(const QVariantMap &map, QList<AbstractAnalyzerSubConfig *> *subConfigs);
AnalyzerSettings(QObject *parent);
QList<AbstractAnalyzerSubConfig *> m_subConfigs;
};
......@@ -137,12 +145,12 @@ public:
void readSettings();
void registerSubConfigs(AnalyzerSubConfigFactory globalFactory, AnalyzerSubConfigFactory projectFactory);
QList<AnalyzerSubConfigFactory> projectSubConfigs() const;
QList<AnalyzerSubConfigFactory> projectSubConfigFactories() const;
private:
AnalyzerGlobalSettings(QObject *parent);
static AnalyzerGlobalSettings *m_instance;
QList<AnalyzerSubConfigFactory> m_projectSubConfigs;
QList<AnalyzerSubConfigFactory> m_projectSubConfigFactories;
};
/**
......@@ -161,12 +169,23 @@ class ANALYZER_EXPORT AnalyzerProjectSettings
public:
AnalyzerProjectSettings(QObject *parent = 0);
~AnalyzerProjectSettings();
QString displayName() const;
virtual QVariantMap toMap() const;
bool isUsingGlobalSettings() const { return m_useGlobalSettings; }
void setUsingGlobalSettings(bool value);
void resetCustomToGlobalSettings();
QList<AbstractAnalyzerSubConfig *> customSubConfigs() const { return m_customConfigurations; }
protected:
virtual bool fromMap(const QVariantMap &map);
private:
bool m_useGlobalSettings;
QList<AbstractAnalyzerSubConfig *> m_customConfigurations;
};
} // namespace Analyzer
......
......@@ -54,11 +54,14 @@ ValgrindConfigWidget::ValgrindConfigWidget(ValgrindBaseSettings *settings,
m_ui(new Ui::ValgrindConfigWidget)
{
m_ui->setupUi(this);
m_model = new QStandardItemModel(this);
m_ui->valgrindExeChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
m_ui->valgrindExeChooser->setPromptDialogTitle(tr("Valgrind Command"));
m_ui->valgrindExeChooser->setPath(m_settings->valgrindExecutable());
updateUi();
connect(m_settings, SIGNAL(changed()), this, SLOT(updateUi()));
connect(m_ui->valgrindExeChooser, SIGNAL(changed(QString)),
m_settings, SLOT(setValgrindExecutable(QString)));
connect(m_settings, SIGNAL(valgrindExecutableChanged(QString)),
......@@ -74,43 +77,36 @@ ValgrindConfigWidget::ValgrindConfigWidget(ValgrindBaseSettings *settings,
//
// Callgrind
//
m_ui->enableCacheSim->setChecked(m_settings->enableCacheSim());
connect(m_ui->enableCacheSim, SIGNAL(toggled(bool)),
m_settings, SLOT(setEnableCacheSim(bool)));
connect(m_settings, SIGNAL(enableCacheSimChanged(bool)),
m_ui->enableCacheSim, SLOT(setChecked(bool)));
m_ui->enableBranchSim->setChecked(m_settings->enableBranchSim());
connect(m_ui->enableBranchSim, SIGNAL(toggled(bool)),
m_settings, SLOT(setEnableBranchSim(bool)));
connect(m_settings, SIGNAL(enableBranchSimChanged(bool)),
m_ui->enableBranchSim, SLOT(setChecked(bool)));
m_ui->collectSystime->setChecked(m_settings->collectSystime());
connect(m_ui->collectSystime, SIGNAL(toggled(bool)),
m_settings, SLOT(setCollectSystime(bool)));
connect(m_settings, SIGNAL(collectSystimeChanged(bool)),
m_ui->collectSystime, SLOT(setChecked(bool)));
m_ui->collectBusEvents->setChecked(m_settings->collectBusEvents());
connect(m_ui->collectBusEvents, SIGNAL(toggled(bool)),
m_settings, SLOT(setCollectBusEvents(bool)));
connect(m_settings, SIGNAL(collectBusEventsChanged(bool)),
m_ui->collectBusEvents, SLOT(setChecked(bool)));
m_ui->enableEventToolTips->setChecked(m_settings->enableEventToolTips());
connect(m_ui->enableEventToolTips, SIGNAL(toggled(bool)),
m_settings, SLOT(setEnableEventToolTips(bool)));
connect(m_settings, SIGNAL(enableEventToolTipsChanged(bool)),
m_ui->enableEventToolTips, SLOT(setChecked(bool)));
m_ui->minimumInclusiveCostRatio->setValue(m_settings->minimumInclusiveCostRatio());
connect(m_ui->minimumInclusiveCostRatio, SIGNAL(valueChanged(double)),
m_settings, SLOT(setMinimumInclusiveCostRatio(double)));
connect(m_settings, SIGNAL(minimumInclusiveCostRatioChanged(double)),
m_ui->minimumInclusiveCostRatio, SLOT(setValue(double)));
m_ui->visualisationMinimumInclusiveCostRatio->setValue(m_settings->visualisationMinimumInclusiveCostRatio());
connect(m_ui->visualisationMinimumInclusiveCostRatio, SIGNAL(valueChanged(double)),
m_settings, SLOT(setVisualisationMinimumInclusiveCostRatio(double)));
connect(m_settings, SIGNAL(visualisationMinimumInclusiveCostRatioChanged(double)),
......@@ -119,8 +115,6 @@ ValgrindConfigWidget::ValgrindConfigWidget(ValgrindBaseSettings *settings,
//
// Memcheck
//
m_model = new QStandardItemModel(this);
m_ui->suppressionList->setModel(m_model);
m_ui->suppressionList->setSelectionMode(QAbstractItemView::MultiSelection);
......@@ -129,11 +123,9 @@ ValgrindConfigWidget::ValgrindConfigWidget(ValgrindBaseSettings *settings,
connect(m_ui->removeSuppression, SIGNAL(clicked()),
this, SLOT(slotRemoveSuppression()));
m_ui->numCallers->setValue(m_settings->numCallers());
connect(m_ui->numCallers, SIGNAL(valueChanged(int)), m_settings, SLOT(setNumCallers(int)));
connect(m_settings, SIGNAL(numCallersChanged(int)), m_ui->numCallers, SLOT(setValue(int)));
m_ui->trackOrigins->setChecked(m_settings->trackOrigins());
connect(m_ui->trackOrigins, SIGNAL(toggled(bool)),
m_settings, SLOT(setTrackOrigins(bool)));
connect(m_settings, SIGNAL(trackOriginsChanged(bool)),
......@@ -144,10 +136,6 @@ ValgrindConfigWidget::ValgrindConfigWidget(ValgrindBaseSettings *settings,
connect(m_settings, SIGNAL(suppressionFilesAdded(QStringList)),
this, SLOT(slotSuppressionsAdded(QStringList)));
m_model->clear();
foreach (const QString &file, m_settings->suppressionFiles())
m_model->appendRow(new QStandardItem(file));
connect(m_ui->suppressionList->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(slotSuppressionSelectionChanged()));
......@@ -169,6 +157,23 @@ ValgrindConfigWidget::~ValgrindConfigWidget()
delete m_ui;
}
void ValgrindConfigWidget::updateUi()
{
m_ui->valgrindExeChooser->setPath(m_settings->valgrindExecutable());
m_ui->enableCacheSim->setChecked(m_settings->enableCacheSim());
m_ui->enableBranchSim->setChecked(m_settings->enableBranchSim());
m_ui->collectSystime->setChecked(m_settings->collectSystime());
m_ui->collectBusEvents->setChecked(m_settings->collectBusEvents());
m_ui->enableEventToolTips->setChecked(m_settings->enableEventToolTips());
m_ui->minimumInclusiveCostRatio->setValue(m_settings->minimumInclusiveCostRatio());
m_ui->visualisationMinimumInclusiveCostRatio->setValue(m_settings->visualisationMinimumInclusiveCostRatio());
m_ui->numCallers->setValue(m_settings->numCallers());
m_ui->trackOrigins->setChecked(m_settings->trackOrigins());
m_model->clear();
foreach (const QString &file, m_settings->suppressionFiles())
m_model->appendRow(new QStandardItem(file));
}
void ValgrindConfigWidget::slotAddSuppression()
{
QFileDialog dialog;
......
......@@ -68,6 +68,9 @@ public Q_SLOTS:
void slotSuppressionsAdded(const QStringList &files);
void slotSuppressionSelectionChanged();
private slots:
void updateUi();
private:
ValgrindBaseSettings *m_settings;
Ui::ValgrindConfigWidget *m_ui;
......
......@@ -131,6 +131,7 @@ bool ValgrindBaseSettings::fromMap(const QVariantMap &map)
setIfPresent(map, QLatin1String(callgrindVisualisationMinimumCostRatioC),
&m_visualisationMinimumInclusiveCostRatio);
emit changed();
return true;
}
......
......@@ -62,6 +62,9 @@ public:
virtual QString id() const;
virtual QString displayName() const;
signals:
void changed(); // sent when multiple values have changed simulatenously (e.g. fromMap)
/**
* Base valgrind settings
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment