runsettingspropertiespage.cpp 20.6 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** 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 Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "runsettingspropertiespage.h"
Tobias Hunger's avatar
Tobias Hunger committed
31
32
33
34

#include "buildstepspage.h"
#include "deployconfiguration.h"
#include "deployconfigurationmodel.h"
dt's avatar
dt committed
35
#include "runconfigurationmodel.h"
con's avatar
con committed
36
#include "runconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
37
#include "target.h"
38
#include "project.h"
con's avatar
con committed
39
40

#include <extensionsystem/pluginmanager.h>
Daniel Teske's avatar
Daniel Teske committed
41
42
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/buildmanager.h>
43
#include <utils/algorithm.h>
hjk's avatar
hjk committed
44
#include <utils/qtcassert.h>
con's avatar
con committed
45

46
47
48
49
50
51
52
53
54
55
56
#include <QVariant>
#include <QAction>
#include <QComboBox>
#include <QGridLayout>
#include <QInputDialog>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QSpacerItem>
#include <QWidget>
con's avatar
con committed
57
58
59

namespace ProjectExplorer {
namespace Internal {
hjk's avatar
hjk committed
60

61
struct FactoryAndId
con's avatar
con committed
62
63
{
    ProjectExplorer::IRunConfigurationFactory *factory;
64
    Core::Id id;
con's avatar
con committed
65
};
hjk's avatar
hjk committed
66

67
68
69
70
71
72
73
class DeployFactoryAndId
{
public:
    ProjectExplorer::DeployConfigurationFactory *factory;
    Core::Id id;
};

74

hjk's avatar
hjk committed
75
76
} // namespace Internal
} // namespace ProjectExplorer
con's avatar
con committed
77

78
Q_DECLARE_METATYPE(ProjectExplorer::Internal::FactoryAndId)
79
Q_DECLARE_METATYPE(ProjectExplorer::Internal::DeployFactoryAndId)
con's avatar
con committed
80
81
82
83
84
85
86
87
88

using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
using ExtensionSystem::PluginManager;

///
/// RunSettingsWidget
///

Tobias Hunger's avatar
Tobias Hunger committed
89
90
RunSettingsWidget::RunSettingsWidget(Target *target)
    : m_target(target),
dt's avatar
dt committed
91
      m_runConfigurationsModel(new RunConfigurationModel(target, this)),
Tobias Hunger's avatar
Tobias Hunger committed
92
      m_deployConfigurationModel(new DeployConfigurationModel(target, this)),
93
      m_runConfigurationWidget(0),
94
      m_runConfiguration(0),
95
      m_runLayout(0),
Tobias Hunger's avatar
Tobias Hunger committed
96
97
98
      m_deployConfigurationWidget(0),
      m_deployLayout(0),
      m_deploySteps(0),
99
      m_ignoreChange(false)
con's avatar
con committed
100
{
Tobias Hunger's avatar
Tobias Hunger committed
101
102
    Q_ASSERT(m_target);

103
104
105
    m_deployConfigurationCombo = new QComboBox(this);
    m_addDeployToolButton = new QPushButton(tr("Add"), this);
    m_removeDeployToolButton = new QPushButton(tr("Remove"), this);
hjk's avatar
hjk committed
106
    m_renameDeployButton = new QPushButton(tr("Rename..."), this);
107
108
109
110
111
112
113
114
115

    QWidget *deployWidget = new QWidget(this);

    m_runConfigurationCombo = new QComboBox(this);
    m_runConfigurationCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    m_runConfigurationCombo->setMinimumContentsLength(15);

    m_addRunToolButton = new QPushButton(tr("Add"), this);
    m_removeRunToolButton = new QPushButton(tr("Remove"), this);
hjk's avatar
hjk committed
116
    m_renameRunButton = new QPushButton(tr("Rename..."), this);
117

118
119
120
121
    QSpacerItem *spacer1 =
        new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum);
    QSpacerItem *spacer2 =
        new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding);
122
123
124

    QWidget *runWidget = new QWidget(this);

125
126
127
    QLabel *deployTitle = new QLabel(tr("Deployment"), this);
    QLabel *deployLabel = new QLabel(tr("Method:"), this);
    QLabel *runTitle = new QLabel(tr("Run"), this);
128
    QLabel *runLabel = new QLabel(tr("Run configuration:"), this);
129

130
131
    runLabel->setBuddy(m_runConfigurationCombo);

