buildsettingspropertiespage.cpp 12 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
33
#include "buildsettingspropertiespage.h"
#include "buildstep.h"
#include "buildstepspage.h"
#include "project.h"
Tobias Hunger's avatar
Tobias Hunger committed
34
#include "target.h"
35
#include "buildconfiguration.h"
con's avatar
con committed
36

37
#include <coreplugin/coreconstants.h>
con's avatar
con committed
38
#include <extensionsystem/pluginmanager.h>
39
#include <utils/qtcassert.h>
con's avatar
con committed
40

41
42
#include <QtCore/QMargins>
#include <QtCore/QTimer>
Friedemann Kleint's avatar
Friedemann Kleint committed
43
#include <QtCore/QCoreApplication>
44
#include <QtGui/QComboBox>
con's avatar
con committed
45
46
#include <QtGui/QInputDialog>
#include <QtGui/QLabel>
47
#include <QtGui/QMenu>
48
49
#include <QtGui/QPushButton>
#include <QtGui/QVBoxLayout>
con's avatar
con committed
50
51
52
53
54

using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;

///
55
// BuildSettingsPanelFactory
con's avatar
con committed
56
57
///

Tobias Hunger's avatar
Tobias Hunger committed
58
59
60
61
62
QString BuildSettingsPanelFactory::id() const
{
    return QLatin1String(BUILDSETTINGS_PANEL_ID);
}

con's avatar
con committed
63
64
QString BuildSettingsPanelFactory::displayName() const
{
Friedemann Kleint's avatar
Friedemann Kleint committed
65
    return QCoreApplication::translate("BuildSettingsPanelFactory", "Build Settings");
con's avatar
con committed
66
67
}

Tobias Hunger's avatar
Tobias Hunger committed
68
69
70
bool BuildSettingsPanelFactory::supports(Target *target)
{
    return target->buildConfigurationFactory();
con's avatar
con committed
71
72
}

Tobias Hunger's avatar
Tobias Hunger committed
73
74
75
76
77
78
IPropertiesPanel *BuildSettingsPanelFactory::createPanel(Target *target)
{
    return new BuildSettingsPanel(target);
}


con's avatar
con committed
79
///
80
// BuildSettingsPanel
con's avatar
con committed
81
82
///

Tobias Hunger's avatar
Tobias Hunger committed
83
84
BuildSettingsPanel::BuildSettingsPanel(Target *target) :
    m_widget(new BuildSettingsWidget(target)),
con's avatar
con committed
85
    m_icon(":/projectexplorer/images/BuildSettings.png")
con's avatar
con committed
86
87
88
89
90
{
}

BuildSettingsPanel::~BuildSettingsPanel()
{
91
    delete m_widget;
con's avatar
con committed
92
93
}

94
QString BuildSettingsPanel::displayName() const
con's avatar
con committed
95
{
Friedemann Kleint's avatar
Friedemann Kleint committed
96
    return QCoreApplication::translate("BuildSettingsPanel", "Build Settings");
con's avatar
con committed
97
98
}

99
QWidget *BuildSettingsPanel::widget() const
con's avatar
con committed
100
101
102
103
{
    return m_widget;
}

104
105
106
107
108
QIcon BuildSettingsPanel::icon() const
{
    return m_icon;
}

dt's avatar
dt committed
109
///
110
// BuildSettingsWidget
dt's avatar
dt committed
111
112
///

113
BuildSettingsWidget::~BuildSettingsWidget()
dt's avatar
dt committed
114
115
116
117
{
    clear();
}

Tobias Hunger's avatar
Tobias Hunger committed
118
119
BuildSettingsWidget::BuildSettingsWidget(Target *target) :
    m_target(target),
120
121
    m_buildConfiguration(0),
    m_leftMargin(0)
dt's avatar
dt committed
122
{
Tobias Hunger's avatar
Tobias Hunger committed
123
124
    Q_ASSERT(m_target);
    setupUi();
dt's avatar
dt committed
125
126
}

