debuggermainwindow.cpp 23.6 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
** 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
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30
31

#include "debuggermainwindow.h"
hjk's avatar
hjk committed
32
#include "debuggercore.h"
33
#include "debuggerrunconfigurationaspect.h"
34

35
#include <utils/algorithm.h>
36
#include <utils/appmainwindow.h>
37
38
39
40
41
#include <utils/styledbar.h>
#include <utils/qtcassert.h>

#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
42
#include <coreplugin/actionmanager/command.h>
43
44
45
46
47
48
49
50
51
#include <coreplugin/imode.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/icore.h>
#include <coreplugin/navigationwidget.h>
#include <coreplugin/outputpane.h>
#include <coreplugin/rightpane.h>

hjk's avatar
hjk committed
52
53
#include <projectexplorer/project.h>
#include <projectexplorer/runconfiguration.h>
54
55
56
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>

57
#include <QDebug>
58

59
#include <QAction>
60
#include <QDockWidget>
61
#include <QMenu>
hjk's avatar
hjk committed
62
#include <QToolButton>
63
#include <QVBoxLayout>
64
65

using namespace Core;
66
using namespace ProjectExplorer;
67
using namespace Debugger::Constants;
68
69
70
71
72
73
74

namespace Debugger {
namespace Internal {

class DockWidgetEventFilter : public QObject
{
public:
hjk's avatar
hjk committed
75
76
    DockWidgetEventFilter(DebuggerMainWindowPrivate *mw) : m_mw(mw) {}
private:
77
    virtual bool eventFilter(QObject *obj, QEvent *event);
hjk's avatar
hjk committed
78
    DebuggerMainWindowPrivate *m_mw;
79
80
};

81
class DebuggerMainWindowPrivate : public QObject
82
83
84
85
{
public:
    explicit DebuggerMainWindowPrivate(DebuggerMainWindow *mainWindow);

86
87
88
89
90
    void activateQmlCppLayout();
    void activateCppLayout();
    void createViewsMenuItems();
    bool isQmlCppActive() const;
    bool isQmlActive() const;
91
    void setSimpleDockWidgetArrangement();
hjk's avatar
hjk committed
92
    // Debuggable languages are registered with this function.
93
    void addLanguage(DebuggerLanguage language, const Context &context);
hjk's avatar
hjk committed
94

hjk's avatar
hjk committed
95
96
    QDockWidget *dockWidget(const QString &objectName) const
        { return q->findChild<QDockWidget *>(objectName); }
97
98

    void resetDebuggerLayout();
99
100
101
    void updateUiForProject(Project *project);
    void updateUiForTarget(Target *target);
    void updateUiForRunConfiguration(RunConfiguration *rc);
102
    void updateUiForCurrentRunConfiguration();
hjk's avatar
hjk committed
103
104
    void updateActiveLanguages();
    void updateDockWidgetSettings();
105

106
107
108
109
110
public:
    DebuggerMainWindow *q;

    QHash<QString, QVariant> m_dockWidgetActiveStateCpp;
    QHash<QString, QVariant> m_dockWidgetActiveStateQmlCpp;
hjk's avatar
hjk committed
111
    DockWidgetEventFilter m_resizeEventFilter;
112
113
114
115
116

    QMap<DebuggerLanguage, QWidget *> m_toolBars;

    DebuggerLanguages m_supportedLanguages;

117
    QWidget *m_debugToolBar;
hjk's avatar
hjk committed
118
    QToolButton *m_viewButton;
119
    QHBoxLayout *m_debugToolBarLayout;
120
121
122
123
124
125
126
127

    QHash<DebuggerLanguage, Context> m_contextsForLanguage;

    bool m_inDebugMode;
    bool m_changingUI;

    DebuggerLanguages m_previousDebugLanguages;
    DebuggerLanguages m_activeDebugLanguages;
128
    DebuggerLanguages m_engineDebugLanguages;
129
130
131

    ActionContainer *m_viewsMenu;

132
133
134
    Project *m_previousProject;
    Target *m_previousTarget;
    RunConfiguration *m_previousRunConfiguration;
135
136
137
138
};

DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *mw)
    : q(mw)
hjk's avatar
hjk committed
139
    , m_resizeEventFilter(this)
140
    , m_supportedLanguages(AnyLanguage)
141
142
    , m_debugToolBar(new QWidget)
    , m_debugToolBarLayout(new QHBoxLayout(m_debugToolBar))
143
144
145
146
    , m_inDebugMode(false)
    , m_changingUI(false)
    , m_previousDebugLanguages(AnyLanguage)
    , m_activeDebugLanguages(AnyLanguage)
147
    , m_engineDebugLanguages(AnyLanguage)
148
    , m_viewsMenu(0)
149
150
151
    , m_previousProject(0)
    , m_previousTarget(0)
    , m_previousRunConfiguration(0)
hjk's avatar
hjk committed
152
{
153
154
    m_debugToolBarLayout->setMargin(0);
    m_debugToolBarLayout->setSpacing(0);
hjk's avatar
hjk committed
155
    createViewsMenuItems();
156
    addLanguage(AnyLanguage, Context());
hjk's avatar
hjk committed
157
158
159
    addLanguage(CppLanguage, Context(C_CPPDEBUGGER));
    addLanguage(QmlLanguage, Context(C_QMLDEBUGGER));
}
160

161
void DebuggerMainWindowPrivate::updateUiForProject(Project *project)
162
{
163
    if (m_previousProject) {
164
165
        disconnect(m_previousProject, &Project::activeTargetChanged,
            this, &DebuggerMainWindowPrivate::updateUiForTarget);
166
    }
167
    m_previousProject = project;
168
169
170
171
    if (!project) {
        updateUiForTarget(0);
        return;
    }
172
173
    connect(project, &Project::activeTargetChanged,
            this, &DebuggerMainWindowPrivate::updateUiForTarget);
174
175
176
    updateUiForTarget(project->activeTarget());
}

177
void DebuggerMainWindowPrivate::updateUiForTarget(Target *target)
178
{
179
    if (m_previousTarget) {
180
181
         disconnect(m_previousTarget, &Target::activeRunConfigurationChanged,
                    this, &DebuggerMainWindowPrivate::updateUiForRunConfiguration);
182
    }
183

184
    m_previousTarget = target;
185
186
187
188
189
190

    if (!target) {
        updateUiForRunConfiguration(0);
        return;
    }

191
192
    connect(target, &Target::activeRunConfigurationChanged,
            this, &DebuggerMainWindowPrivate::updateUiForRunConfiguration);
193
194
195
196
    updateUiForRunConfiguration(target->activeRunConfiguration());
}

// updates default debug language settings per run config.
197
void DebuggerMainWindowPrivate::updateUiForRunConfiguration(RunConfiguration *rc)
198
{
199
    if (m_previousRunConfiguration)
200
201
        disconnect(m_previousRunConfiguration, &RunConfiguration::requestRunActionsUpdate,
                   this, &DebuggerMainWindowPrivate::updateUiForCurrentRunConfiguration);
202
    m_previousRunConfiguration = rc;
203
204
205
    updateUiForCurrentRunConfiguration();
    if (!rc)
        return;
206
207
208

    connect(m_previousRunConfiguration, &RunConfiguration::requestRunActionsUpdate,
            this, &DebuggerMainWindowPrivate::updateUiForCurrentRunConfiguration);
209
}
210

211
212
void DebuggerMainWindowPrivate::updateUiForCurrentRunConfiguration()
{
hjk's avatar
hjk committed
213
214
215
216
217
218
219
    updateActiveLanguages();
}

void DebuggerMainWindowPrivate::updateActiveLanguages()
{
    DebuggerLanguages newLanguages = AnyLanguage;

220
    if (m_engineDebugLanguages != AnyLanguage) {
221
        newLanguages = m_engineDebugLanguages;
222
223
224
225
226
    } else if (m_previousRunConfiguration) {
        if (m_previousRunConfiguration->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useCppDebugger())
            newLanguages |= CppLanguage;
        if (m_previousRunConfiguration->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useQmlDebugger())
            newLanguages |= QmlLanguage;
hjk's avatar
hjk committed
227
228
    }

229
    if (newLanguages != m_activeDebugLanguages)
hjk's avatar
hjk committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
        m_activeDebugLanguages = newLanguages;

    if (m_changingUI || !m_inDebugMode)
        return;

    m_changingUI = true;

    if (isQmlActive())
        activateQmlCppLayout();
    else
        activateCppLayout();

    m_previousDebugLanguages = m_activeDebugLanguages;

    m_changingUI = false;
245
246
}

247
248
249
250
251
} // namespace Internal