132
133
134
135
136
137
    QFont f = runLabel->font();
    f.setBold(true);
    f.setPointSizeF(f.pointSizeF() * 1.2);

    runTitle->setFont(f);
    deployTitle->setFont(f);
138
139

    m_gridLayout = new QGridLayout(this);
140
    m_gridLayout->setContentsMargins(0, 20, 0, 0);
141
    m_gridLayout->setHorizontalSpacing(6);
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    m_gridLayout->setVerticalSpacing(8);
    m_gridLayout->addWidget(deployTitle, 0, 0, 1, 6);
    m_gridLayout->addWidget(deployLabel, 1, 0, 1, 1);
    m_gridLayout->addWidget(m_deployConfigurationCombo, 1, 1, 1, 1);
    m_gridLayout->addWidget(m_addDeployToolButton, 1, 2, 1, 1);
    m_gridLayout->addWidget(m_removeDeployToolButton, 1, 3, 1, 1);
    m_gridLayout->addWidget(m_renameDeployButton, 1, 4, 1, 1);
    m_gridLayout->addWidget(deployWidget, 2, 0, 1, 6);

    m_gridLayout->addWidget(runTitle, 3, 0, 1, 6);
    m_gridLayout->addWidget(runLabel, 4, 0, 1, 1);
    m_gridLayout->addWidget(m_runConfigurationCombo, 4, 1, 1, 1);
    m_gridLayout->addWidget(m_addRunToolButton, 4, 2, 1, 1);
    m_gridLayout->addWidget(m_removeRunToolButton, 4, 3, 1, 1);
    m_gridLayout->addWidget(m_renameRunButton, 4, 4, 1, 1);
    m_gridLayout->addItem(spacer1, 4, 5, 1, 1);
    m_gridLayout->addWidget(runWidget, 5, 0, 1, 6);
    m_gridLayout->addItem(spacer2, 6, 0, 1, 1);
Tobias Hunger's avatar
Tobias Hunger committed
160

161
    // deploy part
162
163
    deployWidget->setContentsMargins(0, 10, 0, 25);
    m_deployLayout = new QVBoxLayout(deployWidget);
Tobias Hunger's avatar
Tobias Hunger committed
164
165
166
    m_deployLayout->setMargin(0);
    m_deployLayout->setSpacing(5);

167
168
169
170
    m_deployConfigurationCombo->setModel(m_deployConfigurationModel);

    m_addDeployMenu = new QMenu(m_addDeployToolButton);
    m_addDeployToolButton->setMenu(m_addDeployMenu);
Tobias Hunger's avatar
Tobias Hunger committed
171
172
173

    updateDeployConfiguration(m_target->activeDeployConfiguration());

174
    // Some projects may not support deployment, so we need this:
175
176
    m_addDeployToolButton->setEnabled(m_target->activeDeployConfiguration());
    m_deployConfigurationCombo->setEnabled(m_target->activeDeployConfiguration());
177

178
179
    m_removeDeployToolButton->setEnabled(m_target->deployConfigurations().count() > 1);
    m_renameDeployButton->setEnabled(m_target->activeDeployConfiguration());
Tobias Hunger's avatar
Tobias Hunger committed
180
181
182

    connect(m_addDeployMenu, SIGNAL(aboutToShow()),
            this, SLOT(aboutToShowDeployMenu()));
183
    connect(m_deployConfigurationCombo, SIGNAL(currentIndexChanged(int)),
Tobias Hunger's avatar
Tobias Hunger committed
184
            this, SLOT(currentDeployConfigurationChanged(int)));
185
    connect(m_removeDeployToolButton, SIGNAL(clicked(bool)),
Tobias Hunger's avatar
Tobias Hunger committed
186
            this, SLOT(removeDeployConfiguration()));
187
    connect(m_renameDeployButton, SIGNAL(clicked()),
188
            this, SLOT(renameDeployConfiguration()));
Tobias Hunger's avatar
Tobias Hunger committed
189
190
191
192
193

    connect(m_target, SIGNAL(activeDeployConfigurationChanged(ProjectExplorer::DeployConfiguration*)),
            this, SLOT(activeDeployConfigurationChanged()));

    // run part
194
195
    runWidget->setContentsMargins(0, 10, 0, 25);
    m_runLayout = new QVBoxLayout(runWidget);
196
197
198
    m_runLayout->setMargin(0);
    m_runLayout->setSpacing(5);

