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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "targetsettingspanel.h"
#include "buildconfiguration.h"
#include "buildmanager.h"
#include "buildsettingspropertiespage.h"
#include "ipotentialkit.h"
#include "kit.h"
#include "kitmanager.h"
#include "panelswidget.h"
#include "project.h"
#include "projectexplorer.h"
#include "projectexplorericons.h"
#include "projectwindow.h"
#include "runsettingspropertiespage.h"
#include "session.h"
#include "target.h"
#include "targetsetuppage.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/modemanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <utils/treemodel.h>
#include <utils/utilsicons.h>
#include <QCoreApplication>
#include <QApplication>
#include <QDialogButtonBox>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPainter>
#include <QPushButton>
#include <QTimer>
#include <QToolTip>
#include <QVBoxLayout>
#include <cmath>
using namespace Core;
using namespace Utils;
namespace ProjectExplorer {
namespace Internal {
class TargetSetupPageWrapper : public QWidget
{
Q_DECLARE_TR_FUNCTIONS(TargetSettingsPanelWidget)
public:
explicit TargetSetupPageWrapper(Project *project);
protected:
void keyReleaseEvent(QKeyEvent *event) override
{
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
event->accept();
}
void keyPressEvent(QKeyEvent *event) override
{
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
event->accept();
done();
}
}
private:
void done()
{
m_targetSetupPage->setupProject(m_project);
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
}
void cancel()
{
ProjectExplorerPlugin::unloadProject(m_project);
}
void kitUpdated(ProjectExplorer::Kit *k)
{
if (k == KitManager::defaultKit())
updateNoteText();
}
void completeChanged()
{
m_configureButton->setEnabled(m_targetSetupPage->isComplete());
}
void updateNoteText();
Project *m_project;
TargetSetupPage *m_targetSetupPage;
QPushButton *m_configureButton;
};
TargetSetupPageWrapper::TargetSetupPageWrapper(Project *project)
: m_project(project)
{
m_targetSetupPage = new TargetSetupPage(this);
m_targetSetupPage->setUseScrollArea(false);
m_targetSetupPage->setProjectPath(project->projectFilePath().toString());
m_targetSetupPage->setRequiredKitPredicate(project->requiredKitPredicate());
m_targetSetupPage->setPreferredKitPredicate(project->preferredKitPredicate());
m_targetSetupPage->setProjectImporter(project->projectImporter());
m_targetSetupPage->initializePage();
m_targetSetupPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
updateNoteText();
auto box = new QDialogButtonBox(this);
m_configureButton = new QPushButton(this);
m_configureButton->setText(tr("Configure Project"));
box->addButton(m_configureButton, QDialogButtonBox::AcceptRole);
auto hbox = new QHBoxLayout;
hbox->addStretch();
hbox->addWidget(box);
auto layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->addWidget(m_targetSetupPage);
layout->addLayout(hbox);
layout->addStretch(10);
completeChanged();
connect(m_configureButton, &QAbstractButton::clicked,
this, &TargetSetupPageWrapper::done);
connect(m_targetSetupPage, &QWizardPage::completeChanged,
this, &TargetSetupPageWrapper::completeChanged);
connect(KitManager::instance(), &KitManager::defaultkitChanged,
this, &TargetSetupPageWrapper::updateNoteText);
connect(KitManager::instance(), &KitManager::kitUpdated,
this, &TargetSetupPageWrapper::kitUpdated);
}
void TargetSetupPageWrapper::updateNoteText()
{
Kit *k = KitManager::defaultKit();
QString text;
bool showHint = false;
if (!k) {
text = tr("The project <b>%1</b> is not yet configured.<br/>"
"Qt Creator cannot parse the project, because no kit "
"has been set up.")
.arg(m_project->displayName());
showHint = true;
} else if (k->isValid()) {
text = tr("The project <b>%1</b> is not yet configured.<br/>"
"Qt Creator uses the kit <b>%2</b> to parse the project.")
.arg(m_project->displayName())
.arg(k->displayName());
showHint = false;
} else {
text = tr("The project <b>%1</b> is not yet configured.<br/>"
"Qt Creator uses the <b>invalid</b> kit <b>%2</b> to parse the project.")
.arg(m_project->displayName())
.arg(k->displayName());
showHint = true;
}
m_targetSetupPage->setNoteText(text);
m_targetSetupPage->showOptionsHint(showHint);
}
//
// TargetSettingsPanelItem
//
class TargetGroupItemPrivate : public QObject
{
Q_DECLARE_TR_FUNCTIONS(TargetSettingsPanelItem)
public:
TargetGroupItemPrivate(TargetGroupItem *q, Project *project);
~TargetGroupItemPrivate();
void handleRemovedKit(Kit *kit);
void handleAddedKit(Kit *kit);
void handleUpdatedKit(Kit *kit);
void handleTargetAdded(Target *target);
void handleTargetRemoved(Target *target);
void handleTargetChanged(Target *target);
void ensureWidget();
void rebuildContents();
TargetGroupItem *q;
QString m_displayName;
Project *m_project;
QPointer<QWidget> m_noKitLabel;
QPointer<QWidget> m_configurePage;
QPointer<QWidget> m_configuredPage;
};
void TargetGroupItemPrivate::ensureWidget()
{
if (!m_noKitLabel) {
m_noKitLabel = new QWidget;
m_noKitLabel->setFocusPolicy(Qt::NoFocus);
auto label = new QLabel;
label->setText(tr("No kit defined in this project."));
QFont f = label->font();
f.setPointSizeF(f.pointSizeF() * 1.4);
f.setBold(true);
label->setFont(f);
label->setMargin(10);
label->setAlignment(Qt::AlignTop);
auto layout = new QVBoxLayout(m_noKitLabel);
layout->setMargin(0);
layout->setSpacing(0);
layout->addWidget(label);
layout->addStretch(10);
}
if (!m_configurePage) {
auto widget = new TargetSetupPageWrapper(m_project);
m_configurePage = new PanelsWidget(tr("Configure Project"),
QIcon(":/projectexplorer/images/unconfigured.png"),
widget);
m_configurePage->setFocusProxy(widget);
}
if (!m_configuredPage) {
auto widget = new QWidget;
auto label = new QLabel("This project is already configured.");
auto layout = new QVBoxLayout(widget);
layout->setMargin(0);
layout->addWidget(label);
layout->addStretch(10);
m_configuredPage = new PanelsWidget(tr("Configure Project"),
QIcon(":/projectexplorer/images/unconfigured.png"),
widget);
}
}
//
// Third level: The per-kit entries (inactive or with a 'Build' and a 'Run' subitem)
//
class TargetItem : public TypedTreeItem<TreeItem, TargetGroupItem>
{
Q_DECLARE_TR_FUNCTIONS(TargetSettingsPanelWidget)
public:
enum { DefaultPage = 0 }; // Build page.
TargetItem(Project *project, Id kitId)
: m_project(project), m_kitId(kitId)
{
updateSubItems();
}
Target *target() const
{
return m_project->target(m_kitId);
}
void updateSubItems();
Qt::ItemFlags flags(int column) const override
{
Q_UNUSED(column)
return Qt::ItemFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
}
QVariant data(int column, int role) const override
{
switch (role) {
case Qt::DisplayRole: {
if (Kit *kit = KitManager::kit(m_kitId))
return kit->displayName();
break;
}
case Qt::DecorationRole: {
const Kit *k = KitManager::kit(m_kitId);
QTC_ASSERT(k, return QVariant());
if (!isEnabled())
return kitIconWithOverlay(*k, IconOverlay::Add);
if (!k->isValid())
return kitIconWithOverlay(*k, IconOverlay::Error);
if (k->hasWarning())
return kitIconWithOverlay(*k, IconOverlay::Warning);
return k->icon();
}
case Qt::TextColorRole: {
if (!isEnabled())
return Utils::creatorTheme()->color(Theme::TextColorDisabled);
break;
}
case Qt::FontRole: {
QFont font = parent()->data(column, role).value<QFont>();
if (TargetItem *targetItem = parent()->currentTargetItem())
if (targetItem->target()->id() == m_kitId
&& m_project == SessionManager::startupProject())
font.setBold(true);
return font;
}
case Qt::ToolTipRole: {
Kit *k = KitManager::kit(m_kitId);
QTC_ASSERT(k, return QVariant());
QString toolTip;
if (!isEnabled())
toolTip = "<h3>" + tr("Click to activate:") + "</h3>";
toolTip += k->toHtml();
return toolTip;
}
case PanelWidgetRole:
case ActiveItemRole: {
if (m_currentChild >= 0 && m_currentChild < childCount())
return childAt(m_currentChild)->data(column, role);
break;
}
default:
break;
}
return QVariant();
}
bool setData(int column, const QVariant &data, int role) override
{
Q_UNUSED(column)
if (role == ContextMenuItemAdderRole) {
QMenu *menu = data.value<QMenu *>();
addToContextMenu(menu);
return true;
}
if (role == ItemActivatedDirectlyRole) {
QTC_ASSERT(!data.isValid(), return false);
if (!isEnabled()) {
m_currentChild = DefaultPage;
Kit *k = KitManager::kit(m_kitId);
m_project->addTarget(m_project->createTarget(k));
} else {
// Go to Run page, when on Run previously etc.
TargetItem *previousItem = parent()->currentTargetItem();
m_currentChild = previousItem ? previousItem->m_currentChild : DefaultPage;
SessionManager::setActiveTarget(m_project, target(), SetActive::Cascade);
parent()->setData(column, QVariant::fromValue(static_cast<TreeItem *>(this)),
ItemActivatedFromBelowRole);
}
return true;
}
if (role == ItemActivatedFromBelowRole) {
// I.e. 'Build' and 'Run' items were present and user clicked on them.
int child = indexOf(data.value<TreeItem *>());
QTC_ASSERT(child != -1, return false);
m_currentChild = child; // Triggered from sub-item.
SessionManager::setActiveTarget(m_project, target(), SetActive::Cascade);
// Propagate Build/Run selection up.
parent()->setData(column, QVariant::fromValue(static_cast<TreeItem *>(this)),
ItemActivatedFromBelowRole);
return true;
}
if (role == ItemActivatedFromAboveRole) {
// Usually programmatic activation, e.g. after opening the Project mode.
SessionManager::setActiveTarget(m_project, target(), SetActive::Cascade);
return true;
}
return false;
}
void addToContextMenu(QMenu *menu)
{
Kit *kit = KitManager::kit(m_kitId);
QTC_ASSERT(kit, return);
const QString kitName = kit->displayName();
const QString projectName = m_project->displayName();
QAction *enableAction = menu->addAction(tr("Enable Kit \"%1\" for Project \"%2\"").arg(kitName, projectName));
enableAction->setEnabled(m_kitId.isValid() && !isEnabled());
QObject::connect(enableAction, &QAction::triggered, [this, kit] {
m_project->addTarget(m_project->createTarget(kit));
});
QAction *disableAction = menu->addAction(tr("Disable Kit \"%1\" for Project \"%2\"").arg(kitName, projectName));
disableAction->setEnabled(m_kitId.isValid() && isEnabled());
QObject::connect(disableAction, &QAction::triggered, [this, kit] {
Target *t = target();
QTC_ASSERT(t, return);
QString kitName = t->displayName();
if (BuildManager::isBuilding(t)) {
QMessageBox box;
QPushButton *closeAnyway = box.addButton(tr("Cancel Build and Disable Kit in This Project"), QMessageBox::AcceptRole);
QPushButton *cancelClose = box.addButton(tr("Do Not Remove"), QMessageBox::RejectRole);
box.setDefaultButton(cancelClose);
box.setWindowTitle(tr("Disable Kit %1 in This Project?").arg(kitName));
box.setText(tr("The kit <b>%1</b> is currently being built.").arg(kitName));
box.setInformativeText(tr("Do you want to cancel the build process and remove the kit anyway?"));
box.exec();
if (box.clickedButton() != closeAnyway)
return;
BuildManager::cancel();
}
QCoreApplication::processEvents();
m_project->removeTarget(t);
});
QMenu *copyMenu = menu->addMenu(tr("Copy Steps From Other Kit..."));
if (m_kitId.isValid() && m_project->target(m_kitId)) {
const QList<Kit *> kits = KitManager::kits();
for (Kit *kit : kits) {
QAction *copyAction = copyMenu->addAction(kit->displayName());
if (kit->id() == m_kitId || !m_project->target(kit->id())) {
copyAction->setEnabled(false);
} else {
QObject::connect(copyAction, &QAction::triggered, [this, kit] {
Target *thisTarget = m_project->target(m_kitId);
Target *sourceTarget = m_project->target(kit->id());
Project::copySteps(sourceTarget, thisTarget);
});
}
}
} else {
copyMenu->setEnabled(false);
}
}
bool isEnabled() const { return target() != 0; }
public:
QPointer<Project> m_project; // Not owned.
Id m_kitId;
int m_currentChild = DefaultPage; // Use run page by default.
private:
enum class IconOverlay {
Add,
Warning,
Error
};
static QIcon kitIconWithOverlay(const Kit &kit, IconOverlay overlayType)
{
QIcon overlayIcon;
switch (overlayType) {
case IconOverlay::Add: {
static const QIcon add = Utils::Icons::OVERLAY_ADD.icon();
overlayIcon = add;
break;
}
case IconOverlay::Warning: {
static const QIcon warning = Utils::Icons::OVERLAY_WARNING.icon();
overlayIcon = warning;
break;
}
case IconOverlay::Error: {
static const QIcon err = Utils::Icons::OVERLAY_ERROR.icon();
overlayIcon = err;
break;
}
}
const QSize iconSize(16, 16);
const QRect iconRect(QPoint(), iconSize);
QPixmap result(iconSize * qApp->devicePixelRatio());
result.fill(Qt::transparent);
result.setDevicePixelRatio(qApp->devicePixelRatio());
QPainter p(&result);
kit.icon().paint(&p, iconRect, Qt::AlignCenter,
overlayType == IconOverlay::Add ? QIcon::Disabled : QIcon::Normal);
overlayIcon.paint(&p, iconRect);
return result;
}
};
//
// Fourth level: The 'Build' and 'Run' sub-items.
//
class BuildOrRunItem : public TreeItem
{
Q_DECLARE_TR_FUNCTIONS(TargetSettingsPanelWidget)
public:
enum SubIndex { BuildPage = 0, RunPage = 1 };
BuildOrRunItem(Project *project, Id kitId, SubIndex subIndex)
: m_project(project), m_kitId(kitId), m_subIndex(subIndex)
{
}
~BuildOrRunItem()
{
delete m_panel;
}
Target *target() const
{
return m_project->target(m_kitId);
}
QVariant data(int column, int role) const override
{
switch (role) {
case Qt::DisplayRole: {
switch (m_subIndex) {
case BuildPage:
return tr("Build");
case RunPage:
return tr("Run");
}
break;
}
case Qt::ToolTipRole:
return parent()->data(column, role);
case PanelWidgetRole:
return QVariant::fromValue(panel());
case ActiveItemRole:
return QVariant::fromValue<TreeItem *>(const_cast<BuildOrRunItem *>(this));
case KitIdRole:
return m_kitId.toSetting();
case Qt::DecorationRole: {
switch (m_subIndex) {
case BuildPage: {
static const QIcon buildIcon = ProjectExplorer::Icons::BUILD_SMALL.icon();
return buildIcon;
}
case RunPage: {
static const QIcon runIcon = Utils::Icons::RUN_SMALL.icon();
return runIcon;
}
}
break;
}
default:
break;
}
return QVariant();
}
Qt::ItemFlags flags(int column) const override
{
return parent()->flags(column);
}
bool setData(int column, const QVariant &data, int role) override
{
if (role == ItemActivatedDirectlyRole) {
parent()->setData(column, QVariant::fromValue(static_cast<TreeItem *>(this)),
ItemActivatedFromBelowRole);
return true;
}
return parent()->setData(column, data, role);
}
QWidget *panel() const
{
if (!m_panel) {
m_panel = (m_subIndex == RunPage)
? new PanelsWidget(RunSettingsWidget::tr("Run Settings"),
QIcon(":/projectexplorer/images/RunSettings.png"),
new RunSettingsWidget(target()))
: new PanelsWidget(QCoreApplication::translate("BuildSettingsPanel", "Build Settings"),
QIcon(":/projectexplorer/images/BuildSettings.png"),
new BuildSettingsWidget(target()));
}
return m_panel;
}
public:
Project *m_project; // Not owned.
Id m_kitId;
mutable QPointer<QWidget> m_panel; // Owned.
const SubIndex m_subIndex;
};
//
// Also third level:
//
class PotentialKitItem : public TypedTreeItem<TreeItem, TargetGroupItem>
{
Q_DECLARE_TR_FUNCTIONS(TargetSettingsPanelWidget)
public:
PotentialKitItem(Project *project, IPotentialKit *potentialKit)
: m_project(project), m_potentialKit(potentialKit)
{}
QVariant data(int column, int role) const override
{
if (role == Qt::DisplayRole)
return m_potentialKit->displayName();
if (role == Qt::FontRole) {
QFont font = parent()->data(column, role).value<QFont>();
font.setItalic(true);
return font;
}
return QVariant();
}
bool setData(int column, const QVariant &data, int role) override
{
Q_UNUSED(column)
if (role == ContextMenuItemAdderRole) {
QMenu *menu = data.value<QMenu *>();
auto enableAction = menu->addAction(tr("Enable Kit"));
enableAction->setEnabled(!isEnabled());
QObject::connect(enableAction, &QAction::triggered, [this] {
m_potentialKit->executeFromMenu();
});
return true;
}
return false;
}
Qt::ItemFlags flags(int column) const override
{
Q_UNUSED(column)
if (isEnabled())
return Qt::ItemFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
return Qt::ItemIsSelectable;
}
bool isEnabled() const { return m_potentialKit->isEnabled(); }
Project *m_project;
IPotentialKit *m_potentialKit;
};
TargetGroupItem::TargetGroupItem(const QString &displayName, Project *project)
: d(new TargetGroupItemPrivate(this, project))
{
d->m_displayName = displayName;
QObject::connect(project, &Project::addedTarget,
d, &TargetGroupItemPrivate::handleTargetAdded,
Qt::QueuedConnection);
QObject::connect(project, &Project::removedTarget,
d, &TargetGroupItemPrivate::handleTargetRemoved);
QObject::connect(project, &Project::activeTargetChanged,
d, &TargetGroupItemPrivate::handleTargetChanged, Qt::QueuedConnection);
}
TargetGroupItem::~TargetGroupItem()
{
delete d;
}
TargetGroupItemPrivate::TargetGroupItemPrivate(TargetGroupItem *q, Project *project)
: q(q), m_project(project)
{
// force a signal since the index has changed
connect(KitManager::instance(), &KitManager::kitAdded,
this, &TargetGroupItemPrivate::handleAddedKit);
connect(KitManager::instance(), &KitManager::kitRemoved,
this, &TargetGroupItemPrivate::handleRemovedKit);
connect(KitManager::instance(), &KitManager::kitUpdated,
this, &TargetGroupItemPrivate::handleUpdatedKit);
rebuildContents();
}
TargetGroupItemPrivate::~TargetGroupItemPrivate()
{
disconnect();
delete m_noKitLabel;
delete m_configurePage;
delete m_configuredPage;
}
QVariant TargetGroupItem::data(int column, int role) const
{
if (role == Qt::DisplayRole)
return d->m_displayName;
if (role == ActiveItemRole) {
if (TargetItem *item = currentTargetItem())
return item->data(column, role);
return QVariant::fromValue<TreeItem *>(const_cast<TargetGroupItem *>(this));
}
if (role == PanelWidgetRole) {
if (TargetItem *item = currentTargetItem())
return item->data(column, role);
d->ensureWidget();
return QVariant::fromValue<QWidget *>(d->m_configurePage.data());
}
return QVariant();
}
bool TargetGroupItem::setData(int column, const QVariant &data, int role)
{
Q_UNUSED(data)
if (role == ItemActivatedFromBelowRole || role == ItemUpdatedFromBelowRole) {
// Bubble up to trigger setting the active project.
parent()->setData(column, QVariant::fromValue(static_cast<TreeItem *>(this)), role);
return true;
}
return false;
}
Qt::ItemFlags TargetGroupItem::flags(int) const
{
return Qt::NoItemFlags;
}
TargetItem *TargetGroupItem::currentTargetItem() const
{
return targetItem(d->m_project->activeTarget());
}
TargetItem *TargetGroupItem::targetItem(Target *target) const
{
if (target) {
Id needle = target->id(); // Unconfigured project have no active target.
return findFirstLevelChild([this, needle](TargetItem *item) { return item->m_kitId == needle; });
}
return 0;
}
void TargetGroupItemPrivate::handleRemovedKit(Kit *kit)
{
Q_UNUSED(kit);
rebuildContents();
}
void TargetGroupItemPrivate::handleUpdatedKit(Kit *kit)
{
Q_UNUSED(kit);
rebuildContents();
}
void TargetGroupItemPrivate::handleAddedKit(Kit *kit)
{
if (m_project->supportsKit(kit))
q->appendChild(new TargetItem(m_project, kit->id()));
}
void TargetItem::updateSubItems()
{
if (childCount() == 0 && isEnabled())
m_currentChild = DefaultPage; // We will add children below.
removeChildren();
if (isEnabled()) {
appendChild(new BuildOrRunItem(m_project, m_kitId, BuildOrRunItem::BuildPage));
appendChild(new BuildOrRunItem(m_project, m_kitId, BuildOrRunItem::RunPage));
}
}
void TargetGroupItemPrivate::rebuildContents()
{
q->removeChildren();
const QList<Kit *> kits = KitManager::sortKits(KitManager::kits([this](const Kit *kit) {
return m_project->supportsKit(const_cast<Kit *>(kit));
}));
for (Kit *kit : kits)
q->appendChild(new TargetItem(m_project, kit->id()));
if (q->parent())
q->parent()->setData(0, QVariant::fromValue(static_cast<TreeItem *>(q)),
ItemUpdatedFromBelowRole);
}
void TargetGroupItemPrivate::handleTargetAdded(Target *target)
{
if (TargetItem *item = q->targetItem(target))
item->updateSubItems();
q->update();
}
void TargetGroupItemPrivate::handleTargetRemoved(Target *target)
{
if (TargetItem *item = q->targetItem(target))
item->updateSubItems();
q->parent()->setData(0, QVariant::fromValue(static_cast<TreeItem *>(q)),
ItemDeactivatedFromBelowRole);
}
void TargetGroupItemPrivate::handleTargetChanged(Target *target)
{
if (TargetItem *item = q->targetItem(target))
item->updateSubItems();
q->setData(0, QVariant(), ItemActivatedFromBelowRole);
}
} // Internal
} // ProjectExplorer
|