using namespace Internal;

DebuggerMainWindow::DebuggerMainWindow()
252
{
253
    d = new DebuggerMainWindowPrivate(this);
254
255
256
257
258
}

DebuggerMainWindow::~DebuggerMainWindow()
{
    delete d;
259
260
261
262
263
264
265
}

DebuggerLanguages DebuggerMainWindow::activeDebugLanguages() const
{
    return d->m_activeDebugLanguages;
}

266
267
268
269
270
271
272
273
274
void DebuggerMainWindow::setEngineDebugLanguages(DebuggerLanguages languages)
{
    if (d->m_engineDebugLanguages == languages)
        return;

    d->m_engineDebugLanguages = languages;
    d->updateActiveLanguages();
}

275
276
void DebuggerMainWindow::onModeChanged(IMode *mode)
{
277
    d->m_inDebugMode = (mode && mode->id() == Constants::MODE_DEBUG);
278
279
280
    setDockActionsVisible(d->m_inDebugMode);

    // Hide all the debugger windows if mode is different.
281
    if (d->m_inDebugMode) {
hjk's avatar
hjk committed
282
283
284
285
        readSettings();
        d->updateActiveLanguages();
    } else {
        // Hide dock widgets manually in case they are floating.
286
        foreach (QDockWidget *dockWidget, dockWidgets()) {
hjk's avatar
hjk committed
287
288
289
            if (dockWidget->isFloating())
                dockWidget->hide();
        }
290
291
292
    }
}

