debuggeractions.cpp 14.2 KB
Newer Older
hjk's avatar
hjk committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/

#include "debuggeractions.h"

32
33
34
35
#include <utils/qtcassert.h>
#include <utils/pathchooser.h>

#include <QtCore/QSettings>
hjk's avatar
hjk committed
36
#include <QtGui/QAction>
37
38
39
40
#include <QtGui/QAbstractButton>
#include <QtGui/QRadioButton>
#include <QtGui/QCheckBox>
#include <QtGui/QLineEdit>
hjk's avatar
hjk committed
41
42
43
44

namespace Debugger {
namespace Internal {

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//////////////////////////////////////////////////////////////////////////
//
// 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)
{
120
    m_action->setText(value);
121
122
123
124
125
126
127
128
129
130
131
132
}

QString QtcSettingsItem::textPattern() const
{
    return m_textPattern;
}

void QtcSettingsItem::setTextPattern(const QString &value)
{
    m_textPattern = value;
}

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
QAction *QtcSettingsItem::updatedAction(const QString &text0)
{
    QString text = text0;
    bool enabled = true;
    if (!m_textPattern.isEmpty()) {
        if (text.isEmpty()) {
            text = m_textPattern;
            text.remove("\"%1\"");
            text.remove("%1");
            enabled = false;
        } else {
            text = m_textPattern.arg(text0);
        }
    }
    m_action->setEnabled(enabled);
148
    m_action->setData(text0);
149
150
151
152
    m_action->setText(text);
    return m_action;
}

153
154
155
156
157
158
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);
hjk's avatar
hjk committed
159
    //qDebug() << "READING: " << m_settingsKey << " -> " << m_value;
160
161
162
163
164
165
166
167
168
    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);
hjk's avatar
hjk committed
169
    //qDebug() << "WRITING: " << m_settingsKey << " -> " << m_value;
170
171
172
    settings->endGroup();
}
   
173
QAction *QtcSettingsItem::action()
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{
    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;
    }
}

hjk's avatar
hjk committed
209
void QtcSettingsItem::apply(QSettings *s)
210
211
{
    setValue(m_deferedValue);
hjk's avatar
hjk committed
212
213
    if (s)
        writeSettings(s);
214
215
216
217
218
219
}

void QtcSettingsItem::uncheckableButtonClicked()
{
    QAbstractButton *button = qobject_cast<QAbstractButton *>(sender());
    QTC_ASSERT(button, return);
hjk's avatar
hjk committed
220
    //qDebug() << "UNCHECKABLE BUTTON: " << sender();
221
222
223
224
225
226
227
    m_action->trigger();
}

void QtcSettingsItem::checkableButtonClicked(bool)
{
    QAbstractButton *button = qobject_cast<QAbstractButton *>(sender());
    QTC_ASSERT(button, return);
hjk's avatar
hjk committed
228
    //qDebug() << "CHECKABLE BUTTON: " << sender();
229
230
231
232
233
234
235
236
237
238
    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);
hjk's avatar
hjk committed
239
    //qDebug() << "LINEEDIT: " << sender() << lineEdit->text();
240
241
242
243
244
245
246
247
248
249
250
    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);
hjk's avatar
hjk committed
251
    //qDebug() << "PATHCHOOSER: " << sender() << pathChooser->path();
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
    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());
    }
}

hjk's avatar
hjk committed
267
268
269

//////////////////////////////////////////////////////////////////////////
//
hjk's avatar
hjk committed
270
// QtcSettingsPool
hjk's avatar
hjk committed
271
272
273
//
//////////////////////////////////////////////////////////////////////////

274

hjk's avatar
hjk committed
275
QtcSettingsPool::QtcSettingsPool(QObject *parent)
276
277
278
    : QObject(parent)
{}

hjk's avatar
hjk committed
279
QtcSettingsPool::~QtcSettingsPool()
hjk's avatar
hjk committed
280
{
281
282
283
    qDeleteAll(m_items);
}
    
hjk's avatar
hjk committed
284
void QtcSettingsPool::insertItem(int code, QtcSettingsItem *item)
hjk's avatar
hjk committed
285
{
286
287
288
    m_items[code] = item;
}