127
void BuildSettingsWidget::setupUi()
dt's avatar
dt committed
128
{
Tobias Hunger's avatar
Tobias Hunger committed
129
    m_leftMargin = Constants::PANEL_LEFT_MARGIN;
dt's avatar
dt committed
130
    QVBoxLayout *vbox = new QVBoxLayout(this);
131
    vbox->setContentsMargins(0, 0, 0, 0);
132

Tobias Hunger's avatar
Tobias Hunger committed
133
134
135
136
137
138
139
140
141
142
143
144
    if (!m_target->buildConfigurationFactory()) {
        QLabel * noSettingsLabel(new QLabel(this));
        noSettingsLabel->setText(tr("No Build Settings available"));
        {
            QFont f(noSettingsLabel->font());
            f.setPointSizeF(f.pointSizeF() * 1.2);
            noSettingsLabel->setFont(f);
        }
        vbox->addWidget(noSettingsLabel);
        return;
    }

145
146
    { // Edit Build Configuration row
        QHBoxLayout *hbox = new QHBoxLayout();
147
        hbox->setContentsMargins(m_leftMargin, 0, 0, 0);
148
149
150
151
152
153
154
155
156
        hbox->addWidget(new QLabel(tr("Edit Build Configuration:"), this));
        m_buildConfigurationComboBox = new QComboBox(this);
        m_buildConfigurationComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
        hbox->addWidget(m_buildConfigurationComboBox);

        m_addButton = new QPushButton(this);
        m_addButton->setText(tr("Add"));
        m_addButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        hbox->addWidget(m_addButton);
157
158
        m_addButtonMenu = new QMenu(this);
        m_addButton->setMenu(m_addButtonMenu);
159
160
161
162
163

        m_removeButton = new QPushButton(this);
        m_removeButton->setText(tr("Remove"));
        m_removeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        hbox->addWidget(m_removeButton);
164

165
166
167
168
        hbox->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
        vbox->addLayout(hbox);
    }

Tobias Hunger's avatar
Tobias Hunger committed
169
    m_buildConfiguration = m_target->activeBuildConfiguration();
dt's avatar
dt committed
170

171
172
173
    updateAddButtonMenu();
    updateBuildSettings();

dt's avatar
dt committed
174
175
    connect(m_buildConfigurationComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(currentIndexChanged(int)));
con's avatar
con committed
176

dt's avatar
dt committed
177
    connect(m_removeButton, SIGNAL(clicked()),
con's avatar
con committed
178
            this, SLOT(deleteConfiguration()));
dt's avatar
dt committed
179

Tobias Hunger's avatar
Tobias Hunger committed
180
    connect(m_target, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
181
            this, SLOT(updateActiveConfiguration()));
Tobias Hunger's avatar
Tobias Hunger committed
182
183

    connect(m_target, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
184
185
            this, SLOT(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));

Tobias Hunger's avatar
Tobias Hunger committed
186
    connect(m_target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
187
188
            this, SLOT(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));

Tobias Hunger's avatar
Tobias Hunger committed
189
    foreach (BuildConfiguration *bc, m_target->buildConfigurations()) {
190
191
192
193
        connect(bc, SIGNAL(displayNameChanged()),
                this, SLOT(buildConfigurationDisplayNameChanged()));
    }

Tobias Hunger's avatar
Tobias Hunger committed
194
195
196
    if (m_target->buildConfigurationFactory())
        connect(m_target->buildConfigurationFactory(), SIGNAL(availableCreationIdsChanged()),
                SLOT(updateAddButtonMenu()));
con's avatar
con committed
197
198
}

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
void BuildSettingsWidget::addedBuildConfiguration(BuildConfiguration *bc)
{
    connect(bc, SIGNAL(displayNameChanged()),
            this, SLOT(buildConfigurationDisplayNameChanged()));
}

void BuildSettingsWidget::removedBuildConfiguration(BuildConfiguration *bc)
{
    disconnect(bc, SIGNAL(displayNameChanged()),
               this, SLOT(buildConfigurationDisplayNameChanged()));
}

void BuildSettingsWidget::buildConfigurationDisplayNameChanged()
{
    for (int i = 0; i < m_buildConfigurationComboBox->count(); ++i) {
        BuildConfiguration *bc = m_buildConfigurationComboBox->itemData(i).value<BuildConfiguration *>();
215
        m_buildConfigurationComboBox->setItemText(i, bc->displayName());
216
217
218
    }
}