199
200
    m_addRunMenu = new QMenu(m_addRunToolButton);
    m_addRunToolButton->setMenu(m_addRunMenu);
201
    RunConfiguration *rc = m_target->activeRunConfiguration();
202
203
    m_runConfigurationCombo->setModel(m_runConfigurationsModel);
    m_runConfigurationCombo->setCurrentIndex(
204
            m_runConfigurationsModel->indexFor(rc).row());
205

206
    m_removeRunToolButton->setEnabled(m_target->runConfigurations().size() > 1);
207
    m_renameRunButton->setEnabled(rc);
dt's avatar
dt committed
208

209
    setConfigurationWidget(rc);
con's avatar
con committed
210

Tobias Hunger's avatar
Tobias Hunger committed
211
    connect(m_addRunMenu, SIGNAL(aboutToShow()),
con's avatar
con committed
212
            this, SLOT(aboutToShowAddMenu()));
213
    connect(m_runConfigurationCombo, SIGNAL(currentIndexChanged(int)),
214
            this, SLOT(currentRunConfigurationChanged(int)));
215
    connect(m_removeRunToolButton, SIGNAL(clicked(bool)),
con's avatar
con committed
216
            this, SLOT(removeRunConfiguration()));
217
    connect(m_renameRunButton, SIGNAL(clicked()),
218
            this, SLOT(renameRunConfiguration()));
Tobias Hunger's avatar
Tobias Hunger committed
219

220
221
222
223
224
225
226
227
228
229
    connect(m_target, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
            this, SLOT(updateRemoveToolButton()));
    connect(m_target, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
            this, SLOT(updateRemoveToolButton()));

    connect(m_target, SIGNAL(addedDeployConfiguration(ProjectExplorer::DeployConfiguration*)),
            this, SLOT(updateRemoveToolButton()));
    connect(m_target, SIGNAL(removedDeployConfiguration(ProjectExplorer::DeployConfiguration*)),
            this, SLOT(updateRemoveToolButton()));

Tobias Hunger's avatar
Tobias Hunger committed
230
    connect(m_target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
231
            this, SLOT(activeRunConfigurationChanged()));
con's avatar
con committed
232
233
234
235
236
237
238
239
}

RunSettingsWidget::~RunSettingsWidget()
{
}

void RunSettingsWidget::aboutToShowAddMenu()
{
Tobias Hunger's avatar
Tobias Hunger committed
240
    m_addRunMenu->clear();
241
242
243
244
    if (m_target->activeRunConfiguration()) {
        m_addRunMenu->addAction(tr("&Clone Selected"),
                                this, SLOT(cloneRunConfiguration()));
    }
hjk's avatar
hjk committed
245
    QList<IRunConfigurationFactory *> factories =
246
        ExtensionSystem::PluginManager::getObjects<IRunConfigurationFactory>();
247
248

    QList<QAction *> menuActions;
hjk's avatar
hjk committed
249
    foreach (IRunConfigurationFactory *factory, factories) {
250
251
        QList<Core::Id> ids = factory->availableCreationIds(m_target);
        foreach (Core::Id id, ids) {
252
            QAction *action = new QAction(factory->displayNameForId(id), m_addRunMenu);
253
254
255
256
257
258
259
260
261
            connect(action, &QAction::triggered, [factory, id, this]() {
                RunConfiguration *newRC = factory->create(m_target, id);
                if (!newRC)
                    return;
                QTC_CHECK(newRC->id() == id);
                m_target->addRunConfiguration(newRC);
                m_target->setActiveRunConfiguration(newRC);
                m_removeRunToolButton->setEnabled(m_target->runConfigurations().size() > 1);
            });
262
            menuActions.append(action);
con's avatar
con committed
263
264
        }
    }
265

266
267
268
    Utils::sort(menuActions, [](const QAction *l, const QAction *r) {
        return l->text() < r->text();
    });
269
270
    foreach (QAction *action, menuActions)
        m_addRunMenu->addAction(action);
con's avatar
con committed
271
272
}