293
void DebuggerMainWindowPrivate::createViewsMenuItems()
294
{
Friedemann Kleint's avatar
Friedemann Kleint committed
295
    Context debugcontext(Constants::C_DEBUGMODE);
296
    m_viewsMenu = ActionManager::actionContainer(Id(Core::Constants::M_WINDOW_VIEWS));
297
    QTC_ASSERT(m_viewsMenu, return);
298

hjk's avatar
hjk committed
299
300
    auto openMemoryEditorAction = new QAction(this);
    openMemoryEditorAction->setText(DebuggerMainWindow::tr("Memory..."));
hjk's avatar
hjk committed
301
    connect(openMemoryEditorAction, &QAction::triggered,
hjk's avatar
hjk committed
302
            this, &Internal::openMemoryEditor);
303
304
305

    // Add menu items
    Command *cmd = 0;
306
    cmd = ActionManager::registerAction(openMemoryEditorAction,
307
        "Debugger.Views.OpenMemoryEditor", debugcontext);
308
    cmd->setAttribute(Command::CA_Hide);
309
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
310
    cmd = ActionManager::registerAction(q->menuSeparator1(),
311
312
313
        "Debugger.Views.Separator1", debugcontext);
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
314
    cmd = ActionManager::registerAction(q->menuSeparator2(),
315
        "Debugger.Views.Separator2", debugcontext);
316
317
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
318
319
}

320
321
void DebuggerMainWindowPrivate::addLanguage(DebuggerLanguage languageId,
                                            const Context &context)
322
{
hjk's avatar
hjk committed
323
324
325
    m_supportedLanguages = m_supportedLanguages | languageId;
    m_toolBars.insert(languageId, 0);
    m_contextsForLanguage.insert(languageId, context);
326
327
}

328
void DebuggerMainWindowPrivate::activateQmlCppLayout()
329
{
330
331
    Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
    qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
332
333
    if (m_toolBars.value(QmlLanguage)) {
        m_debugToolBarLayout->insertWidget(1, m_toolBars.value(QmlLanguage));
334
        m_toolBars.value(QmlLanguage)->show();
335
    }
336

337
338
    if (m_previousDebugLanguages & QmlLanguage) {
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
339
        ICore::removeAdditionalContext(qmlCppContext);
340
341
    } else if (m_previousDebugLanguages & CppLanguage) {
        m_dockWidgetActiveStateCpp = q->saveSettings();
342
        ICore::removeAdditionalContext(m_contextsForLanguage.value(CppLanguage));
343
344
    }

345
    q->restoreSettings(m_dockWidgetActiveStateQmlCpp);
346
    ICore::addAdditionalContext(qmlCppContext);
347
348
}