219
void BuildSettingsWidget::addSubWidget(const QString &name, BuildConfigWidget *widget)
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
{
    widget->setContentsMargins(m_leftMargin, 10, 0, 0);

    QLabel *label = new QLabel(this);
    label->setText(name);
    QFont f = label->font();
    f.setBold(true);
    f.setPointSizeF(f.pointSizeF() * 1.2);
    label->setFont(f);

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

    layout()->addWidget(label);
    layout()->addWidget(widget);

    m_labels.append(label);
    m_subWidgets.append(widget);
}

void BuildSettingsWidget::clear()
{
    qDeleteAll(m_subWidgets);
    m_subWidgets.clear();
    qDeleteAll(m_labels);
    m_labels.clear();
}

247
QList<BuildConfigWidget *> BuildSettingsWidget::subWidgets() const
248
249
250
251
{
    return m_subWidgets;
}

con's avatar
con committed
252
void BuildSettingsWidget::updateAddButtonMenu()
253
{
con's avatar
con committed
254
    m_addButtonMenu->clear();
Tobias Hunger's avatar
Tobias Hunger committed
255
256
257
258
259
260
    if (m_target &&
        m_target->activeBuildConfiguration()) {
        m_addButtonMenu->addAction(tr("&Clone Selected"),
                                   this, SLOT(cloneConfiguration()));
    }
    IBuildConfigurationFactory *factory = m_target->buildConfigurationFactory();
261
    if (factory) {
Tobias Hunger's avatar
Tobias Hunger committed
262
        foreach (const QString &id, factory->availableCreationIds(m_target)) {
263
264
            QAction *action = m_addButtonMenu->addAction(factory->displayNameForId(id), this, SLOT(createConfiguration()));
            action->setData(id);
265
266
267
268
        }
    }
}

con's avatar
con committed
269
270
271
void BuildSettingsWidget::updateBuildSettings()
{
    // Delete old tree items
272
    bool blocked = m_buildConfigurationComboBox->blockSignals(true);
dt's avatar
dt committed
273
    m_buildConfigurationComboBox->clear();
274
    clear();
con's avatar
con committed
275

dt's avatar
dt committed
276
    // update buttons
Tobias Hunger's avatar
Tobias Hunger committed
277
    m_removeButton->setEnabled(m_target->buildConfigurations().size() > 1);
con's avatar
con committed
278
279

    // Add pages
Tobias Hunger's avatar
Tobias Hunger committed
280
    BuildConfigWidget *generalConfigWidget = m_target->project()->createConfigWidget();
281
    addSubWidget(generalConfigWidget->displayName(), generalConfigWidget);
dt's avatar
dt committed
282

283
284
    addSubWidget(tr("Build Steps"), new BuildStepsPage(m_target, Build));
    addSubWidget(tr("Clean Steps"), new BuildStepsPage(m_target, Clean));
con's avatar
con committed
285

Tobias Hunger's avatar
Tobias Hunger committed
286
    QList<BuildConfigWidget *> subConfigWidgets = m_target->project()->subConfigWidgets();
dt's avatar
dt committed
287
    foreach (BuildConfigWidget *subConfigWidget, subConfigWidgets)
288
        addSubWidget(subConfigWidget->displayName(), subConfigWidget);
con's avatar
con committed
289
290

    // Add tree items
Tobias Hunger's avatar
Tobias Hunger committed
291
    foreach (BuildConfiguration *bc, m_target->buildConfigurations()) {
292
        m_buildConfigurationComboBox->addItem(bc->displayName(), QVariant::fromValue<BuildConfiguration *>(bc));
dt's avatar
dt committed
293
        if (bc == m_buildConfiguration)
dt's avatar
dt committed
294
            m_buildConfigurationComboBox->setCurrentIndex(m_buildConfigurationComboBox->count() - 1);
con's avatar
con committed
295
296
    }

297
298
    foreach (BuildConfigWidget *widget, subWidgets())
        widget->init(m_buildConfiguration);
con's avatar
con committed
299

300
    m_buildConfigurationComboBox->blockSignals(blocked);
con's avatar
con committed
301
302
}

dt's avatar
dt committed
303
void BuildSettingsWidget::currentIndexChanged(int index)
con's avatar
con committed
304
{
305
306
    BuildConfiguration *buildConfiguration = m_buildConfigurationComboBox->itemData(index).value<BuildConfiguration *>();
    m_target->setActiveBuildConfiguration(buildConfiguration);
con's avatar
con committed
307
308
}