273
274
275
276
277
278
279
280
void RunSettingsWidget::cloneRunConfiguration()
{
    RunConfiguration* activeRunConfiguration = m_target->activeRunConfiguration();
    IRunConfigurationFactory *factory = IRunConfigurationFactory::find(m_target,
                                                                       activeRunConfiguration);
    if (!factory)
        return;

281
282
283
284
285
    //: Title of a the cloned RunConfiguration window, text of the window
    QString name = uniqueRCName(QInputDialog::getText(this, tr("Clone Configuration"), tr("New configuration name:")));
    if (name.isEmpty())
        return;

286
287
288
289
    RunConfiguration *newRc = factory->clone(m_target, activeRunConfiguration);
    if (!newRc)
        return;

290
    newRc->setDisplayName(name);
291
292
293
294
    m_target->addRunConfiguration(newRc);
    m_target->setActiveRunConfiguration(newRc);
}

con's avatar
con committed
295
296
void RunSettingsWidget::removeRunConfiguration()
{
297
    RunConfiguration *rc = m_target->activeRunConfiguration();
298
    QMessageBox msgBox(QMessageBox::Question, tr("Remove Run Configuration?"),
299
                       tr("Do you really want to delete the run configuration <b>%1</b>?").arg(rc->displayName()),
300
301
302
                       QMessageBox::Yes|QMessageBox::No, this);
    msgBox.setDefaultButton(QMessageBox::No);
    msgBox.setEscapeButton(QMessageBox::No);
hjk's avatar
hjk committed
303
    if (msgBox.exec() == QMessageBox::No)
304
305
        return;

Tobias Hunger's avatar
Tobias Hunger committed
306
    m_target->removeRunConfiguration(rc);
307
308
    m_removeRunToolButton->setEnabled(m_target->runConfigurations().size() > 1);
    m_renameRunButton->setEnabled(m_target->activeRunConfiguration());
309
310
311
312
}

void RunSettingsWidget::activeRunConfigurationChanged()
{
313
314
315
316
    if (m_ignoreChange)
        return;
    QModelIndex actRc = m_runConfigurationsModel->indexFor(m_target->activeRunConfiguration());
    m_ignoreChange = true;
317
    m_runConfigurationCombo->setCurrentIndex(actRc.row());
318
    setConfigurationWidget(m_runConfigurationsModel->runConfigurationAt(actRc.row()));
319
    m_ignoreChange = false;
320
    m_renameRunButton->setEnabled(m_target->activeRunConfiguration());
con's avatar
con committed
321
322
}

323
324
325
326
327
328
329
330
void RunSettingsWidget::renameRunConfiguration()
{
    bool ok;
    QString name = QInputDialog::getText(this, tr("Rename..."),
                                         tr("New name for run configuration <b>%1</b>:").
                                            arg(m_target->activeRunConfiguration()->displayName()),
                                         QLineEdit::Normal,
                                         m_target->activeRunConfiguration()->displayName(), &ok);
hjk's avatar
hjk committed
331
    if (!ok)
332
333
        return;

334
335
336
337
    name = uniqueRCName(name);
    if (name.isEmpty())
        return;

338
339
340
    m_target->activeRunConfiguration()->setDisplayName(name);
}

341
void RunSettingsWidget::currentRunConfigurationChanged(int index)
con's avatar
con committed
342
{
343
344
    if (m_ignoreChange)
        return;
345
346
347
348

    RunConfiguration *selectedRunConfiguration = 0;
    if (index >= 0)
        selectedRunConfiguration = m_runConfigurationsModel->runConfigurationAt(index);
349

350
    if (selectedRunConfiguration == m_runConfiguration)
351
352
        return;

353
354
355
    m_ignoreChange = true;
    m_target->setActiveRunConfiguration(selectedRunConfiguration);
    m_ignoreChange = false;
con's avatar
con committed
356
357

    // Update the run configuration configuration widget
358
    setConfigurationWidget(selectedRunConfiguration);
359
}
Tobias Hunger's avatar
Tobias Hunger committed
360
361
362

void RunSettingsWidget::currentDeployConfigurationChanged(int index)
{
363
364
    if (m_ignoreChange)
        return;
Tobias Hunger's avatar
Tobias Hunger committed
365
    if (index == -1)
366
        m_target->setActiveDeployConfiguration(0);
Tobias Hunger's avatar
Tobias Hunger committed
367
368
369
370
371
372
373
    else
        m_target->setActiveDeployConfiguration(m_deployConfigurationModel->deployConfigurationAt(index));
}