349
void DebuggerMainWindowPrivate::activateCppLayout()
350
{
351
352
    Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
    qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
353
354
355
356
    if (m_toolBars.value(QmlLanguage)) {
        m_toolBars.value(QmlLanguage)->hide();
        m_debugToolBarLayout->removeWidget(m_toolBars.value(QmlLanguage));
    }
357

358
359
    if (m_previousDebugLanguages & QmlLanguage) {
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
360
        ICore::removeAdditionalContext(qmlCppContext);
361
362
    } else if (m_previousDebugLanguages & CppLanguage) {
        m_dockWidgetActiveStateCpp = q->saveSettings();
363
        ICore::removeAdditionalContext(m_contextsForLanguage.value(CppLanguage));
364
365
    }

366
    q->restoreSettings(m_dockWidgetActiveStateCpp);
367

368
    const Context &cppContext = m_contextsForLanguage.value(CppLanguage);
369
    ICore::addAdditionalContext(cppContext);
370
371
}

372
void DebuggerMainWindow::setToolBar(DebuggerLanguage language, QWidget *widget)
373
374
375
{
    Q_ASSERT(d->m_toolBars.contains(language));
    d->m_toolBars[language] = widget;
376
377
378
379
380
381
    if (language == CppLanguage)
        d->m_debugToolBarLayout->addWidget(widget);

    //Add widget at the end
    if (language == AnyLanguage)
        d->m_debugToolBarLayout->insertWidget(-1, widget, 10);
382
383
384
385
386
387
}

/*!
    Keep track of dock widgets so they can be shown/hidden for different languages
*/
QDockWidget *DebuggerMainWindow::createDockWidget(const DebuggerLanguage &language,
hjk's avatar
hjk committed
388
    QWidget *widget)
389
390
{
    QDockWidget *dockWidget = addDockForWidget(widget);
hjk's avatar
hjk committed
391
    dockWidget->setObjectName(widget->objectName());
392
    addDockWidget(Qt::BottomDockWidgetArea, dockWidget);
393
394
395
396
397

    if (!(d->m_activeDebugLanguages & language))
        dockWidget->hide();

    QAction *toggleViewAction = dockWidget->toggleViewAction();
398
    Command *cmd = ActionManager::registerAction(toggleViewAction,
399
             Id("Debugger.").withSuffix(widget->objectName()));
400
401
    cmd->setAttribute(Command::CA_Hide);

hjk's avatar
hjk committed
402
    dockWidget->installEventFilter(&d->m_resizeEventFilter);
403

hjk's avatar
hjk committed
404
405
406
407
408
409
    connect(dockWidget->toggleViewAction(), &QAction::triggered,
            d, &DebuggerMainWindowPrivate::updateDockWidgetSettings);
    connect(dockWidget, &QDockWidget::topLevelChanged,
            d, &DebuggerMainWindowPrivate::updateDockWidgetSettings);
    connect(dockWidget, &QDockWidget::dockLocationChanged,
            d, &DebuggerMainWindowPrivate::updateDockWidgetSettings);
410
411
412
413

    return dockWidget;
}

414
415
void DebuggerMainWindow::addStagedMenuEntries()
{
416
    addDockActionsToMenu(d->m_viewsMenu->menu());
417
418
}

419
420
QWidget *DebuggerMainWindow::createContents(IMode *mode)
{
421
422
    connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
        d, &DebuggerMainWindowPrivate::updateUiForProject);
423

424
    d->m_viewsMenu = ActionManager::actionContainer(Id(Core::Constants::M_WINDOW_VIEWS));
425
    QTC_ASSERT(d->m_viewsMenu, return 0);
426
427
428
429

    //d->m_mainWindow = new Internal::DebuggerMainWindow(this);
    setDocumentMode(true);
    setDockNestingEnabled(true);
hjk's avatar
hjk committed
430
431
432
433
    connect(this, &FancyMainWindow::resetLayout,
            d, &DebuggerMainWindowPrivate::resetDebuggerLayout);
    connect(autoHideTitleBarsAction(), &QAction::triggered,
            d, &DebuggerMainWindowPrivate::updateDockWidgetSettings);
434

hjk's avatar
hjk committed
435
    auto editorHolderLayout = new QVBoxLayout;
436
437
438
    editorHolderLayout->setMargin(0);
    editorHolderLayout->setSpacing(0);

hjk's avatar
hjk committed
439
    auto editorAndFindWidget = new QWidget;
440
    editorAndFindWidget->setLayout(editorHolderLayout);