309
void BuildSettingsWidget::updateActiveConfiguration()
con's avatar
con committed
310
{
311
    if (!m_buildConfiguration || m_buildConfiguration == m_target->activeBuildConfiguration())
Tobias Hunger's avatar
Tobias Hunger committed
312
313
        return;

314
315
    m_buildConfiguration = m_target->activeBuildConfiguration();

dt's avatar
dt committed
316
    for (int i = 0; i < m_buildConfigurationComboBox->count(); ++i) {
dt's avatar
dt committed
317
        if (m_buildConfigurationComboBox->itemData(i).value<BuildConfiguration *>() == m_buildConfiguration) {
dt's avatar
dt committed
318
319
320
321
            m_buildConfigurationComboBox->setCurrentIndex(i);
            break;
        }
    }
Tobias Hunger's avatar
Tobias Hunger committed
322

323
    foreach (QWidget *widget, subWidgets()) {
dt's avatar
dt committed
324
        if (BuildConfigWidget *buildStepWidget = qobject_cast<BuildConfigWidget*>(widget)) {
dt's avatar
dt committed
325
            buildStepWidget->init(m_buildConfiguration);
con's avatar
con committed
326
327
        }
    }
328
329
}

con's avatar
con committed
330
331
void BuildSettingsWidget::createConfiguration()
{
Tobias Hunger's avatar
Tobias Hunger committed
332
333
334
    if (!m_target->buildConfigurationFactory())
        return;

335
    QAction *action = qobject_cast<QAction *>(sender());
Tobias Hunger's avatar
Tobias Hunger committed
336
337
    const QString &id = action->data().toString();
    BuildConfiguration *bc = m_target->buildConfigurationFactory()->create(m_target, id);
dt's avatar
dt committed
338
339
    if (bc) {
        m_buildConfiguration = bc;
340
341
        updateBuildSettings();
    }
con's avatar
con committed
342
343
344
345
}

void BuildSettingsWidget::cloneConfiguration()
{
346
    cloneConfiguration(m_buildConfiguration);
con's avatar
con committed
347
348
349
350
}

void BuildSettingsWidget::deleteConfiguration()
{
351
    deleteConfiguration(m_buildConfiguration);
con's avatar
con committed
352
353
}

dt's avatar
dt committed
354
void BuildSettingsWidget::cloneConfiguration(BuildConfiguration *sourceConfiguration)
con's avatar
con committed
355
{
Tobias Hunger's avatar
Tobias Hunger committed
356
357
    if (!sourceConfiguration ||
        !m_target->buildConfigurationFactory())
con's avatar
con committed
358
359
        return;

360
    QString newDisplayName(QInputDialog::getText(this, tr("Clone configuration"), tr("New Configuration Name:")));
dt's avatar
dt committed
361
    if (newDisplayName.isEmpty())
con's avatar
con committed
362
363
        return;

364
    QStringList buildConfigurationDisplayNames;
Tobias Hunger's avatar
Tobias Hunger committed
365
    foreach(BuildConfiguration *bc, m_target->buildConfigurations())
366
367
368
        buildConfigurationDisplayNames << bc->displayName();
    newDisplayName = Project::makeUnique(newDisplayName, buildConfigurationDisplayNames);

Tobias Hunger's avatar
Tobias Hunger committed
369
370
    BuildConfiguration * bc(m_target->buildConfigurationFactory()->clone(m_target, sourceConfiguration));
    if (!bc)
371
        return;
Tobias Hunger's avatar
Tobias Hunger committed
372
373

    m_buildConfiguration = bc;
374
    m_buildConfiguration->setDisplayName(newDisplayName);
Tobias Hunger's avatar
Tobias Hunger committed
375
    m_target->addBuildConfiguration(m_buildConfiguration);
dt's avatar
dt committed
376

con's avatar
con committed
377
378
379
    updateBuildSettings();
}

dt's avatar
dt committed
380
void BuildSettingsWidget::deleteConfiguration(BuildConfiguration *deleteConfiguration)
con's avatar
con committed
381
{
Tobias Hunger's avatar
Tobias Hunger committed
382
383
    if (!deleteConfiguration ||
        m_target->buildConfigurations().size() <= 1)
con's avatar
con committed
384
385
        return;

Tobias Hunger's avatar
Tobias Hunger committed
386
    m_target->removeBuildConfiguration(deleteConfiguration);
con's avatar
con committed
387
388
389

    updateBuildSettings();
}