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
|
/**************************************************************************
**
** 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 "editorsplitter.h"
#include "coreconstants.h"
#include "editormanager.h"
#include "icore.h"
#include "minisplitter.h"
#include "openeditorswindow.h"
#include "stackededitorgroup.h"
#include "uniqueidmanager.h"
#include "actionmanager/actionmanager.h"
#include <utils/qtcassert.h>
#include <QtGui/QHBoxLayout>
#include <QtGui/QMenu>
#include <QtGui/QApplication>
using namespace Core;
using namespace Core::Internal;
EditorSplitter::EditorSplitter(QWidget *parent)
: QWidget(parent),
m_curGroup(0)
{
registerActions();
createRootGroup();
updateActions();
}
EditorSplitter::~EditorSplitter()
{
}
void EditorSplitter::registerActions()
{
QList<int> gc = QList<int>() << Constants::C_GLOBAL_ID;
const QList<int> editorManagerContext =
QList<int>() << ICore::instance()->uniqueIDManager()->uniqueIdentifier(Constants::C_EDITORMANAGER);
ActionManager *am = ICore::instance()->actionManager();
ActionContainer *mwindow = am->actionContainer(Constants::M_WINDOW);
Command *cmd;
#if 0
//Horizontal Action
m_horizontalSplitAction = new QAction(tr("Split Left/Right"), this);
cmd = am->registerAction(m_horizontalSplitAction, Constants::HORIZONTAL, editorManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_horizontalSplitAction, SIGNAL(triggered()),
this, SLOT(splitHorizontal()));
//Vertical Action
m_verticalSplitAction = new QAction(tr("Split Top/Bottom"), this);
cmd = am->registerAction(m_verticalSplitAction, Constants::VERTICAL, editorManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_verticalSplitAction, SIGNAL(triggered()),
this, SLOT(splitVertical()));
//Unsplit Action
m_unsplitAction = new QAction(tr("Unsplit"), this);
cmd = am->registerAction(m_unsplitAction, Constants::REMOVE, editorManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_unsplitAction, SIGNAL(triggered()),
this, SLOT(unsplit()));
#endif
//Default Layout menu
ActionContainer *mLayout = am->createMenu("QtCreator.Menu.Window.Layout");
mwindow->addMenu(mLayout, Constants::G_WINDOW_SPLIT);
mLayout->menu()->setTitle(tr("Default Splitter Layout"));
//Set Current As Default
m_currentAsDefault = new QAction(tr("Save Current as Default"), this);
cmd = am->registerAction(m_currentAsDefault, Constants::SAVEASDEFAULT, editorManagerContext);
mLayout->addAction(cmd);
connect(m_currentAsDefault, SIGNAL(triggered()),
this, SLOT(saveCurrentLayout()));
//Restore Default
m_restoreDefault = new QAction(tr("Restore Default Layout"), this);
cmd = am->registerAction(m_restoreDefault, Constants::RESTOREDEFAULT, editorManagerContext);
mLayout->addAction(cmd);
connect(m_restoreDefault, SIGNAL(triggered()),
this, SLOT(restoreDefaultLayout()));
// TODO: The previous and next actions are removed, to be reenabled when they
// navigate according to code navigation history. And they need different shortcuts on the mac
// since Alt+Left/Right is jumping wordwise in editors
#if 0
// Goto Previous Action
m_gotoPreviousEditorAction = new QAction(QIcon(Constants::ICON_PREV), tr("Previous Document"), this);
cmd = am->registerAction(m_gotoPreviousEditorAction, Constants::GOTOPREV, editorManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("Alt+Left")));
mwindow->addAction(cmd, Constants::G_WINDOW_NAVIGATE);
connect(m_gotoPreviousEditorAction, SIGNAL(triggered()), this, SLOT(gotoPreviousEditor()));
// Goto Next Action
m_gotoNextEditorAction = new QAction(QIcon(Constants::ICON_NEXT), tr("Next Document"), this);
cmd = am->registerAction(m_gotoNextEditorAction, Constants::GOTONEXT, editorManagerContext);
cmd->setDefaultKeySequence(QKeySequence(tr("Alt+Right")));
mwindow->addAction(cmd, Constants::G_WINDOW_NAVIGATE);
connect(m_gotoNextEditorAction, SIGNAL(triggered()), this, SLOT(gotoNextEditor()));
#endif
// Previous Group Action
m_gotoPreviousGroupAction = new QAction(tr("Previous Group"), this);
cmd = am->registerAction(m_gotoPreviousGroupAction, Constants::GOTOPREVIOUSGROUP, editorManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_NAVIGATE_GROUPS);
connect(m_gotoPreviousGroupAction, SIGNAL(triggered()), this, SLOT(selectPreviousGroup()));
// Next Group Action
m_gotoNextGroupAction = new QAction(tr("Next Group"), this);
cmd = am->registerAction(m_gotoNextGroupAction, Constants::GOTONEXTGROUP, editorManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_NAVIGATE_GROUPS);
connect(m_gotoNextGroupAction, SIGNAL(triggered()), this, SLOT(selectNextGroup()));
// Move to Previous Group
m_moveDocToPreviousGroupAction = new QAction(tr("Move Document to Previous Group"), this);
cmd = am->registerAction(m_moveDocToPreviousGroupAction, "QtCreator.DocumentToPreviousGroup", editorManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_NAVIGATE_GROUPS);
connect(m_moveDocToPreviousGroupAction, SIGNAL(triggered()), this, SLOT(moveDocToPreviousGroup()));
// Move to Next Group
m_moveDocToNextGroupAction = new QAction(tr("Move Document to Next Group"), this);
cmd = am->registerAction(m_moveDocToNextGroupAction, "QtCreator.DocumentToNextGroup", editorManagerContext);
mwindow->addAction(cmd, Constants::G_WINDOW_NAVIGATE_GROUPS);
connect(m_moveDocToNextGroupAction, SIGNAL(triggered()), this, SLOT(moveDocToNextGroup()));
}
void EditorSplitter::updateActions()
{
const bool hasMultipleGroups = (qobject_cast<QSplitter*>(m_root) != 0);
QTC_ASSERT(currentGroup(), return);
const bool hasEditors = (currentGroup()->editorCount() != 0);
m_unsplitAction->setEnabled(hasMultipleGroups);
#if 0
const bool hasMultipleEditors = (editorCount() > 1);
m_gotoNextEditorAction->setEnabled(hasMultipleEditors);
m_gotoPreviousEditorAction->setEnabled(hasMultipleEditors);
#endif
m_gotoPreviousGroupAction->setEnabled(hasMultipleGroups);
m_gotoNextGroupAction->setEnabled(hasMultipleGroups);
m_moveDocToPreviousGroupAction->setEnabled(hasEditors && hasMultipleGroups);
m_moveDocToNextGroupAction->setEnabled(hasEditors && hasMultipleGroups);
}
int EditorSplitter::editorCount() const
{
int count = 0;
foreach (EditorGroup *group, groups()) {
count += group->editorCount();
}
return count;
}
void EditorSplitter::createRootGroup()
{
QHBoxLayout *l = new QHBoxLayout(this);
l->setMargin(0);
l->setSpacing(0);
EditorGroup *rootGroup = createGroup();
m_root = rootGroup->widget();
l->addWidget(m_root);
setCurrentGroup(rootGroup);
}
void EditorSplitter::splitHorizontal()
{
split(Qt::Horizontal);
}
void EditorSplitter::splitVertical()
{
split(Qt::Vertical);
}
void EditorSplitter::gotoNextEditor()
{
OpenEditorsWindow *dialog = EditorManager::instance()->windowPopup();
dialog->setMode(OpenEditorsWindow::ListMode);
dialog->selectNextEditor();
EditorManager::instance()->showWindowPopup();
}
void EditorSplitter::gotoPreviousEditor()
{
OpenEditorsWindow *dialog = EditorManager::instance()->windowPopup();
dialog->setMode(OpenEditorsWindow::ListMode);
dialog->selectPreviousEditor();
EditorManager::instance()->showWindowPopup();
}
void EditorSplitter::setCurrentGroup(EditorGroup *group)
{
if (!group || group == m_curGroup)
return;
m_curGroup = group;
if (m_curGroup->widget()->focusWidget() != QApplication::focusWidget())
m_curGroup->widget()->setFocus();
updateActions();
}
QList<EditorGroup*> EditorSplitter::groups() const
{
QList<EditorGroup*> grps;
collectGroups(m_root, grps);
return grps;
}
void EditorSplitter::collectGroups(QWidget *widget, QList<EditorGroup*> &groups) const
{
EditorGroup *group = qobject_cast<EditorGroup *>(widget);
if (group) {
groups += group;
return;
}
QSplitter *splitter = qobject_cast<QSplitter*>(widget);
QTC_ASSERT(splitter, return);
collectGroups(splitter->widget(LEFT), groups);
collectGroups(splitter->widget(RIGHT), groups);
}
EditorGroup *EditorSplitter::currentGroup() const
{
return m_curGroup;
}
void EditorSplitter::split(Qt::Orientation orientation)
{
EditorGroup *curGroup = currentGroup();
IEditor *editor = curGroup->currentEditor();
split(orientation, 0);
if (editor) {
EditorGroup *otherGroup = currentGroup();
if (curGroup != otherGroup) {
curGroup->removeEditor(editor);
otherGroup->addEditor(editor);
}
}
emit editorGroupsChanged();
}
QSplitter *EditorSplitter::split(Qt::Orientation orientation, EditorGroup *group)
{
EditorGroup *curGroup = group;
if (!curGroup)
curGroup = currentGroup();
if (!curGroup)
return 0;
int oldSibling1 = -1;
int oldSibling2 = -1;
int idx = 1;
QWidget *curGroupWidget = curGroup->widget();
QSplitter *parentSplitter = qobject_cast<QSplitter*>(curGroupWidget->parentWidget());
if (parentSplitter) {
if (parentSplitter->orientation() == Qt::Vertical) {
oldSibling1 = parentSplitter->widget(LEFT)->height();
oldSibling2 = parentSplitter->widget(RIGHT)->height();
} else {
oldSibling1 = parentSplitter->widget(LEFT)->width();
oldSibling2 = parentSplitter->widget(RIGHT)->width();
}
idx = parentSplitter->indexOf(curGroupWidget);
}
QLayout *l = curGroupWidget->parentWidget()->layout();
curGroupWidget->setParent(0);
QSplitter *splitter = new MiniSplitter(0);
splitter->setOrientation(orientation);
EditorGroup *eg = createGroup();
splitter->addWidget(curGroupWidget);
splitter->addWidget(eg->widget());
if (curGroupWidget == m_root) {
l->addWidget(splitter);
m_root = splitter;
} else {
parentSplitter->insertWidget(idx, splitter);
}
if (parentSplitter)
parentSplitter->setSizes(QList<int>() << oldSibling1 << oldSibling2);
if (orientation == Qt::Vertical)
splitter->setSizes(QList<int>() << curGroupWidget->height()/2
<< curGroupWidget->height()/2);
else
splitter->setSizes(QList<int>() << curGroupWidget->width()/2
<< curGroupWidget->width()/2);
setCurrentGroup(eg);
return splitter;
}
void EditorSplitter::unsplit()
{
EditorGroup *curGroup = currentGroup();
if (!curGroup)
return;
QWidget *curGroupWidget = curGroup->widget();
QTC_ASSERT(curGroupWidget, return);
IEditor *selectedEditor = curGroup->currentEditor();
QSplitter *parentSplitter = qobject_cast<QSplitter*>(curGroupWidget->parentWidget());
if (parentSplitter) {
int oldSibling1 = -1;
int oldSibling2 = -1;
EditorGroup *e1 = qobject_cast<EditorGroup *>(parentSplitter->widget(LEFT));
EditorGroup *e2 = qobject_cast<EditorGroup *>(parentSplitter->widget(RIGHT));
QWidget *w = parentSplitter->parentWidget();
QSplitter *grandParentSplitter = qobject_cast<QSplitter*>(w);
int idx = 0;
if (grandParentSplitter) {
idx = grandParentSplitter->indexOf(parentSplitter);
if (grandParentSplitter->orientation() == Qt::Vertical) {
oldSibling1 = grandParentSplitter->widget(LEFT)->height();
oldSibling2 = grandParentSplitter->widget(RIGHT)->height();
} else {
oldSibling1 = grandParentSplitter->widget(LEFT)->width();
oldSibling2 = grandParentSplitter->widget(RIGHT)->width();
}
}
if (e1 && e2) { // we are unsplitting a split that contains of groups directly not one or more additional splits
e1->moveEditorsFromGroup(e2);
parentSplitter->setParent(0);
if (grandParentSplitter) {
grandParentSplitter->insertWidget(idx, e1->widget());
} else {
w->layout()->addWidget(e1->widget());
m_root = e1->widget();
}
setCurrentGroup(e1);
deleteGroup(e2);
e2 = 0;
delete parentSplitter;
e1->setCurrentEditor(selectedEditor);
} else if (e1 || e2) {
parentSplitter->setParent(0);
QSplitter *s = 0;
if (e1) {
s = qobject_cast<QSplitter*>(parentSplitter->widget(RIGHT));
} else {
s = qobject_cast<QSplitter*>(parentSplitter->widget(LEFT));
e1 = e2;
}
if (grandParentSplitter) {
grandParentSplitter->insertWidget(idx, s);
} else {
w->layout()->addWidget(s);
m_root = s;
}
EditorGroup *leftMost = groupFarthestOnSide(s, LEFT);
leftMost->moveEditorsFromGroup(e1);
leftMost->setCurrentEditor(selectedEditor);
setCurrentGroup(leftMost);
deleteGroup(e1);
}
if (grandParentSplitter)
grandParentSplitter->setSizes(QList<int>() << oldSibling1 << oldSibling2);
emit editorGroupsChanged();
}
updateActions();
}
void EditorSplitter::unsplitAll()
{
QSplitter *rootSplit = qobject_cast<QSplitter *>(m_root);
if (!rootSplit)
return;
// first create and set the new root, then kill the original stuff
// this way we can avoid unnecessary signals/ context changes
rootSplit->setParent(0);
EditorGroup *rootGroup = createGroup();
QLayout *l = layout();
l->addWidget(rootGroup->widget());
m_root = rootGroup->widget();
setCurrentGroup(rootGroup);
// kill old hierarchy
QList<IEditor *> editors;
unsplitAll(rootSplit->widget(1), editors);
unsplitAll(rootSplit->widget(0), editors);
delete rootSplit;
rootSplit = 0;
foreach (IEditor *editor, editors) {
rootGroup->addEditor(editor);
}
}
void EditorSplitter::unsplitAll(QWidget *node, QList<IEditor*> &editors)
{
QSplitter *splitter = qobject_cast<QSplitter *>(node);
if (splitter) {
unsplitAll(splitter->widget(1), editors);
unsplitAll(splitter->widget(0), editors);
delete splitter;
splitter = 0;
} else {
EditorGroup *group = qobject_cast<EditorGroup *>(node);
editors << group->editors();
bool blocking = group->widget()->blockSignals(true);
foreach (IEditor *editor, group->editors()) {
group->removeEditor(editor);
}
group->widget()->blockSignals(blocking);
deleteGroup(group);
}
}
EditorGroup *EditorSplitter::groupFarthestOnSide(QWidget *node, Side side) const
{
QWidget *current = node;
QSplitter *split = 0;
while ((split = qobject_cast<QSplitter*>(current))) {
current = split->widget(side);
}
return qobject_cast<EditorGroup *>(current);
}
void EditorSplitter::selectNextGroup()
{
EditorGroup *curGroup = currentGroup();
QTC_ASSERT(curGroup, return);
setCurrentGroup(nextGroup(curGroup, RIGHT));
}
void EditorSplitter::selectPreviousGroup()
{
EditorGroup *curGroup = currentGroup();
QTC_ASSERT(curGroup, return);
setCurrentGroup(nextGroup(curGroup, LEFT));
}
EditorGroup *EditorSplitter::nextGroup(EditorGroup *curGroup, Side side) const
{
QTC_ASSERT(curGroup, return 0);
QWidget *curWidget = curGroup->widget();
QWidget *parent = curWidget->parentWidget();
while (curWidget != m_root) {
QSplitter *splitter = qobject_cast<QSplitter *>(parent);
QTC_ASSERT(splitter, return 0);
if (splitter->widget(side) != curWidget) {
curWidget = splitter->widget(side);
break;
}
curWidget = parent;
parent = curWidget->parentWidget();
}
return groupFarthestOnSide(curWidget, side==LEFT ? RIGHT : LEFT);
}
void EditorSplitter::moveDocToAdjacentGroup(Side side)
{
EditorGroup *curGroup = currentGroup();
QTC_ASSERT(curGroup, return);
IEditor *editor = curGroup->currentEditor();
if (!editor)
return;
EditorGroup *next = nextGroup(curGroup, side);
next->moveEditorFromGroup(curGroup, editor);
setCurrentGroup(next);
}
void EditorSplitter::moveDocToNextGroup()
{
moveDocToAdjacentGroup(RIGHT);
}
void EditorSplitter::moveDocToPreviousGroup()
{
moveDocToAdjacentGroup(LEFT);
}
QWidget *EditorSplitter::recreateGroupTree(QWidget *node)
{
QSplitter *splitter = qobject_cast<QSplitter *>(node);
if (!splitter) {
EditorGroup *group = qobject_cast<EditorGroup *>(node);
QTC_ASSERT(group, return 0);
IEditor *currentEditor = group->currentEditor();
EditorGroup *newGroup = createGroup();
bool block = newGroup->widget()->blockSignals(true);
foreach (IEditor *editor, group->editors()) {
newGroup->addEditor(editor);
}
newGroup->setCurrentEditor(currentEditor);
deleteGroup(group);
newGroup->widget()->blockSignals(block);
return newGroup->widget();
} else {
QByteArray splitterState = splitter->saveState();
QWidget *orig0 = splitter->widget(0);
QWidget *orig1 = splitter->widget(1);
QWidget *g0 = recreateGroupTree(orig0);
QWidget *g1 = recreateGroupTree(orig1);
splitter->insertWidget(0, g0);
splitter->insertWidget(1, g1);
splitter->restoreState(splitterState);
return node;
}
}
void EditorSplitter::saveCurrentLayout()
{
QSettings *settings = ICore::instance()->settings();
settings->setValue("EditorManager/Splitting", saveState());
}
void EditorSplitter::restoreDefaultLayout()
{
QSettings *settings = ICore::instance()->settings();
if (settings->contains("EditorManager/Splitting"))
restoreState(settings->value("EditorManager/Splitting").toByteArray());
}
void EditorSplitter::saveSettings(QSettings * /*settings*/) const
{
}
void EditorSplitter::readSettings(QSettings * /*settings*/)
{
restoreDefaultLayout();
}
QByteArray EditorSplitter::saveState() const
{
//todo: versioning
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
saveState(m_root, stream);
return bytes;
}
bool EditorSplitter::restoreState(const QByteArray &state)
{
unsplitAll();
//todo: versioning
QDataStream stream(state);
EditorGroup *curGroup =
restoreState(qobject_cast<EditorGroup *>(m_root), stream);
setCurrentGroup(curGroup);
return true;
}
void EditorSplitter::saveState(QWidget *current, QDataStream &stream) const
{
QSplitter *splitter = qobject_cast<QSplitter *>(current);
quint8 type;
if (splitter) {
type = 0;
stream << type;
stream << splitter->saveState();
saveState(splitter->widget(0), stream);
saveState(splitter->widget(1), stream);
} else {
EditorGroup *group = qobject_cast<EditorGroup *>(current);
QTC_ASSERT(group, /**/);
if (group != currentGroup())
type = 1;
else
type = 2;
stream << type;
}
}
EditorGroup *EditorSplitter::restoreState(EditorGroup *current,
QDataStream &stream)
{
EditorGroup *curGroup = 0;
EditorGroup *group;
quint8 type;
stream >> type;
if (type == 0) {
QSplitter *splitter = split(Qt::Horizontal, current);
QByteArray splitterState;
stream >> splitterState;
splitter->restoreState(splitterState);
group = restoreState(qobject_cast<EditorGroup *>(splitter->widget(0)),
stream);
if (group)
curGroup = group;
group = restoreState(qobject_cast<EditorGroup *>(splitter->widget(1)),
stream);
if (group)
curGroup = group;
} else {
if (type == 2)
return current;
}
return curGroup;
}
QMap<QString,EditorGroup *> EditorSplitter::pathGroupMap()
{
QMap<QString,EditorGroup *> map;
fillPathGroupMap(m_root, "", map);
return map;
}
void EditorSplitter::fillPathGroupMap(QWidget *current, QString currentPath,
QMap<QString,EditorGroup *> &map)
{
EditorGroup *group = qobject_cast<EditorGroup *>(current);
if (group) {
map.insert(currentPath, group);
} else {
QSplitter *splitter = qobject_cast<QSplitter *>(current);
QTC_ASSERT(splitter, return);
fillPathGroupMap(splitter->widget(0), currentPath+"0", map);
fillPathGroupMap(splitter->widget(1), currentPath+"1", map);
}
}
EditorGroup *EditorSplitter::createGroup()
{
EditorGroup *group = new StackedEditorGroup(this);
connect(group, SIGNAL(closeRequested(Core::IEditor *)),
this, SIGNAL(closeRequested(Core::IEditor *)));
connect(group, SIGNAL(editorRemoved(Core::IEditor *)),
this, SLOT(updateActions()));
connect(group, SIGNAL(editorAdded(Core::IEditor *)),
this, SLOT(updateActions()));
ICore::instance()->addContextObject(group->contextObject());
return group;
}
void EditorSplitter::deleteGroup(EditorGroup *group)
{
ICore::instance()->removeContextObject(group->contextObject());
delete group;
}
|