441
442
    auto editorManagerPlaceHolder = new EditorManagerPlaceHolder(mode);
    editorHolderLayout->addWidget(editorManagerPlaceHolder);
443
444
    editorHolderLayout->addWidget(new FindToolBarPlaceHolder(editorAndFindWidget));

hjk's avatar
hjk committed
445
    auto documentAndRightPane = new MiniSplitter;
446
447
448
449
450
    documentAndRightPane->addWidget(editorAndFindWidget);
    documentAndRightPane->addWidget(new RightPanePlaceHolder(mode));
    documentAndRightPane->setStretchFactor(0, 1);
    documentAndRightPane->setStretchFactor(1, 0);

hjk's avatar
hjk committed
451
452
453
454
455
456
    d->m_viewButton = new QToolButton();
    // FIXME: Use real thing after string freeze.
    QString hackyName = QCoreApplication::translate("Core::Internal::MainWindow", "&Views");
    hackyName.replace(QLatin1Char('&'), QString());
    d->m_viewButton->setText(hackyName);

hjk's avatar
hjk committed
457
    auto debugToolBar = new Utils::StyledBar;
458
    debugToolBar->setProperty("topBorder", true);
hjk's avatar
hjk committed
459
    auto debugToolBarLayout = new QHBoxLayout(debugToolBar);
460
461
    debugToolBarLayout->setMargin(0);
    debugToolBarLayout->setSpacing(0);
462
    debugToolBarLayout->addWidget(d->m_debugToolBar);
463
    debugToolBarLayout->addWidget(new Utils::StyledSeparator);
hjk's avatar
hjk committed
464
465
    debugToolBarLayout->addWidget(d->m_viewButton);

hjk's avatar
hjk committed
466
467
468
469
470
    connect(d->m_viewButton, &QAbstractButton::clicked, [this] {
        QMenu menu;
        addDockActionsToMenu(&menu);
        menu.exec(d->m_viewButton->mapToGlobal(QPoint()));
    });
471

hjk's avatar
hjk committed
472
    auto dock = new QDockWidget(DebuggerMainWindow::tr("Debugger Toolbar"));
473
474
475
476
477
    dock->setObjectName(QLatin1String("Debugger Toolbar"));
    dock->setWidget(debugToolBar);
    dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
    dock->setAllowedAreas(Qt::BottomDockWidgetArea);
    dock->setTitleBarWidget(new QWidget(dock));
478
    dock->setProperty("managed_dockwidget", QLatin1String("true"));
479
480
481
    addDockWidget(Qt::BottomDockWidgetArea, dock);
    setToolBarDockWidget(dock);

hjk's avatar
hjk committed
482
    auto centralWidget = new QWidget;
483
484
    setCentralWidget(centralWidget);

hjk's avatar
hjk committed
485
    auto centralLayout = new QVBoxLayout(centralWidget);
486
487
488
489
490
491
492
493
    centralWidget->setLayout(centralLayout);
    centralLayout->setMargin(0);
    centralLayout->setSpacing(0);
    centralLayout->addWidget(documentAndRightPane);
    centralLayout->setStretch(0, 1);
    centralLayout->setStretch(1, 0);

    // Right-side window with editor, output etc.
hjk's avatar
hjk committed
494
    auto mainWindowSplitter = new MiniSplitter;
495
    mainWindowSplitter->addWidget(this);
hjk's avatar
hjk committed
496
    auto outputPane = new OutputPanePlaceHolder(mode, mainWindowSplitter);
497
498
    outputPane->setObjectName(QLatin1String("DebuggerOutputPanePlaceHolder"));
    mainWindowSplitter->addWidget(outputPane);
499
500
501
502
503
    mainWindowSplitter->setStretchFactor(0, 10);
    mainWindowSplitter->setStretchFactor(1, 0);
    mainWindowSplitter->setOrientation(Qt::Vertical);

    // Navigation and right-side window.
hjk's avatar
hjk committed
504
    auto splitter = new MiniSplitter;
505
    splitter->setFocusProxy(editorManagerPlaceHolder);
506
507
508
509
    splitter->addWidget(new NavigationWidgetPlaceHolder(mode));
    splitter->addWidget(mainWindowSplitter);
    splitter->setStretchFactor(0, 0);
    splitter->setStretchFactor(1, 1);