hjk's avatar
hjk committed
289
void QtcSettingsPool::readSettings(QSettings *settings)
290
291
292
293
294
{
    foreach (QtcSettingsItem *item, m_items)
        item->readSettings(settings);
}

hjk's avatar
hjk committed
295
void QtcSettingsPool::writeSettings(QSettings *settings)
296
297
298
299
300
{
    foreach (QtcSettingsItem *item, m_items)
        item->writeSettings(settings);
}
   
hjk's avatar
hjk committed
301
QtcSettingsItem *QtcSettingsPool::item(int code)
302
303
304
305
306
{
    QTC_ASSERT(m_items.value(code, 0), return 0);
    return m_items.value(code, 0);
}

hjk's avatar
hjk committed
307
QString QtcSettingsPool::dump()
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
{
    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


hjk's avatar
hjk committed
348
QtcSettingsPool *theDebuggerSettings()
349
{
hjk's avatar
hjk committed
350
    static QtcSettingsPool *instance = 0;
351
352
353
    if (instance)
        return instance;

hjk's avatar
hjk committed
354
    instance = new QtcSettingsPool;
355
356
357

    QtcSettingsItem *item = 0;

hjk's avatar
hjk committed
358
359
    item = new QtcSettingsItem(instance);
    instance->insertItem(AdjustColumnWidths, item);
360
361
    item->setText(QObject::tr("Adjust column widths to contents"));

hjk's avatar
hjk committed
362
363
    item = new QtcSettingsItem(instance);
    instance->insertItem(AlwaysAdjustColumnWidths, item);
364
365
366
    item->setText(QObject::tr("Always adjust column widths to contents"));
    item->action()->setCheckable(true);

hjk's avatar
hjk committed
367
368
    item = new QtcSettingsItem(instance);
    instance->insertItem(WatchExpression, item);
369
370
    item->setTextPattern(QObject::tr("Watch expression \"%1\""));

hjk's avatar
hjk committed
371
372
    item = new QtcSettingsItem(instance);
    instance->insertItem(RemoveWatchExpression, item);
373
374
    item->setTextPattern(QObject::tr("Remove watch expression \"%1\""));

375
376
377
378
379
380
381
    item = new QtcSettingsItem(instance);
    instance->insertItem(WatchExpressionInWindow, item);
    item->setTextPattern(QObject::tr("Watch expression \"%1\" in separate window"));

    //
    // Dumpers
    //
hjk's avatar
hjk committed
382
383
    item = new QtcSettingsItem(instance);
    instance->insertItem(SettingsDialog, item);
384
385
    item->setText(QObject::tr("Debugger properties..."));

hjk's avatar
hjk committed
386
387
    item = new QtcSettingsItem(instance);
    instance->insertItem(DebugDumpers, item);
388
389
390
    item->setText(QObject::tr("Debug custom dumpers"));
    item->action()->setCheckable(true);

hjk's avatar
hjk committed
391
392
    item = new QtcSettingsItem(instance);
    instance->insertItem(RecheckDumpers, item);
393
    item->setText(QObject::tr("Recheck custom dumper availability"));
hjk's avatar
hjk committed
394
395

    //
396
    // Breakpoints
hjk's avatar
hjk committed
397
    //
hjk's avatar
hjk committed
398
399
    item = new QtcSettingsItem(instance);
    instance->insertItem(SynchronizeBreakpoints, item);
400
    item->setText(QObject::tr("Syncronize breakpoints"));
hjk's avatar
hjk committed
401
402

    //
hjk's avatar
hjk committed
403
404
    item = new QtcSettingsItem(instance);
    instance->insertItem(AutoQuit, item);
405
406
407
    item->setText(QObject::tr("Automatically quit debugger"));
    item->action()->setCheckable(true);

hjk's avatar
hjk committed
408
409
    item = new QtcSettingsItem(instance);
    instance->insertItem(SkipKnownFrames, item);
410
411
412
    item->setText(QObject::tr("Skip known frames"));
    item->action()->setCheckable(true);

hjk's avatar
hjk committed
413
414
    item = new QtcSettingsItem(instance);
    instance->insertItem(UseToolTips, item);
415
416
417
    item->setText(QObject::tr("Use tooltips when debugging"));
    item->action()->setCheckable(true);

hjk's avatar
hjk committed
418
419
    item = new QtcSettingsItem(instance);
    instance->insertItem(ListSourceFiles, item);
420
421
422
423
424
425
    item->setText(QObject::tr("List source files"));
    item->action()->setCheckable(true);


    //
    // Settings
hjk's avatar
hjk committed
426
    //
hjk's avatar
hjk committed
427
428
    item = new QtcSettingsItem(instance);
    instance->insertItem(GdbLocation, item);
429
    item->setSettingsKey("DebugMode", "Location");
hjk's avatar
hjk committed
430

hjk's avatar
hjk committed
431
432
    item = new QtcSettingsItem(instance);
    instance->insertItem(GdbEnvironment, item);
433
    item->setSettingsKey("DebugMode", "Environment");
hjk's avatar
hjk committed
434

hjk's avatar
hjk committed
435
436
    item = new QtcSettingsItem(instance);
    instance->insertItem(GdbScriptFile, item);
437
438
    item->setSettingsKey("DebugMode", "ScriptFile");

hjk's avatar
hjk committed
439
440
    item = new QtcSettingsItem(instance);
    instance->insertItem(GdbAutoQuit, item);
441
442
    item->setSettingsKey("DebugMode", "AutoQuit");

hjk's avatar
hjk committed
443
444
    item = new QtcSettingsItem(instance);
    instance->insertItem(GdbAutoRun, item);
445
446
    item->setSettingsKey("DebugMode", "AutoRun");

hjk's avatar
hjk committed
447
448
    item = new QtcSettingsItem(instance);
    instance->insertItem(UseToolTips, item);
449
450
    item->setSettingsKey("DebugMode", "UseToolTips");

hjk's avatar
hjk committed
451
452
    item = new QtcSettingsItem(instance);
    instance->insertItem(UseDumpers, item);
453
454
455
456
457
    item->setSettingsKey("DebugMode", "UseCustomDumpers");
    item->setText(QObject::tr("Use custom dumpers"));
    item->action()->setCheckable(true);


hjk's avatar
hjk committed
458
459
    item = new QtcSettingsItem(instance);
    instance->insertItem(ListSourceFiles, item);
460
461
    item->setSettingsKey("DebugMode", "ListSourceFiles");

hjk's avatar
hjk committed
462
463
    item = new QtcSettingsItem(instance);
    instance->insertItem(SkipKnownFrames, item);
464
465
    item->setSettingsKey("DebugMode", "SkipKnownFrames");

hjk's avatar
hjk committed
466
467
    item = new QtcSettingsItem(instance);
    instance->insertItem(DebugDumpers, item);
468
469
    item->setSettingsKey("DebugMode", "DebugDumpers");

hjk's avatar
hjk committed
470
471
    item = new QtcSettingsItem(instance);
    instance->insertItem(AllPluginBreakpoints, item);
472
473
    item->setSettingsKey("DebugMode", "AllPluginBreakpoints");

hjk's avatar
hjk committed
474
475
    item = new QtcSettingsItem(instance);
    instance->insertItem(SelectedPluginBreakpoints, item);
476
477
    item->setSettingsKey("DebugMode", "SelectedPluginBreakpoints");

hjk's avatar
hjk committed
478
479
    item = new QtcSettingsItem(instance);
    instance->insertItem(NoPluginBreakpoints, item);
480
481
    item->setSettingsKey("DebugMode", "NoPluginBreakpoints");

hjk's avatar
hjk committed
482
483
    item = new QtcSettingsItem(instance);
    instance->insertItem(SelectedPluginBreakpointsPattern, item);
484
    item->setSettingsKey("DebugMode", "SelectedPluginBreakpointsPattern");
hjk's avatar
hjk committed
485

486
    return instance;
hjk's avatar
hjk committed
487
488
}

hjk's avatar
hjk committed
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
QtcSettingsItem *theDebuggerSetting(int code)
{
    return theDebuggerSettings()->item(code);
}

bool theDebuggerBoolSetting(int code)
{
    return theDebuggerSettings()->item(code)->value().toBool();
}

QString theDebuggerStringSetting(int code)
{
    return theDebuggerSettings()->item(code)->value().toString();
}

hjk's avatar
hjk committed
504
505
506
} // namespace Internal
} // namespace Debugger