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
32
33
34
35
36
37
38
39
40
41
42
43
44
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "debuggermainwindow.h"
#include "debuggercore.h"
#include "debuggerengine.h"
#include <utils/appmainwindow.h>
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
#include <utils/fancymainwindow.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/id.h>
#include <coreplugin/imode.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/icore.h>
#include <coreplugin/minisplitter.h>
#include <coreplugin/navigationwidget.h>
#include <coreplugin/outputpane.h>
#include <coreplugin/rightpane.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <QDebug>
#include <QList>
#include <QMap>
#include <QPair>
#include <QSettings>
#include <QDockWidget>
#include <QMenu>
#include <QResizeEvent>
#include <QStackedWidget>
#include <QVBoxLayout>
using namespace Core;
using namespace ProjectExplorer;
using namespace Debugger::Constants;
namespace Debugger {
namespace Internal {
class DockWidgetEventFilter : public QObject
{
public:
DockWidgetEventFilter(DebuggerMainWindowPrivate *mw) : m_mw(mw) {}
private:
virtual bool eventFilter(QObject *obj, QEvent *event);
DebuggerMainWindowPrivate *m_mw;
};
class DebuggerMainWindowPrivate : public QObject
{
Q_OBJECT
public:
explicit DebuggerMainWindowPrivate(DebuggerMainWindow *mainWindow);
void activateQmlCppLayout();
void activateCppLayout();
void createViewsMenuItems();
bool isQmlCppActive() const;
bool isQmlActive() const;
void setSimpleDockWidgetArrangement();
// Debuggable languages are registered with this function.
void addLanguage(DebuggerLanguage language, const Core::Context &context);
public slots:
void resetDebuggerLayout();
void updateUiForProject(ProjectExplorer::Project *project);
void updateUiForTarget(ProjectExplorer::Target *target);
void updateUiForRunConfiguration(ProjectExplorer::RunConfiguration *rc);
void updateUiForCurrentRunConfiguration();
void updateActiveLanguages();
void updateDockWidgetSettings();
void openMemoryEditor() { debuggerCore()->openMemoryEditor(); }
public:
DebuggerMainWindow *q;
QHash<QString, QVariant> m_dockWidgetActiveStateCpp;
QHash<QString, QVariant> m_dockWidgetActiveStateQmlCpp;
DockWidgetEventFilter m_resizeEventFilter;
QMap<DebuggerLanguage, QWidget *> m_toolBars;
DebuggerLanguages m_supportedLanguages;
QWidget *m_debugToolBar;
QHBoxLayout *m_debugToolBarLayout;
QHash<DebuggerLanguage, Context> m_contextsForLanguage;
bool m_inDebugMode;
bool m_changingUI;
DebuggerLanguages m_previousDebugLanguages;
DebuggerLanguages m_activeDebugLanguages;
DebuggerLanguages m_engineDebugLanguages;
ActionContainer *m_viewsMenu;
QList<Command *> m_menuCommandsToAdd;
Project *m_previousProject;
Target *m_previousTarget;
RunConfiguration *m_previousRunConfiguration;
DebuggerEngine *m_engine;
};
DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *mw)
: q(mw)
, m_resizeEventFilter(this)
, m_supportedLanguages(AnyLanguage)
, m_debugToolBar(new QWidget)
, m_debugToolBarLayout(new QHBoxLayout(m_debugToolBar))
, m_inDebugMode(false)
, m_changingUI(false)
, m_previousDebugLanguages(AnyLanguage)
, m_activeDebugLanguages(AnyLanguage)
, m_engineDebugLanguages(AnyLanguage)
, m_viewsMenu(0)
, m_previousProject(0)
, m_previousTarget(0)
, m_previousRunConfiguration(0)
, m_engine(0)
{
m_debugToolBarLayout->setMargin(0);
m_debugToolBarLayout->setSpacing(0);
createViewsMenuItems();
addLanguage(AnyLanguage, Context());
addLanguage(CppLanguage, Context(C_CPPDEBUGGER));
addLanguage(QmlLanguage, Context(C_QMLDEBUGGER));
}
void DebuggerMainWindowPrivate::updateUiForProject(Project *project)
{
if (m_previousProject) {
disconnect(m_previousProject,
SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
this, SLOT(updateUiForTarget(ProjectExplorer::Target*)));
}
m_previousProject = project;
if (!project) {
updateUiForTarget(0);
return;
}
connect(project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
SLOT(updateUiForTarget(ProjectExplorer::Target*)));
updateUiForTarget(project->activeTarget());
}
void DebuggerMainWindowPrivate::updateUiForTarget(Target *target)
{
if (m_previousTarget) {
disconnect(m_previousTarget,
SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
this, SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
}
m_previousTarget = target;
if (!target) {
updateUiForRunConfiguration(0);
return;
}
connect(target,
SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
updateUiForRunConfiguration(target->activeRunConfiguration());
}
// updates default debug language settings per run config.
void DebuggerMainWindowPrivate::updateUiForRunConfiguration(RunConfiguration *rc)
{
if (m_previousRunConfiguration)
disconnect(m_previousRunConfiguration->debuggerAspect(), SIGNAL(debuggersChanged()),
this, SLOT(updateUiForCurrentRunConfiguration()));
m_previousRunConfiguration = rc;
updateUiForCurrentRunConfiguration();
if (!rc)
return;
connect(m_previousRunConfiguration->debuggerAspect(),
SIGNAL(debuggersChanged()),
SLOT(updateUiForCurrentRunConfiguration()));
}
void DebuggerMainWindowPrivate::updateUiForCurrentRunConfiguration()
{
updateActiveLanguages();
}
void DebuggerMainWindowPrivate::updateActiveLanguages()
{
DebuggerLanguages newLanguages = AnyLanguage;
if (m_engineDebugLanguages != AnyLanguage)
newLanguages = m_engineDebugLanguages;
else {
if (m_previousRunConfiguration) {
if (m_previousRunConfiguration->debuggerAspect()->useCppDebugger())
newLanguages |= CppLanguage;
if (m_previousRunConfiguration->debuggerAspect()->useQmlDebugger())
newLanguages |= QmlLanguage;
}
}
if (newLanguages != m_activeDebugLanguages) {
m_activeDebugLanguages = newLanguages;
debuggerCore()->languagesChanged();
emit q->activeDebugLanguagesChanged(m_activeDebugLanguages);
}
if (m_changingUI || !m_inDebugMode)
return;
m_changingUI = true;
if (isQmlActive())
activateQmlCppLayout();
else
activateCppLayout();
m_previousDebugLanguages = m_activeDebugLanguages;
m_changingUI = false;
}
} // namespace Internal
using namespace Internal;
DebuggerMainWindow::DebuggerMainWindow()
{
d = new DebuggerMainWindowPrivate(this);
}
DebuggerMainWindow::~DebuggerMainWindow()
{
delete d;
}
void DebuggerMainWindow::setCurrentEngine(DebuggerEngine *engine)
{
if (d->m_engine)
disconnect(d->m_engine, SIGNAL(raiseWindow()), this, SLOT(raiseDebuggerWindow()));
d->m_engine = engine;
if (d->m_engine)
connect(d->m_engine, SIGNAL(raiseWindow()), this, SLOT(raiseDebuggerWindow()));
}
DebuggerLanguages DebuggerMainWindow::activeDebugLanguages() const
{
return d->m_activeDebugLanguages;
}
void DebuggerMainWindow::setEngineDebugLanguages(DebuggerLanguages languages)
{
if (d->m_engineDebugLanguages == languages)
return;
d->m_engineDebugLanguages = languages;
d->updateActiveLanguages();
}
void DebuggerMainWindow::onModeChanged(IMode *mode)
{
d->m_inDebugMode = (mode && mode->id() == QLatin1String(Constants::MODE_DEBUG));
setDockActionsVisible(d->m_inDebugMode);
// Hide all the debugger windows if mode is different.
if (d->m_inDebugMode) {
readSettings();
d->updateActiveLanguages();
} else {
// Hide dock widgets manually in case they are floating.
foreach (QDockWidget *dockWidget, dockWidgets()) {
if (dockWidget->isFloating())
dockWidget->hide();
}
}
}
void DebuggerMainWindowPrivate::createViewsMenuItems()
{
ActionManager *am = ICore::actionManager();
Context debugcontext(Constants::C_DEBUGMODE);
m_viewsMenu = am->actionContainer(Id(Core::Constants::M_WINDOW_VIEWS));
QTC_ASSERT(m_viewsMenu, return)
QAction *openMemoryEditorAction = new QAction(this);
openMemoryEditorAction->setText(tr("Memory..."));
connect(openMemoryEditorAction, SIGNAL(triggered()),
SLOT(openMemoryEditor()));
// Add menu items
Command *cmd = 0;
cmd = am->registerAction(openMemoryEditorAction,
Core::Id("Debugger.Views.OpenMemoryEditor"),
debugcontext);
cmd->setAttribute(Command::CA_Hide);
m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
cmd = am->registerAction(q->menuSeparator1(),
Core::Id("Debugger.Views.Separator1"), debugcontext);
cmd->setAttribute(Command::CA_Hide);
m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
cmd = am->registerAction(q->toggleLockedAction(),
Core::Id("Debugger.Views.ToggleLocked"), debugcontext);
cmd->setAttribute(Command::CA_Hide);
m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
cmd = am->registerAction(q->menuSeparator2(),
Core::Id("Debugger.Views.Separator2"), debugcontext);
cmd->setAttribute(Command::CA_Hide);
m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
cmd = am->registerAction(q->resetLayoutAction(),
Core::Id("Debugger.Views.ResetSimple"), debugcontext);
cmd->setAttribute(Command::CA_Hide);
m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
}
void DebuggerMainWindowPrivate::addLanguage(DebuggerLanguage languageId,
const Context &context)
{
m_supportedLanguages = m_supportedLanguages | languageId;
m_toolBars.insert(languageId, 0);
m_contextsForLanguage.insert(languageId, context);
}
void DebuggerMainWindowPrivate::activateQmlCppLayout()
{
Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
if (m_toolBars.value(QmlLanguage)) {
m_toolBars.value(QmlLanguage)->show();
m_debugToolBarLayout->insertWidget(1, m_toolBars.value(QmlLanguage));
}
if (m_previousDebugLanguages & QmlLanguage) {
m_dockWidgetActiveStateQmlCpp = q->saveSettings();
ICore::updateAdditionalContexts(qmlCppContext, Context());
} else if (m_previousDebugLanguages & CppLanguage) {
m_dockWidgetActiveStateCpp = q->saveSettings();
ICore::updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
Context());
}
q->restoreSettings(m_dockWidgetActiveStateQmlCpp);
ICore::updateAdditionalContexts(Context(), qmlCppContext);
}
void DebuggerMainWindowPrivate::activateCppLayout()
{
Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
if (m_toolBars.value(QmlLanguage)) {
m_toolBars.value(QmlLanguage)->hide();
m_debugToolBarLayout->removeWidget(m_toolBars.value(QmlLanguage));
}
if (m_previousDebugLanguages & QmlLanguage) {
m_dockWidgetActiveStateQmlCpp = q->saveSettings();
ICore::updateAdditionalContexts(qmlCppContext, Context());
} else if (m_previousDebugLanguages & CppLanguage) {
m_dockWidgetActiveStateCpp = q->saveSettings();
ICore::updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
Context());
}
q->restoreSettings(m_dockWidgetActiveStateCpp);
const Context &cppContext = m_contextsForLanguage.value(CppLanguage);
ICore::updateAdditionalContexts(Context(), cppContext);
}
void DebuggerMainWindow::setToolBar(DebuggerLanguage language, QWidget *widget)
{
Q_ASSERT(d->m_toolBars.contains(language));
d->m_toolBars[language] = widget;
if (language == CppLanguage)
d->m_debugToolBarLayout->addWidget(widget);
//Add widget at the end
if (language == AnyLanguage)
d->m_debugToolBarLayout->insertWidget(-1, widget, 10);
}
QDockWidget *DebuggerMainWindow::dockWidget(const QString &objectName) const
{
return findChild<QDockWidget *>(objectName);
}
bool DebuggerMainWindow::isDockVisible(const QString &objectName) const
{
QDockWidget *dock = dockWidget(objectName);
return dock && dock->toggleViewAction()->isChecked();
}
/*!
Keep track of dock widgets so they can be shown/hidden for different languages
*/
QDockWidget *DebuggerMainWindow::createDockWidget(const DebuggerLanguage &language,
QWidget *widget)
{
QDockWidget *dockWidget = addDockForWidget(widget);
dockWidget->setObjectName(widget->objectName());
addDockWidget(Qt::BottomDockWidgetArea, dockWidget);
if (!(d->m_activeDebugLanguages & language))
dockWidget->hide();
Context globalContext(Core::Constants::C_GLOBAL);
ActionManager *am = ICore::actionManager();
QAction *toggleViewAction = dockWidget->toggleViewAction();
Command *cmd = am->registerAction(toggleViewAction,
Core::Id(QLatin1String("Debugger.") + widget->objectName()), globalContext);
cmd->setAttribute(Command::CA_Hide);
d->m_menuCommandsToAdd.append(cmd);
dockWidget->installEventFilter(&d->m_resizeEventFilter);
connect(dockWidget->toggleViewAction(), SIGNAL(triggered(bool)),
d, SLOT(updateDockWidgetSettings()));
connect(dockWidget, SIGNAL(topLevelChanged(bool)),
d, SLOT(updateDockWidgetSettings()));
connect(dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
d, SLOT(updateDockWidgetSettings()));
return dockWidget;
}
static bool sortCommands(Command *cmd1, Command *cmd2)
{
return cmd1->action()->text() < cmd2->action()->text();
}
void DebuggerMainWindow::addStagedMenuEntries()
{
qSort(d->m_menuCommandsToAdd.begin(), d->m_menuCommandsToAdd.end(), &sortCommands);
foreach (Command *cmd, d->m_menuCommandsToAdd)
d->m_viewsMenu->addAction(cmd);
d->m_menuCommandsToAdd.clear();
}
QWidget *DebuggerMainWindow::createContents(IMode *mode)
{
ActionManager *am = ICore::actionManager();
ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
connect(pe->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
d, SLOT(updateUiForProject(ProjectExplorer::Project*)));
d->m_viewsMenu = am->actionContainer(Core::Id(Core::Constants::M_WINDOW_VIEWS));
QTC_ASSERT(d->m_viewsMenu, return 0)
//d->m_mainWindow = new Internal::DebuggerMainWindow(this);
setDocumentMode(true);
setDockNestingEnabled(true);
connect(this, SIGNAL(resetLayout()),
d, SLOT(resetDebuggerLayout()));
connect(toggleLockedAction(), SIGNAL(triggered()),
d, SLOT(updateDockWidgetSettings()));
QBoxLayout *editorHolderLayout = new QVBoxLayout;
editorHolderLayout->setMargin(0);
editorHolderLayout->setSpacing(0);
QWidget *editorAndFindWidget = new QWidget;
editorAndFindWidget->setLayout(editorHolderLayout);
editorHolderLayout->addWidget(new EditorManagerPlaceHolder(mode));
editorHolderLayout->addWidget(new FindToolBarPlaceHolder(editorAndFindWidget));
MiniSplitter *documentAndRightPane = new MiniSplitter;
documentAndRightPane->addWidget(editorAndFindWidget);
documentAndRightPane->addWidget(new RightPanePlaceHolder(mode));
documentAndRightPane->setStretchFactor(0, 1);
documentAndRightPane->setStretchFactor(1, 0);
Utils::StyledBar *debugToolBar = new Utils::StyledBar;
debugToolBar->setProperty("topBorder", true);
QHBoxLayout *debugToolBarLayout = new QHBoxLayout(debugToolBar);
debugToolBarLayout->setMargin(0);
debugToolBarLayout->setSpacing(0);
debugToolBarLayout->addWidget(d->m_debugToolBar);
debugToolBarLayout->addWidget(new Utils::StyledSeparator);
QDockWidget *dock = new QDockWidget(DebuggerMainWindowPrivate::tr("Debugger Toolbar"));
dock->setObjectName(QLatin1String("Debugger Toolbar"));
dock->setWidget(debugToolBar);
dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
dock->setAllowedAreas(Qt::BottomDockWidgetArea);
dock->setTitleBarWidget(new QWidget(dock));
dock->setProperty("managed_dockwidget", QLatin1String("true"));
addDockWidget(Qt::BottomDockWidgetArea, dock);
setToolBarDockWidget(dock);
QWidget *centralWidget = new QWidget;
setCentralWidget(centralWidget);
QVBoxLayout *centralLayout = new QVBoxLayout(centralWidget);
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.
MiniSplitter *mainWindowSplitter = new MiniSplitter;
mainWindowSplitter->addWidget(this);
QWidget *outputPane = new OutputPanePlaceHolder(mode, mainWindowSplitter);
outputPane->setObjectName(QLatin1String("DebuggerOutputPanePlaceHolder"));
mainWindowSplitter->addWidget(outputPane);
mainWindowSplitter->setStretchFactor(0, 10);
mainWindowSplitter->setStretchFactor(1, 0);
mainWindowSplitter->setOrientation(Qt::Vertical);
// Navigation and right-side window.
MiniSplitter *splitter = new MiniSplitter;
splitter->addWidget(new NavigationWidgetPlaceHolder(mode));
splitter->addWidget(mainWindowSplitter);
splitter->setStretchFactor(0, 0);
splitter->setStretchFactor(1, 1);
splitter->setObjectName(QLatin1String("DebugModeWidget"));
return splitter;
}
void DebuggerMainWindow::writeSettings() const
{
QSettings *settings = ICore::settings();
QTC_ASSERT(settings, return);
settings->beginGroup(QLatin1String("DebugMode.CppMode"));
QHashIterator<QString, QVariant> it(d->m_dockWidgetActiveStateCpp);
while (it.hasNext()) {
it.next();
settings->setValue(it.key(), it.value());
}
settings->endGroup();
settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
it = QHashIterator<QString, QVariant>(d->m_dockWidgetActiveStateQmlCpp);
while (it.hasNext()) {
it.next();
settings->setValue(it.key(), it.value());
}
settings->endGroup();
}
void DebuggerMainWindow::raiseDebuggerWindow()
{
Utils::AppMainWindow *appMainWindow = qobject_cast<Utils::AppMainWindow*>(ICore::mainWindow());
QTC_ASSERT(appMainWindow, return)
appMainWindow->raiseWindow();
}
void DebuggerMainWindow::readSettings()
{
QSettings *settings = ICore::settings();
QTC_ASSERT(settings, return);
d->m_dockWidgetActiveStateCpp.clear();
d->m_dockWidgetActiveStateQmlCpp.clear();
settings->beginGroup(QLatin1String("DebugMode.CppMode"));
foreach (const QString &key, settings->childKeys())
d->m_dockWidgetActiveStateCpp.insert(key, settings->value(key));
settings->endGroup();
settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
foreach (const QString &key, settings->childKeys())
d->m_dockWidgetActiveStateQmlCpp.insert(key, settings->value(key));
settings->endGroup();
// Reset initial settings when there are none yet.
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();
}
writeSettings();
}
void DebuggerMainWindowPrivate::resetDebuggerLayout()
{
m_activeDebugLanguages = DebuggerLanguage(QmlLanguage | CppLanguage);
setSimpleDockWidgetArrangement();
m_dockWidgetActiveStateQmlCpp = q->saveSettings();
m_activeDebugLanguages = CppLanguage;
m_previousDebugLanguages = CppLanguage;
setSimpleDockWidgetArrangement();
// will save state in m_dockWidgetActiveStateCpp
updateActiveLanguages();
}
void DebuggerMainWindowPrivate::updateDockWidgetSettings()
{
if (!m_inDebugMode || m_changingUI)
return;
if (isQmlActive())
m_dockWidgetActiveStateQmlCpp = q->saveSettings();
else
m_dockWidgetActiveStateCpp = q->saveSettings();
}
bool DebuggerMainWindowPrivate::isQmlCppActive() const
{
return (m_activeDebugLanguages & CppLanguage)
&& (m_activeDebugLanguages & QmlLanguage);
}
bool DebuggerMainWindowPrivate::isQmlActive() const
{
return (m_activeDebugLanguages & QmlLanguage);
}
QMenu *DebuggerMainWindow::createPopupMenu()
{
return FancyMainWindow::createPopupMenu();
}
void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
{
using namespace Constants;
QTC_ASSERT(q, return);
q->setTrackingEnabled(false);
QList<QDockWidget *> dockWidgets = q->dockWidgets();
foreach (QDockWidget *dockWidget, dockWidgets) {
dockWidget->setFloating(false);
q->removeDockWidget(dockWidget);
}
foreach (QDockWidget *dockWidget, dockWidgets) {
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();
}
QDockWidget *toolBarDock = q->toolBarDockWidget();
QDockWidget *breakDock = q->dockWidget(QLatin1String(DOCKWIDGET_BREAK));
QDockWidget *stackDock = q->dockWidget(QLatin1String(DOCKWIDGET_STACK));
QDockWidget *watchDock = q->dockWidget(QLatin1String(DOCKWIDGET_WATCHERS));
QDockWidget *snapshotsDock = q->dockWidget(QLatin1String(DOCKWIDGET_SNAPSHOTS));
QDockWidget *threadsDock = q->dockWidget(QLatin1String(DOCKWIDGET_THREADS));
QDockWidget *outputDock = q->dockWidget(QLatin1String(DOCKWIDGET_OUTPUT));
QDockWidget *qmlInspectorDock = q->dockWidget(QLatin1String(DOCKWIDGET_QML_INSPECTOR));
QDockWidget *consoleDock = q->dockWidget(QLatin1String(DOCKWIDGET_QML_SCRIPTCONSOLE));
QDockWidget *modulesDock = q->dockWidget(QLatin1String(DOCKWIDGET_MODULES));
QDockWidget *registerDock = q->dockWidget(QLatin1String(DOCKWIDGET_REGISTER));
QDockWidget *sourceFilesDock = q->dockWidget(QLatin1String(DOCKWIDGET_SOURCE_FILES));
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(consoleDock, return);
QTC_ASSERT(modulesDock, return);
QTC_ASSERT(registerDock, return);
QTC_ASSERT(sourceFilesDock, return);
// make sure main docks are visible so that split equally divides the space
toolBarDock->show();
stackDock->show();
breakDock->show();
watchDock->show();
// toolBar
// --------------------------------------------------------------------------------
// stack,qmlinspector | breakpoints,modules,register,threads,sourceFiles,snapshots,scriptconsole
//
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);
q->tabifyDockWidget(breakDock, consoleDock);
if (m_activeDebugLanguages.testFlag(Debugger::QmlLanguage)) {
if (qmlInspectorDock)
qmlInspectorDock->show();
if (consoleDock)
consoleDock->show();
} else {
// CPP only
threadsDock->show();
snapshotsDock->show();
}
q->setTrackingEnabled(true);
q->update();
}
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);
}
} // namespace Debugger
#include "debuggermainwindow.moc"
|