510
    splitter->setObjectName(QLatin1String("DebugModeWidget"));
511
512
513
514
515
    return splitter;
}

void DebuggerMainWindow::writeSettings() const
{
hjk's avatar
hjk committed
516
    QSettings *settings = ICore::settings();
hjk's avatar
hjk committed
517
    settings->beginGroup(QLatin1String("DebugMode.CppMode"));
518
519
520
    QHashIterator<QString, QVariant> it(d->m_dockWidgetActiveStateCpp);
    while (it.hasNext()) {
        it.next();
hjk's avatar
hjk committed
521
        settings->setValue(it.key(), it.value());
522
    }
hjk's avatar
hjk committed
523
    settings->endGroup();
524

hjk's avatar
hjk committed
525
    settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
526
527
528
    it = QHashIterator<QString, QVariant>(d->m_dockWidgetActiveStateQmlCpp);
    while (it.hasNext()) {
        it.next();
hjk's avatar
hjk committed
529
        settings->setValue(it.key(), it.value());
530
    }
hjk's avatar
hjk committed
531
    settings->endGroup();
532
533
534
535
}

void DebuggerMainWindow::readSettings()
{
hjk's avatar
hjk committed
536
    QSettings *settings = ICore::settings();
537
538
539
    d->m_dockWidgetActiveStateCpp.clear();
    d->m_dockWidgetActiveStateQmlCpp.clear();

hjk's avatar
hjk committed
540
541
542
543
    settings->beginGroup(QLatin1String("DebugMode.CppMode"));
    foreach (const QString &key, settings->childKeys())
        d->m_dockWidgetActiveStateCpp.insert(key, settings->value(key));
    settings->endGroup();
544

hjk's avatar
hjk committed
545
546
547
548
    settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
    foreach (const QString &key, settings->childKeys())
        d->m_dockWidgetActiveStateQmlCpp.insert(key, settings->value(key));
    settings->endGroup();
549

550
    // Reset initial settings when there are none yet.
551
552
553
554
555
556
557
558
559
    if (d->m_dockWidgetActiveStateQmlCpp.isEmpty()) {
        d->m_activeDebugLanguages = DebuggerLanguage(QmlLanguage|CppLanguage);
        d->setSimpleDockWidgetArrangement();
        d->m_dockWidgetActiveStateCpp = saveSettings();
    }
    if (d->m_dockWidgetActiveStateCpp.isEmpty()) {
        d->m_activeDebugLanguages = CppLanguage;
        d->setSimpleDockWidgetArrangement();
        d->m_dockWidgetActiveStateCpp = saveSettings();
560
    }
561
    writeSettings();
562
563
}

564
void DebuggerMainWindowPrivate::resetDebuggerLayout()
565
{
566
    m_activeDebugLanguages = DebuggerLanguage(QmlLanguage | CppLanguage);
567
    setSimpleDockWidgetArrangement();
568
    m_dockWidgetActiveStateQmlCpp = q->saveSettings();
569

570
571
572
573
    m_activeDebugLanguages = CppLanguage;
    m_previousDebugLanguages = CppLanguage;
    setSimpleDockWidgetArrangement();
    // will save state in m_dockWidgetActiveStateCpp
hjk's avatar
hjk committed
574
    updateActiveLanguages();
575
576
}

hjk's avatar
hjk committed
577
void DebuggerMainWindowPrivate::updateDockWidgetSettings()
578
{
hjk's avatar
hjk committed
579
    if (!m_inDebugMode || m_changingUI)
580
581
        return;

hjk's avatar
hjk committed
582
583
    if (isQmlActive())
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
584
    else
hjk's avatar
hjk committed
585
        m_dockWidgetActiveStateCpp = q->saveSettings();
586
587
}

588
bool DebuggerMainWindowPrivate::isQmlCppActive() const
589
{
590
591
    return (m_activeDebugLanguages & CppLanguage)
        && (m_activeDebugLanguages & QmlLanguage);
592
593
}

594
bool DebuggerMainWindowPrivate::isQmlActive() const
595
{
596
    return (m_activeDebugLanguages & QmlLanguage);
597
598
}

