Commit 0b58f1f5 authored by hjk's avatar hjk
Browse files

debugger: reorganizing settings and actions in progress

parent 5f139b49
......@@ -105,6 +105,7 @@ PathChooser::PathChooser(QWidget *parent) :
connect(m_d->m_lineEdit, SIGNAL(validReturnPressed()), this, SIGNAL(returnPressed()));
connect(m_d->m_lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
connect(m_d->m_lineEdit, SIGNAL(validChanged()), this, SIGNAL(validChanged()));
connect(m_d->m_lineEdit, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
m_d->m_lineEdit->setMinimumWidth(200);
hLayout->addWidget(m_d->m_lineEdit);
......
......@@ -89,6 +89,7 @@ private:
signals:
void validChanged();
void changed();
void editingFinished();
void beforeBrowsing();
void browsingFinished();
void returnPressed();
......
......@@ -94,7 +94,6 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
QAction *act3 = new QAction("Edit condition...", &menu);
act0->setEnabled(index.isValid());
QAction *act4 = new QAction("Syncronize breakpoints", &menu);
QAction *act5 = action(SettingsDialog);
menu.addAction(act0);
menu.addAction(act3);
......@@ -102,7 +101,7 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
menu.addAction(act1);
menu.addAction(act2);
menu.addAction(act4);
menu.addAction(act5);
menu.addAction(theDebuggerSettings()->action(SettingsDialog));
QAction *act = menu.exec(ev->globalPos());
......@@ -116,8 +115,6 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
editCondition(index);
else if (act == act4)
emit breakpointSynchronizationRequested();
else if (act == act5)
act->trigger();
}
void BreakWindow::deleteBreakpoint(const QModelIndex &idx)
......
......@@ -29,73 +29,451 @@
#include "debuggeractions.h"
#include <utils/qtcassert.h>
#include <utils/pathchooser.h>
#include <QtCore/QSettings>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QAbstractButton>
#include <QtGui/QRadioButton>
#include <QtGui/QCheckBox>
#include <QtGui/QLineEdit>
namespace Debugger {
namespace Internal {
//////////////////////////////////////////////////////////////////////////
//
// QtcSettingsItem
//
//////////////////////////////////////////////////////////////////////////
QtcSettingsItem::QtcSettingsItem(QObject *parent)
: QObject(parent)
{
m_action = new QAction(this);
connect(m_action, SIGNAL(triggered(bool)), this, SLOT(actionTriggered(bool)));
}
QVariant QtcSettingsItem::value() const
{
return m_value;
}
void QtcSettingsItem::setValue(const QVariant &value, bool doemit)
{
if (value != m_value) {
m_value = value;
if (m_action->isCheckable())
m_action->setChecked(m_value.toBool());
if (doemit) {
emit valueChanged(m_value);
emit boolValueChanged(m_value.toBool());
emit stringValueChanged(m_value.toString());
}
}
}
QVariant QtcSettingsItem::defaultValue() const
{
return m_defaultValue;
}
void QtcSettingsItem::setDefaultValue(const QVariant &value)
{
m_defaultValue = value;
}
QString QtcSettingsItem::settingsKey() const
{
return m_settingsKey;
}
void QtcSettingsItem::setSettingsKey(const QString &key)
{
m_settingsKey = key;
}
void QtcSettingsItem::setSettingsKey(const QString &group, const QString &key)
{
m_settingsKey = key;
m_settingsGroup = group;
}
QString QtcSettingsItem::settingsGroup() const
{
return m_settingsGroup;
}
void QtcSettingsItem::setSettingsGroup(const QString &group)
{
m_settingsGroup = group;
}
QString QtcSettingsItem::text() const
{
return m_action->text();
}
void QtcSettingsItem::setText(const QString &value)
{
if (!value.isEmpty() && !m_textPattern.isEmpty())
m_action->setText(m_textPattern.arg(value));
else
m_action->setText(value);
}
QString QtcSettingsItem::textPattern() const
{
return m_textPattern;
}
void QtcSettingsItem::setTextPattern(const QString &value)
{
m_textPattern = value;
}
void QtcSettingsItem::readSettings(QSettings *settings)
{
if (m_settingsGroup.isEmpty() || m_settingsKey.isEmpty())
return;
settings->beginGroup(m_settingsGroup);
setValue(settings->value(m_settingsKey, m_defaultValue), false);
qDebug() << "READING: " << m_settingsKey << " -> " << m_value;
settings->endGroup();
}
void QtcSettingsItem::writeSettings(QSettings *settings)
{
if (m_settingsGroup.isEmpty() || m_settingsKey.isEmpty())
return;
settings->beginGroup(m_settingsGroup);
settings->setValue(m_settingsKey, m_value);
qDebug() << "WRITING: " << m_settingsKey << " -> " << m_value;
settings->endGroup();
}
QAction *QtcSettingsItem::action() const
{
return m_action;
}
void QtcSettingsItem::connectWidget(QWidget *widget, ApplyMode applyMode)
{
using namespace Core::Utils;
//qDebug() << "CONNECT WIDGET " << widget << " TO " << m_settingsKey;
m_applyModes[widget] = applyMode;
m_deferedValue = m_value;
if (QAbstractButton *button = qobject_cast<QAbstractButton *>(widget)) {
if (button->isCheckable()) {
button->setChecked(m_value.toBool());
connect(button, SIGNAL(clicked(bool)),
this, SLOT(checkableButtonClicked(bool)));
} else {
connect(button, SIGNAL(clicked()),
this, SLOT(uncheckableButtonClicked()));
}
} else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget)) {
lineEdit->setText(m_value.toString());
//qDebug() << "SETTING TEXT" << lineEdit->text();
connect(lineEdit, SIGNAL(editingFinished()),
this, SLOT(lineEditEditingFinished()));
} else if (PathChooser *pathChooser = qobject_cast<PathChooser *>(widget)) {
pathChooser->setPath(m_value.toString());
connect(pathChooser, SIGNAL(editingFinished()),
this, SLOT(pathChooserEditingFinished()));
connect(pathChooser, SIGNAL(browsingFinished()),
this, SLOT(pathChooserEditingFinished()));
} else {
qDebug() << "CANNOT CONNECT WIDGET " << widget;
}
}
void QtcSettingsItem::applyDeferedChange()
{
setValue(m_deferedValue);
}
void QtcSettingsItem::uncheckableButtonClicked()
{
QAbstractButton *button = qobject_cast<QAbstractButton *>(sender());
QTC_ASSERT(button, return);
qDebug() << "UNCHECKABLE BUTTON: " << sender();
m_action->trigger();
}
void QtcSettingsItem::checkableButtonClicked(bool)
{
QAbstractButton *button = qobject_cast<QAbstractButton *>(sender());
QTC_ASSERT(button, return);
qDebug() << "CHECKABLE BUTTON: " << sender();
if (m_applyModes[sender()] == DeferedApply)
m_deferedValue = button->isChecked();
else
setValue(button->isChecked());
}
void QtcSettingsItem::lineEditEditingFinished()
{
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(sender());
QTC_ASSERT(lineEdit, return);
qDebug() << "LINEEDIT: " << sender() << lineEdit->text();
if (m_applyModes[sender()] == DeferedApply)
m_deferedValue = lineEdit->text();
else
setValue(lineEdit->text());
}
void QtcSettingsItem::pathChooserEditingFinished()
{
using namespace Core::Utils;
PathChooser *pathChooser = qobject_cast<PathChooser *>(sender());
QTC_ASSERT(pathChooser, return);
qDebug() << "PATHCHOOSER: " << sender() << pathChooser->path();
if (m_applyModes[sender()] == DeferedApply)
m_deferedValue = pathChooser->path();
else
setValue(pathChooser->path());
}
void QtcSettingsItem::actionTriggered(bool on)
{
Q_UNUSED(on);
if (QAction *action = qobject_cast<QAction *>(sender())) {
if (action->isCheckable())
setValue(action->isChecked());
}
}
//////////////////////////////////////////////////////////////////////////
//
// Debugger specific stuff
// QtcSettings
//
//////////////////////////////////////////////////////////////////////////
struct ActionData
QtcSettings::QtcSettings(QObject *parent)
: QObject(parent)
{}
QtcSettings::~QtcSettings()
{
ActionCode code;
const char *text;
bool checkable;
};
qDeleteAll(m_items);
}
QtcSettingsItem *QtcSettings::createItem(int code)
{
return m_items[code] = new QtcSettingsItem;
}
static ActionData data[] =
void QtcSettings::insertItem(int code, QtcSettingsItem *item)
{
//
// General
//
{ AdjustColumnWidths,
QT_TR_NOOP("Adjust column widths to contents"), false },
{ AlwaysAdjustColumnWidths,
QT_TR_NOOP("Adjust column widths to contents"), true },
m_items[code] = item;
}
void QtcSettings::readSettings(QSettings *settings)
{
foreach (QtcSettingsItem *item, m_items)
item->readSettings(settings);
}
void QtcSettings::writeSettings(QSettings *settings)
{
foreach (QtcSettingsItem *item, m_items)
item->writeSettings(settings);
}
QtcSettingsItem *QtcSettings::item(int code)
{
QTC_ASSERT(m_items.value(code, 0), return 0);
return m_items.value(code, 0);
}
bool QtcSettings::boolValue(int code)
{
return item(code)->value().toBool();
}
QString QtcSettings::stringValue(int code)
{
return item(code)->value().toString();
}
int QtcSettings::intValue(int code)
{
return item(code)->value().toInt();
}
QAction *QtcSettings::action(int code)
{
return item(code)->action();
}
void QtcSettings::applyDeferedChanges()
{
foreach (QtcSettingsItem *item, m_items)
item->applyDeferedChange();
}
void QtcSettings::applyDeferedChange(int code)
{
return item(code)->applyDeferedChange();
}
void QtcSettings::connectWidget(int code, QWidget *widget, ApplyMode applyMode)
{
item(code)->connectWidget(widget, applyMode);
}
QString QtcSettings::dump()
{
QString out;
QTextStream ts(&out);
ts << "Debugger settings: ";
foreach (QtcSettingsItem *item, m_items)
ts << "\n" << item->value().toString();
return out;
}
//////////////////////////////////////////////////////////////////////////
//
// Debugger specific stuff
//
//////////////////////////////////////////////////////////////////////////
#if 0
QString dump();
QString m_gdbCmd;
QString m_gdbEnv;
bool m_autoRun;
bool m_autoQuit;
bool m_useDumpers;
bool m_skipKnownFrames;
bool m_debugDumpers;
bool m_useToolTips;
bool m_listSourceFiles;
QString m_scriptFile;
bool m_pluginAllBreakpoints;
bool m_pluginSelectedBreakpoints;
bool m_pluginNoBreakpoints;
QString m_pluginSelectedBreakpointsPattern;
#endif
QtcSettings *theDebuggerSettings()
{
static QtcSettings *instance = 0;
if (instance)
return instance;
instance = new QtcSettings;
QtcSettingsItem *item = 0;
item = instance->createItem(AdjustColumnWidths);
item->setText(QObject::tr("Adjust column widths to contents"));
item = instance->createItem(AlwaysAdjustColumnWidths);
item->setText(QObject::tr("Always adjust column widths to contents"));
item->action()->setCheckable(true);
item = instance->createItem(WatchExpression);
item->setTextPattern(QObject::tr("Watch expression \"%1\""));
item = instance->createItem(RemoveWatchExpression);
item->setTextPattern(QObject::tr("Remove watch expression \"%1\""));
item = instance->createItem(SettingsDialog);
item->setText(QObject::tr("Debugger properties..."));
item = instance->createItem(DebugDumpers);
item->setText(QObject::tr("Debug custom dumpers"));
item->action()->setCheckable(true);
item = instance->createItem(RecheckDumpers);
item->setText(QObject::tr("Recheck custom dumper availability"));
//
// Locals & Watchers
// Breakpoints
//
{ WatchExpression,
QT_TR_NOOP("Watch expression '%1'"), false },
{ WatchExpression,
QT_TR_NOOP("Watch expression '%1'"), false },
{ SettingsDialog,
QT_TR_NOOP("Debugger properties..."), false },
{ UseDumpers,
QT_TR_NOOP("Use custom dumpers"), true },
{ DebugDumpers,
QT_TR_NOOP("Debug custom dumpers"), true },
{ RecheckDumpers,
QT_TR_NOOP("Recheck custom dumper availability"), true },
item = instance->createItem(SynchronizeBreakpoints);
item->setText(QObject::tr("Syncronize breakpoints"));
//
// Breakpoints
item = instance->createItem(AutoQuit);
item->setText(QObject::tr("Automatically quit debugger"));
item->action()->setCheckable(true);
item = instance->createItem(SkipKnownFrames);
item->setText(QObject::tr("Skip known frames"));
item->action()->setCheckable(true);
item = instance->createItem(UseToolTips);
item->setText(QObject::tr("Use tooltips when debugging"));
item->action()->setCheckable(true);
item = instance->createItem(ListSourceFiles);
item->setText(QObject::tr("List source files"));
item->action()->setCheckable(true);
//
// Settings
//
{ SynchronizeBreakpoints,
QT_TR_NOOP("Syncronize breakpoints"), false },
};
item = instance->createItem(GdbLocation);
item->setSettingsKey("DebugMode", "Location");
QAction *action(ActionCode code)
{
static QHash<ActionCode, QAction *> actions;
item = instance->createItem(GdbEnvironment);
item->setSettingsKey("DebugMode", "Environment");
if (actions.isEmpty()) {
for (int i = 0; i != sizeof(data)/sizeof(data[0]); ++i) {
const ActionData &d = data[i];
QAction *act = new QAction(QObject::tr(d.text), 0);
act->setCheckable(d.checkable);
actions[d.code] = act;
}
}
item = instance->createItem(GdbScriptFile);
item->setSettingsKey("DebugMode", "ScriptFile");
item = instance->createItem(GdbAutoQuit);
item->setSettingsKey("DebugMode", "AutoQuit");
item = instance->createItem(GdbAutoRun);
item->setSettingsKey("DebugMode", "AutoRun");
item = instance->createItem(UseToolTips);
item->setSettingsKey("DebugMode", "UseToolTips");
item = instance->createItem(UseDumpers);
item->setSettingsKey("DebugMode", "UseCustomDumpers");
item->setText(QObject::tr("Use custom dumpers"));
item->action()->setCheckable(true);
item = instance->createItem(ListSourceFiles);
item->setSettingsKey("DebugMode", "ListSourceFiles");
item = instance->createItem(SkipKnownFrames);
item->setSettingsKey("DebugMode", "SkipKnownFrames");
item = instance->createItem(DebugDumpers);
item->setSettingsKey("DebugMode", "DebugDumpers");
item = instance->createItem(AllPluginBreakpoints);
item->setSettingsKey("DebugMode", "AllPluginBreakpoints");
item = instance->createItem(SelectedPluginBreakpoints);
item->setSettingsKey("DebugMode", "SelectedPluginBreakpoints");
item = instance->createItem(NoPluginBreakpoints);
item->setSettingsKey("DebugMode", "NoPluginBreakpoints");
item = instance->createItem(SelectedPluginBreakpointsPattern);
item->setSettingsKey("DebugMode", "SelectedPluginBreakpointsPattern");
return actions.value(code);
return instance;
}
} // namespace Internal
......
......@@ -30,12 +30,114 @@
#ifndef DEBUGGER_ACTIONS_H
#define DEBUGGER_ACTIONS_H
#include <QtGui/QAction>
#include <QtCore/QHash>
#include <QtCore/QString>
#include <QtCore/QVariant>
QT_BEGIN_NAMESPACE
class QAction;
class QSettings;
QT_END_NAMESPACE
namespace Debugger {
namespace Internal {
enum ActionCode
enum ApplyMode { ImmediateApply, DeferedApply };
class QtcSettingsItem : public QObject
{
Q_OBJECT
public:
QtcSettingsItem(QObject *parent = 0);
virtual QVariant value() const;
Q_SLOT virtual void setValue(const QVariant &value, bool doemit = true);
virtual QVariant defaultValue() const;
Q_SLOT virtual void setDefaultValue(const QVariant &value);
virtual QAction *action() const;
// used for persistency
virtual QString settingsKey() const;
Q_SLOT virtual void setSettingsKey(const QString &key);
Q_SLOT virtual void setSettingsKey(const QString &group, const QString &key);
virtual QString settingsGroup() const;
Q_SLOT virtual void setSettingsGroup(const QString &group);
virtual void readSettings(QSettings *settings);
Q_SLOT virtual void writeSettings(QSettings *settings);
virtual void connectWidget(QWidget *widget, ApplyMode applyMode = DeferedApply);
Q_SLOT virtual void applyDeferedChange();
virtual QString text() const;
Q_SLOT virtual void setText(const QString &value);
virtual QString textPattern() const;
Q_SLOT virtual void setTextPattern(const QString &value);
signals:
void valueChanged(const QVariant &newValue);
void boolValueChanged(bool newValue);
void stringValueChanged(const QString &newValue);
private:
Q_SLOT void uncheckableButtonClicked();
Q_SLOT void checkableButtonClicked(bool);
Q_SLOT void lineEditEditingFinished();