void RunSettingsWidget::aboutToShowDeployMenu()
{
    m_addDeployMenu->clear();
374
375
    QList<DeployConfigurationFactory *> factories = DeployConfigurationFactory::find(m_target);
    if (factories.isEmpty())
Tobias Hunger's avatar
Tobias Hunger committed
376
        return;
377
378
379
380
381
382
383

    foreach (DeployConfigurationFactory *factory, factories) {
        QList<Core::Id> ids = factory->availableCreationIds(m_target);
        foreach (Core::Id id, ids) {
            QAction *action = m_addDeployMenu->addAction(factory->displayNameForId(id));
            DeployFactoryAndId data = { factory, id };
            action->setData(QVariant::fromValue(data));
384
385
386
387
388
389
390
391
392
393
394
            connect(action, &QAction::triggered, [factory, id, this]() {
                if (!factory->canCreate(m_target, id))
                    return;
                DeployConfiguration *newDc = factory->create(m_target, id);
                if (!newDc)
                    return;
                QTC_CHECK(!newDc || newDc->id() == id);
                m_target->addDeployConfiguration(newDc);
                m_target->setActiveDeployConfiguration(newDc);
                m_removeDeployToolButton->setEnabled(m_target->deployConfigurations().size() > 1);
            });
395
        }
Tobias Hunger's avatar
Tobias Hunger committed
396
397
398
399
400
401
    }
}

void RunSettingsWidget::removeDeployConfiguration()
{
    DeployConfiguration *dc = m_target->activeDeployConfiguration();
hjk's avatar
hjk committed
402
    if (BuildManager::isBuilding(dc)) {
Daniel Teske's avatar
Daniel Teske committed
403
404
405
406
407
408
409
410
411
412
        QMessageBox box;
        QPushButton *closeAnyway = box.addButton(tr("Cancel Build && Remove Deploy Configuration"), QMessageBox::AcceptRole);
        QPushButton *cancelClose = box.addButton(tr("Do Not Remove"), QMessageBox::RejectRole);
        box.setDefaultButton(cancelClose);
        box.setWindowTitle(tr("Remove Deploy Configuration %1?").arg(dc->displayName()));
        box.setText(tr("The deploy configuration <b>%1</b> is currently being built.").arg(dc->displayName()));
        box.setInformativeText(tr("Do you want to cancel the build process and remove the Deploy Configuration anyway?"));
        box.exec();
        if (box.clickedButton() != closeAnyway)
            return;
hjk's avatar
hjk committed
413
        BuildManager::cancel();
Daniel Teske's avatar
Daniel Teske committed
414
415
416
417
418
419
420
421
422
    } else {
        QMessageBox msgBox(QMessageBox::Question, tr("Remove Deploy Configuration?"),
                           tr("Do you really want to delete deploy configuration <b>%1</b>?").arg(dc->displayName()),
                           QMessageBox::Yes|QMessageBox::No, this);
        msgBox.setDefaultButton(QMessageBox::No);
        msgBox.setEscapeButton(QMessageBox::No);
        if (msgBox.exec() == QMessageBox::No)
            return;
    }
423

Tobias Hunger's avatar
Tobias Hunger committed
424
    m_target->removeDeployConfiguration(dc);
Daniel Teske's avatar
Daniel Teske committed
425

426
    m_removeDeployToolButton->setEnabled(m_target->deployConfigurations().size() > 1);
Tobias Hunger's avatar
Tobias Hunger committed
427
428
429
430
431
432
433
}

void RunSettingsWidget::activeDeployConfigurationChanged()
{
    updateDeployConfiguration(m_target->activeDeployConfiguration());
}

434
435
436
437
438
439
440
441
void RunSettingsWidget::renameDeployConfiguration()
{
    bool ok;
    QString name = QInputDialog::getText(this, tr("Rename..."),
                                         tr("New name for deploy configuration <b>%1</b>:").
                                            arg(m_target->activeDeployConfiguration()->displayName()),
                                         QLineEdit::Normal,
                                         m_target->activeDeployConfiguration()->displayName(), &ok);
hjk's avatar
hjk committed
442
    if (!ok)
443
444
        return;

445
446
447
    name = uniqueDCName(name);
    if (name.isEmpty())
        return;
448
449
450
    m_target->activeDeployConfiguration()->setDisplayName(name);
}

451
452
453
454
455
456
void RunSettingsWidget::updateRemoveToolButton()
{
    m_removeDeployToolButton->setEnabled(m_target->deployConfigurations().count() > 1);
    m_removeRunToolButton->setEnabled(m_target->runConfigurations().size() > 1);
}