599
void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
600
{
hjk's avatar
hjk committed
601
    using namespace Constants;
602
603
604
    QTC_ASSERT(q, return);
    q->setTrackingEnabled(false);

605
606
    QList<QDockWidget *> dockWidgets = q->dockWidgets();
    foreach (QDockWidget *dockWidget, dockWidgets) {
607
608
609
610
        dockWidget->setFloating(false);
        q->removeDockWidget(dockWidget);
    }

611
    foreach (QDockWidget *dockWidget, dockWidgets) {
612
613
614
615
616
617
618
619
        int area = Qt::BottomDockWidgetArea;
        QVariant p = dockWidget->property(DOCKWIDGET_DEFAULT_AREA);
        if (p.isValid())
            area = Qt::DockWidgetArea(p.toInt());
        q->addDockWidget(Qt::DockWidgetArea(area), dockWidget);
        dockWidget->hide();
    }

620
    QDockWidget *toolBarDock = q->toolBarDockWidget();
hjk's avatar
hjk committed
621
622
623
624
625
626
627
628
629
630
    QDockWidget *breakDock = dockWidget(QLatin1String(DOCKWIDGET_BREAK));
    QDockWidget *stackDock = dockWidget(QLatin1String(DOCKWIDGET_STACK));
    QDockWidget *watchDock = dockWidget(QLatin1String(DOCKWIDGET_WATCHERS));
    QDockWidget *snapshotsDock = dockWidget(QLatin1String(DOCKWIDGET_SNAPSHOTS));
    QDockWidget *threadsDock = dockWidget(QLatin1String(DOCKWIDGET_THREADS));
    QDockWidget *outputDock = dockWidget(QLatin1String(DOCKWIDGET_OUTPUT));
    QDockWidget *qmlInspectorDock = dockWidget(QLatin1String(DOCKWIDGET_QML_INSPECTOR));
    QDockWidget *modulesDock = dockWidget(QLatin1String(DOCKWIDGET_MODULES));
    QDockWidget *registerDock = dockWidget(QLatin1String(DOCKWIDGET_REGISTER));
    QDockWidget *sourceFilesDock = dockWidget(QLatin1String(DOCKWIDGET_SOURCE_FILES));
hjk's avatar
hjk committed
631
632
633
634
635
636
637
638
639
640

    QTC_ASSERT(breakDock, return);
    QTC_ASSERT(stackDock, return);
    QTC_ASSERT(watchDock, return);
    QTC_ASSERT(snapshotsDock, return);
    QTC_ASSERT(threadsDock, return);
    QTC_ASSERT(outputDock, return);
    QTC_ASSERT(modulesDock, return);
    QTC_ASSERT(registerDock, return);
    QTC_ASSERT(sourceFilesDock, return);
641

642
643
644
645
646
647
648
649
    // make sure main docks are visible so that split equally divides the space
    toolBarDock->show();
    stackDock->show();
    breakDock->show();
    watchDock->show();

    // toolBar
    // --------------------------------------------------------------------------------
650
    // stack,qmlinspector | breakpoints,modules,register,threads,sourceFiles,snapshots
651
652
653
654
655
656
657
658
659
660
661
662
663
664
    //
    q->splitDockWidget(toolBarDock, stackDock, Qt::Vertical);
    q->splitDockWidget(stackDock, breakDock, Qt::Horizontal);

    if (qmlInspectorDock)
        q->tabifyDockWidget(stackDock, qmlInspectorDock);

    q->tabifyDockWidget(breakDock, modulesDock);
    q->tabifyDockWidget(breakDock, registerDock);
    q->tabifyDockWidget(breakDock, threadsDock);
    q->tabifyDockWidget(breakDock, sourceFilesDock);
    q->tabifyDockWidget(breakDock, snapshotsDock);

    if (m_activeDebugLanguages.testFlag(Debugger::QmlLanguage)) {
665
666
        if (qmlInspectorDock)
            qmlInspectorDock->show();
667
    } else {
668
        // CPP only
669
670
        threadsDock->show();
        snapshotsDock->show();
671
672
673
    }

    q->setTrackingEnabled(true);
674
    q->update();
675
676
}

hjk's avatar
hjk committed
677
678
679
680
681
682
683
684
685
686
687
688
689
bool DockWidgetEventFilter::eventFilter(QObject *obj, QEvent *event)
{
    switch (event->type()) {
    case QEvent::Resize:
    case QEvent::ZOrderChange:
        m_mw->updateDockWidgetSettings();
        break;
    default:
        break;
    }
    return QObject::eventFilter(obj, event);
}

690
} // namespace Debugger