Commit 2d9de933 authored by Friedemann Kleint's avatar Friedemann Kleint

Debugger: Add a flexible widget for source path substitutions.

Add a new widget to edit the mappings. Rework common options
page to use the standard pattern to allow for complex data types,
introduce GlobalOptions class.
parent b9716532
......@@ -40,6 +40,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/manhattanstyle.h>
#include <utils/qtcassert.h>
#include <projectexplorer/projectexplorer.h>
......@@ -53,13 +54,90 @@ using namespace ProjectExplorer;
namespace Debugger {
namespace Internal {
CommonOptionsPageWidget::CommonOptionsPageWidget(const QSharedPointer<Utils::SavedActionSet> &group, QWidget *parent) :
QWidget(parent), m_group(group)
{
m_ui.setupUi(this);
m_group->clear();
m_group->insert(debuggerCore()->action(ListSourceFiles),
m_ui.checkBoxListSourceFiles);
m_group->insert(debuggerCore()->action(UseAlternatingRowColors),
m_ui.checkBoxUseAlternatingRowColors);
m_group->insert(debuggerCore()->action(UseToolTipsInMainEditor),
m_ui.checkBoxUseToolTipsInMainEditor);
m_group->insert(debuggerCore()->action(CloseBuffersOnExit),
m_ui.checkBoxCloseBuffersOnExit);
m_group->insert(debuggerCore()->action(SwitchModeOnExit),
m_ui.checkBoxSwitchModeOnExit);
m_group->insert(debuggerCore()->action(AutoDerefPointers), 0);
m_group->insert(debuggerCore()->action(UseToolTipsInLocalsView), 0);
m_group->insert(debuggerCore()->action(UseToolTipsInBreakpointsView), 0);
m_group->insert(debuggerCore()->action(UseAddressInBreakpointsView), 0);
m_group->insert(debuggerCore()->action(UseAddressInStackView), 0);
m_group->insert(debuggerCore()->action(MaximalStackDepth),
m_ui.spinBoxMaximalStackDepth);
m_group->insert(debuggerCore()->action(ShowStdNamespace), 0);
m_group->insert(debuggerCore()->action(ShowQtNamespace), 0);
m_group->insert(debuggerCore()->action(SortStructMembers), 0);
m_group->insert(debuggerCore()->action(LogTimeStamps), 0);
m_group->insert(debuggerCore()->action(VerboseLog), 0);
m_group->insert(debuggerCore()->action(BreakOnThrow), 0);
m_group->insert(debuggerCore()->action(BreakOnCatch), 0);
#ifdef Q_OS_WIN
Utils::SavedAction *registerAction = debuggerCore()->action(RegisterForPostMortem);
m_group->insert(registerAction,
m_ui.checkBoxRegisterForPostMortem);
connect(registerAction, SIGNAL(toggled(bool)),
m_ui.checkBoxRegisterForPostMortem, SLOT(setChecked(bool)));
#else
m_ui.checkBoxRegisterForPostMortem->setVisible(false);
#endif
}
QString CommonOptionsPageWidget::searchKeyWords() const
{
QString rc;
const QLatin1Char sep(' ');
QTextStream(&rc)
<< sep << m_ui.checkBoxUseAlternatingRowColors->text()
<< sep << m_ui.checkBoxUseToolTipsInMainEditor->text()
<< sep << m_ui.checkBoxListSourceFiles->text()
#ifdef Q_OS_WIN
<< sep << m_ui.checkBoxRegisterForPostMortem->text()
#endif
<< sep << m_ui.checkBoxCloseBuffersOnExit->text()
<< sep << m_ui.checkBoxSwitchModeOnExit->text()
<< sep << m_ui.labelMaximalStackDepth->text()
;
rc.remove(QLatin1Char('&'));
return rc;
}
GlobalDebuggerOptions CommonOptionsPageWidget::globalOptions() const
{
GlobalDebuggerOptions o;
o.sourcePathMap = m_ui.sourcesMappingWidget->sourcePathMap();
return o;
}
void CommonOptionsPageWidget::setGlobalOptions(const GlobalDebuggerOptions &go)
{
m_ui.sourcesMappingWidget->setSourcePathMap(go.sourcePathMap);
}
///////////////////////////////////////////////////////////////////////
//
// CommonOptionsPage
//
///////////////////////////////////////////////////////////////////////
CommonOptionsPage::CommonOptionsPage()
CommonOptionsPage::CommonOptionsPage(const QSharedPointer<GlobalDebuggerOptions> &go) :
m_options(go)
{
}
CommonOptionsPage::~CommonOptionsPage()
{
}
......@@ -88,73 +166,33 @@ QIcon CommonOptionsPage::categoryIcon() const
void CommonOptionsPage::apply()
{
m_group.apply(ICore::instance()->settings());
QTC_ASSERT(!m_widget.isNull() && !m_group.isNull(), return; )
QSettings *settings = ICore::instance()->settings();
m_group->apply(settings);
const GlobalDebuggerOptions newGlobalOptions = m_widget->globalOptions();
if (newGlobalOptions != *m_options) {
*m_options = newGlobalOptions;
m_options->toSettings(settings);
}
}
void CommonOptionsPage::finish()
{
m_group.finish();
QTC_ASSERT(!m_group.isNull(), return; )
m_group->finish();
}
QWidget *CommonOptionsPage::createPage(QWidget *parent)
{
QWidget *w = new QWidget(parent);
m_ui.setupUi(w);
m_group.clear();
m_group.insert(debuggerCore()->action(ListSourceFiles),
m_ui.checkBoxListSourceFiles);
m_group.insert(debuggerCore()->action(UseAlternatingRowColors),
m_ui.checkBoxUseAlternatingRowColors);
m_group.insert(debuggerCore()->action(UseToolTipsInMainEditor),
m_ui.checkBoxUseToolTipsInMainEditor);
m_group.insert(debuggerCore()->action(CloseBuffersOnExit),
m_ui.checkBoxCloseBuffersOnExit);
m_group.insert(debuggerCore()->action(SwitchModeOnExit),
m_ui.checkBoxSwitchModeOnExit);
m_group.insert(debuggerCore()->action(AutoDerefPointers), 0);
m_group.insert(debuggerCore()->action(UseToolTipsInLocalsView), 0);
m_group.insert(debuggerCore()->action(UseToolTipsInBreakpointsView), 0);
m_group.insert(debuggerCore()->action(UseAddressInBreakpointsView), 0);
m_group.insert(debuggerCore()->action(UseAddressInStackView), 0);
m_group.insert(debuggerCore()->action(MaximalStackDepth),
m_ui.spinBoxMaximalStackDepth);
m_group.insert(debuggerCore()->action(ShowStdNamespace), 0);
m_group.insert(debuggerCore()->action(ShowQtNamespace), 0);
m_group.insert(debuggerCore()->action(SortStructMembers), 0);
m_group.insert(debuggerCore()->action(LogTimeStamps), 0);
m_group.insert(debuggerCore()->action(VerboseLog), 0);
m_group.insert(debuggerCore()->action(BreakOnThrow), 0);
m_group.insert(debuggerCore()->action(BreakOnCatch), 0);
m_group.insert(debuggerCore()->action(QtSourcesLocation),
m_ui.qtSourcesChooser);
#ifdef Q_OS_WIN
Utils::SavedAction *registerAction = debuggerCore()->action(RegisterForPostMortem);
m_group.insert(registerAction,
m_ui.checkBoxRegisterForPostMortem);
connect(registerAction, SIGNAL(toggled(bool)),
m_ui.checkBoxRegisterForPostMortem, SLOT(setChecked(bool)));
#endif
if (m_searchKeywords.isEmpty()) {
QLatin1Char sep(' ');
QTextStream(&m_searchKeywords)
<< sep << m_ui.checkBoxUseAlternatingRowColors->text()
<< sep << m_ui.checkBoxUseToolTipsInMainEditor->text()
<< sep << m_ui.checkBoxListSourceFiles->text()
#ifdef Q_OS_WIN
<< sep << m_ui.checkBoxRegisterForPostMortem->text()
#endif
<< sep << m_ui.checkBoxCloseBuffersOnExit->text()
<< sep << m_ui.checkBoxSwitchModeOnExit->text()
<< sep << m_ui.labelMaximalStackDepth->text()
;
m_searchKeywords.remove(QLatin1Char('&'));
}
#ifndef Q_OS_WIN
m_ui.checkBoxRegisterForPostMortem->setVisible(false);
#endif
return w;
if (m_group.isNull())
m_group = QSharedPointer<Utils::SavedActionSet>(new Utils::SavedActionSet);
m_widget = new CommonOptionsPageWidget(m_group, parent);
m_widget->setGlobalOptions(*m_options);
if (m_searchKeywords.isEmpty())
m_searchKeywords = m_widget->searchKeyWords();
return m_widget;
}
bool CommonOptionsPage::matches(const QString &s) const
......
......@@ -40,8 +40,13 @@
#include <coreplugin/dialogs/ioptionspage.h>
#include <utils/savedaction.h>
#include <QtCore/QSharedPointer>
#include <QtCore/QPointer>
#include <QtGui/QWidget>
namespace Debugger {
namespace Internal {
class GlobalDebuggerOptions;
///////////////////////////////////////////////////////////////////////
//
......@@ -49,12 +54,27 @@ namespace Internal {
//
///////////////////////////////////////////////////////////////////////
class CommonOptionsPageWidget : public QWidget
{
public:
explicit CommonOptionsPageWidget(const QSharedPointer<Utils::SavedActionSet> &group, QWidget *parent = 0);
QString searchKeyWords() const;
GlobalDebuggerOptions globalOptions() const;
void setGlobalOptions(const GlobalDebuggerOptions &go);
private:
Ui::CommonOptionsPage m_ui;
const QSharedPointer<Utils::SavedActionSet> m_group;
};
class CommonOptionsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
CommonOptionsPage();
explicit CommonOptionsPage(const QSharedPointer<GlobalDebuggerOptions> &go);
virtual ~CommonOptionsPage();
// IOptionsPage
QString id() const;
......@@ -68,10 +88,10 @@ public:
bool matches(const QString &s) const;
private:
typedef QMap<QString, QString> AbiToDebuggerMap;
Ui::CommonOptionsPage m_ui;
Utils::SavedActionSet m_group;
const QSharedPointer<GlobalDebuggerOptions> m_options;
QSharedPointer<Utils::SavedActionSet> m_group;
QString m_searchKeywords;
QPointer<CommonOptionsPageWidget> m_widget;
};
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>361</width>
<width>387</width>
<height>334</height>
</rect>
</property>
......@@ -130,30 +130,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="sourcesBox">
<property name="title">
<string>Sources</string>
</property>
<layout class="QGridLayout" name="sourcesGridLayout">
<item row="7" column="0">
<widget class="QLabel" name="labelQtSources">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Qt Sources:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="Utils::PathChooser" name="qtSourcesChooser" native="true">
</widget>
</item>
</layout>
</widget>
<widget class="Debugger::Internal::DebuggerSourcePathMappingWidget" name="sourcesMappingWidget"/>
</item>
<item>
<spacer name="verticalSpacer">
......@@ -175,9 +152,10 @@
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<class>Debugger::Internal::DebuggerSourcePathMappingWidget</class>
<extends>QGroupBox</extends>
<header>debuggersourcepathmappingwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
......
......@@ -62,7 +62,8 @@ HEADERS += breakhandler.h \
watchdelegatewidgets.h \
debuggerruncontrolfactory.h \
debuggertooltipmanager.h \
debuggertoolchaincombobox.h
debuggertoolchaincombobox.h \
debuggersourcepathmappingwidget.h
SOURCES += breakhandler.cpp \
breakpoint.cpp \
......@@ -104,7 +105,8 @@ SOURCES += breakhandler.cpp \
stackframe.cpp \
watchdelegatewidgets.cpp \
debuggertooltipmanager.cpp \
debuggertoolchaincombobox.cpp
debuggertoolchaincombobox.cpp \
debuggersourcepathmappingwidget.cpp
FORMS += attachexternaldialog.ui \
attachcoredialog.ui \
......
......@@ -47,10 +47,45 @@
using namespace Utils;
static const char debugModeSettingsGroupC[] = "DebugMode";
static const char sourcePathMappingArrayNameC[] = "SourcePathMappings";
static const char sourcePathMappingSourceKeyC[] = "Source";
static const char sourcePathMappingTargetKeyC[] = "Target";
namespace Debugger {
namespace Internal {
void GlobalDebuggerOptions::toSettings(QSettings *s) const
{
s->beginWriteArray(QLatin1String(sourcePathMappingArrayNameC));
if (!sourcePathMap.isEmpty()) {
const QString sourcePathMappingSourceKey = QLatin1String(sourcePathMappingSourceKeyC);
const QString sourcePathMappingTargetKey = QLatin1String(sourcePathMappingTargetKeyC);
int i = 0;
const SourcePathMap::const_iterator cend = sourcePathMap.constEnd();
for (SourcePathMap::const_iterator it = sourcePathMap.constBegin(); it != cend; ++it, ++i) {
s->setArrayIndex(i);
s->setValue(sourcePathMappingSourceKey, it.key());
s->setValue(sourcePathMappingTargetKey, it.value());
}
}
s->endArray();
}
void GlobalDebuggerOptions::fromSettings(QSettings *s)
{
sourcePathMap.clear();
if (const int count = s->beginReadArray(QLatin1String(sourcePathMappingArrayNameC))) {
const QString sourcePathMappingSourceKey = QLatin1String(sourcePathMappingSourceKeyC);
const QString sourcePathMappingTargetKey = QLatin1String(sourcePathMappingTargetKeyC);
for (int i = 0; i < count; ++i) {
s->setArrayIndex(i);
sourcePathMap.insert(s->value(sourcePathMappingSourceKey).toString(),
s->value(sourcePathMappingTargetKey).toString());
}
}
s->endArray();
}
//////////////////////////////////////////////////////////////////////////
//
// DebuggerSettings
......@@ -400,14 +435,8 @@ DebuggerSettings::DebuggerSettings(QSettings *settings)
item->setSettingsKey(debugModeGroup, QLatin1String("WatchdogTimeout"));
item->setDefaultValue(20);
insertItem(GdbWatchdogTimeout, item);
item = new SavedAction(this);
item->setSettingsKey(debugModeGroup, QLatin1String("QtSourcesLocation"));
item->setDefaultValue(QString());
insertItem(QtSourcesLocation, item);
}
DebuggerSettings::~DebuggerSettings()
{
qDeleteAll(m_items);
......@@ -450,7 +479,7 @@ QString DebuggerSettings::dump() const
if (!key.isEmpty()) {
const QString current = item->value().toString();
const QString default_ = item->defaultValue().toString();
ts << '\n' << key << ": " << current
ts << '\n' << key << ": " << current
<< " (default: " << default_ << ")";
if (current != default_)
ts << " ***";
......
......@@ -35,6 +35,7 @@
#define DEBUGGER_ACTIONS_H
#include <QtCore/QHash>
#include <QtCore/QMap>
QT_BEGIN_NAMESPACE
class QSettings;
......@@ -47,6 +48,22 @@ class SavedAction;
namespace Debugger {
namespace Internal {
// Global debugger options that are not stored as saved action.
class GlobalDebuggerOptions
{
public:
typedef QMap<QString, QString> SourcePathMap;
void toSettings(QSettings *) const;
void fromSettings(QSettings *);
bool equals(const GlobalDebuggerOptions &rhs) const { return sourcePathMap == rhs.sourcePathMap; }
SourcePathMap sourcePathMap;
};
inline bool operator==(const GlobalDebuggerOptions &o1, const GlobalDebuggerOptions &o2) { return o1.equals(o2); }
inline bool operator!=(const GlobalDebuggerOptions &o1, const GlobalDebuggerOptions &o2) { return !o1.equals(o2); }
class DebuggerSettings : public QObject
{
Q_OBJECT // For tr().
......@@ -88,7 +105,6 @@ enum DebuggerActionCode
UseDebuggingHelpers,
UseCustomDebuggingHelperLocation,
CustomDebuggingHelperLocation,
QtSourcesLocation,
UseCodeModel,
ShowThreadNames,
......
......@@ -39,6 +39,7 @@
#include <projectexplorer/abi.h>
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
QT_BEGIN_NAMESPACE
class QIcon;
......@@ -64,6 +65,7 @@ class BreakHandler;
class SnapshotHandler;
class Symbol;
class DebuggerToolTipManager;
class GlobalDebuggerOptions;
class DebuggerCore : public QObject
{
......@@ -116,6 +118,7 @@ public:
virtual QString stringSetting(int code) const = 0;
virtual DebuggerToolTipManager *toolTipManager() const = 0;
virtual QSharedPointer<GlobalDebuggerOptions> globalDebuggerOptions() const = 0;
};
// This is the only way to access the global object.
......
......@@ -972,6 +972,7 @@ public slots:
unsigned *enabledEngines, QString *errorMessage);
DebuggerToolTipManager *toolTipManager() const { return m_toolTipManager; }
virtual QSharedPointer<GlobalDebuggerOptions> globalDebuggerOptions() const { return m_globalDebuggerOptions; }
public:
DebuggerMainWindow *m_mainWindow;
......@@ -1053,11 +1054,13 @@ public:
DebuggerToolTipManager *m_toolTipManager;
CommonOptionsPage *m_commonOptionsPage;
DummyEngine *m_dummyEngine;
const QSharedPointer<GlobalDebuggerOptions> m_globalDebuggerOptions;
};
DebuggerPluginPrivate::DebuggerPluginPrivate(DebuggerPlugin *plugin) :
m_toolTipManager(new DebuggerToolTipManager(this)),
m_dummyEngine(0)
m_dummyEngine(0),
m_globalDebuggerOptions(new GlobalDebuggerOptions)
{
qRegisterMetaType<WatchData>("WatchData");
qRegisterMetaType<ContextData>("ContextData");
......@@ -2714,7 +2717,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
dock = m_mainWindow->createDockWidget(CppLanguage, localsAndWatchers);
dock->setProperty(DOCKWIDGET_DEFAULT_AREA, Qt::RightDockWidgetArea);
m_commonOptionsPage = new CommonOptionsPage;
m_commonOptionsPage = new CommonOptionsPage(m_globalDebuggerOptions);
m_plugin->addAutoReleasedObject(m_commonOptionsPage);
m_debuggerSettings->readSettings();
......@@ -3069,6 +3072,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
SLOT(onCurrentProjectChanged(ProjectExplorer::Project*)));
QTC_ASSERT(m_coreSettings, /**/);
m_globalDebuggerOptions->fromSettings(m_coreSettings);
m_watchersWindow->setVisible(false);
m_returnWindow->setVisible(false);
......
This diff is collapsed.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef DEBUGGERSOURCEPATHMAPPINGWIDGET_H
#define DEBUGGERSOURCEPATHMAPPINGWIDGET_H
#include <QtGui/QGroupBox>
#include <QtCore/QMap>
#include <QtCore/QPair>
QT_BEGIN_NAMESPACE
class QStandardItemModel;
class QTreeView;
class QLineEdit;
class QPushButton;
class QLineEdit;
class QModelIndex;
QT_END_NAMESPACE
namespace Utils {
class PathChooser;
}
namespace Debugger {
namespace Internal {
class SourcePathMappingModel;
class DebuggerSourcePathMappingWidget : public QGroupBox
{
Q_OBJECT
public:
typedef QMap<QString, QString> SourcePathMap;
explicit DebuggerSourcePathMappingWidget(QWidget *parent = 0);
SourcePathMap sourcePathMap() const;
void setSourcePathMap(const SourcePathMap &);
signals:
private slots:
void slotAdd();
void slotAddQt();
void slotRemove();
void slotCurrentRowChanged(const QModelIndex &,const QModelIndex &);
void slotEditSourceFieldChanged();
void slotEditTargetFieldChanged();
private:
void resizeColumns();
void updateEnabled();
QString editSourceField() const;
QString editTargetField() const;
void setEditFieldMapping(const QPair<QString, QString> &m);
int currentRow() const;
void setCurrentRow(int r);
SourcePathMappingModel *m_model;
QTreeView *m_treeView;
QPushButton *m_addButton;
QPushButton *m_addQtButton;
QPushButton *m_removeButton;
QLineEdit *m_sourceLineEdit;
Utils::PathChooser *m_targetChooser;
};
} // namespace Internal
} // namespace Debugger
#endif // DEBUGGERSOURCEPATHMAPPINGWIDGET_H
......@@ -4564,22 +4564,19 @@ void GdbEngine::notifyInferiorSetupFailed()
void GdbEngine::handleInferiorPrepared()
{
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
const QByteArray qtInstallPath =
debuggerCore()->action(QtSourcesLocation)->value().toString().toLocal8Bit();
if (!qtInstallPath.isEmpty()) {
QByteArray qtBuildPath;
#if defined(Q_OS_WIN)
qtBuildPath = "C:/qt-greenhouse/Trolltech/Code_less_create_more/"
"Trolltech/Code_less_create_more/Troll/4.6/qt";
postCommand("set substitute-path " + qtBuildPath + ' ' + qtInstallPath);
qtBuildPath = "C:/iwmake/build_mingw_opensource";
postCommand("set substitute-path " + qtBuildPath + ' ' + qtInstallPath);
qtBuildPath = "C:/ndk_buildrepos/qt-desktop/src";
postCommand("set substitute-path " + qtBuildPath + ' ' + qtInstallPath);
#elif defined(Q_OS_UNIX) && !defined (Q_OS_MAC)
qtBuildPath = "/var/tmp/qt-src";
postCommand("set substitute-path " + qtBuildPath + ' ' + qtInstallPath);
#endif
// Apply source path mappings from global options.
const QSharedPointer<GlobalDebuggerOptions> globalOptions = debuggerCore()->globalDebuggerOptions();
if (!globalOptions->sourcePathMap.isEmpty()) {
typedef GlobalDebuggerOptions::SourcePathMap::const_iterator SourcePathMapIterator;
const SourcePathMapIterator cend = globalOptions->sourcePathMap.constEnd();
for (SourcePathMapIterator it = globalOptions->sourcePathMap.constBegin(); it != cend; ++it) {
QByteArray command = "set substitute-path ";
command += it.key().toLocal8Bit();
command += ' ';
command += it.value().toLocal8Bit();
postCommand(command);