Tobias Hunger's avatar
Tobias Hunger committed
457
458
459
460
461
462
463
void RunSettingsWidget::updateDeployConfiguration(DeployConfiguration *dc)
{
    delete m_deployConfigurationWidget;
    m_deployConfigurationWidget = 0;
    delete m_deploySteps;
    m_deploySteps = 0;

464
    m_ignoreChange = true;
465
    m_deployConfigurationCombo->setCurrentIndex(-1);
466
    m_ignoreChange = false;
Tobias Hunger's avatar
Tobias Hunger committed
467

468
469
    m_renameDeployButton->setEnabled(dc);

Tobias Hunger's avatar
Tobias Hunger committed
470
471
472
473
    if (!dc)
        return;

    QModelIndex actDc = m_deployConfigurationModel->indexFor(dc);
474
    m_ignoreChange = true;
475
    m_deployConfigurationCombo->setCurrentIndex(actDc.row());
476
    m_ignoreChange = false;
Tobias Hunger's avatar
Tobias Hunger committed
477

478
    m_deployConfigurationWidget = dc->createConfigWidget();
479
    if (m_deployConfigurationWidget)
Tobias Hunger's avatar
Tobias Hunger committed
480
481
482
483
484
485
        m_deployLayout->addWidget(m_deployConfigurationWidget);

    m_deploySteps = new BuildStepListWidget;
    m_deploySteps->init(dc->stepList());
    m_deployLayout->addWidget(m_deploySteps);
}
486

487
488
void RunSettingsWidget::setConfigurationWidget(RunConfiguration *rc)
{
489
490
491
    if (rc == m_runConfiguration)
        return;

492
493
    delete m_runConfigurationWidget;
    m_runConfigurationWidget = 0;
494
    removeSubWidgets();
495
496
    if (!rc)
        return;
497
    m_runConfigurationWidget = rc->createConfigurationWidget();
498
    m_runConfiguration = rc;
499
500
    if (m_runConfigurationWidget)
        m_runLayout->addWidget(m_runConfigurationWidget);
501
502

    addRunControlWidgets();
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
QString RunSettingsWidget::uniqueDCName(const QString &name)
{
    QString result = name.trimmed();
    if (!result.isEmpty()) {
        QStringList dcNames;
        foreach (DeployConfiguration *dc, m_target->deployConfigurations()) {
            if (dc == m_target->activeDeployConfiguration())
                continue;
            dcNames.append(dc->displayName());
        }
        result = Project::makeUnique(result, dcNames);
    }
    return result;
}

QString RunSettingsWidget::uniqueRCName(const QString &name)
{
    QString result = name.trimmed();
    if (!result.isEmpty()) {
        QStringList rcNames;
        foreach (RunConfiguration *rc, m_target->runConfigurations()) {
            if (rc == m_target->activeRunConfiguration())
                continue;
            rcNames.append(rc->displayName());
        }
        result = Project::makeUnique(result, rcNames);
    }
    return result;
}
534
535
536

void RunSettingsWidget::addRunControlWidgets()
{
537
    foreach (IRunConfigurationAspect *aspect, m_runConfiguration->extraAspects()) {
538
        ProjectExplorer::RunConfigWidget *rcw = aspect->createConfigurationWidget();
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
        if (rcw)
            addSubWidget(rcw);
    }
}

void RunSettingsWidget::addSubWidget(RunConfigWidget *widget)
{
    widget->setContentsMargins(0, 10, 0, 0);

    QLabel *label = new QLabel(this);
    label->setText(widget->displayName());
    connect(widget, SIGNAL(displayNameChanged(QString)),
            label, SLOT(setText(QString)));
    QFont f = label->font();
    f.setBold(true);
    f.setPointSizeF(f.pointSizeF() * 1.2);
    label->setFont(f);

    label->setContentsMargins(0, 10, 0, 0);

559
    QGridLayout *l = m_gridLayout;
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
    l->addWidget(label, l->rowCount(), 0, 1, -1);
    l->addWidget(widget, l->rowCount(), 0, 1, -1);

    m_subWidgets.append(qMakePair(widget, label));
}

void RunSettingsWidget::removeSubWidgets()
{
    // foreach does not like commas in types, it's only a macro after all
    foreach (const RunConfigItem &item, m_subWidgets) {
        delete item.first;
        delete item.second;
    }
    m_subWidgets.clear();
}