2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "buildstepspage.h"
|
2009-10-27 14:16:28 +01:00
|
|
|
#include "buildconfiguration.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-12 15:06:43 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
#include <QtCore/QSignalMapper>
|
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
#include <QtGui/QLabel>
|
|
|
|
|
#include <QtGui/QPushButton>
|
2009-09-29 11:39:55 +02:00
|
|
|
#include <QtGui/QMenu>
|
2009-09-30 10:42:20 +02:00
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
|
#include <QtGui/QHBoxLayout>
|
2009-10-01 14:24:44 +02:00
|
|
|
#include <QtGui/QToolButton>
|
2009-08-06 15:31:32 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
|
2009-06-22 16:11:45 +02:00
|
|
|
BuildStepsPage::BuildStepsPage(Project *project, bool clean) :
|
2009-08-06 15:31:32 +02:00
|
|
|
BuildConfigWidget(),
|
2009-11-30 16:44:22 +01:00
|
|
|
m_clean(clean),
|
|
|
|
|
m_addButton(0),
|
|
|
|
|
m_leftMargin(-1)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-30 16:44:22 +01:00
|
|
|
Q_UNUSED(project);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuildStepsPage::~BuildStepsPage()
|
|
|
|
|
{
|
2009-08-06 15:31:32 +02:00
|
|
|
foreach(BuildStepsWidgetStruct s, m_buildSteps) {
|
|
|
|
|
delete s.widget;
|
2009-10-01 14:24:44 +02:00
|
|
|
delete s.detailsWidget;
|
2009-08-06 15:31:32 +02:00
|
|
|
}
|
|
|
|
|
m_buildSteps.clear();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
void BuildStepsPage::updateSummary()
|
|
|
|
|
{
|
|
|
|
|
BuildStepConfigWidget *widget = qobject_cast<BuildStepConfigWidget *>(sender());
|
2009-10-27 14:16:28 +01:00
|
|
|
if (widget) {
|
|
|
|
|
foreach(const BuildStepsWidgetStruct &s, m_buildSteps) {
|
|
|
|
|
if (s.widget == widget) {
|
2009-10-01 14:24:44 +02:00
|
|
|
s.detailsWidget->setSummaryText(widget->summaryText());
|
2009-10-27 14:16:28 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BuildStepsPage::displayName() const
|
|
|
|
|
{
|
2009-06-22 16:11:45 +02:00
|
|
|
return m_clean ? tr("Clean Steps") : tr("Build Steps");
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-24 15:36:31 +01:00
|
|
|
void BuildStepsPage::init(BuildConfiguration *bc)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-30 16:44:22 +01:00
|
|
|
QTC_ASSERT(bc, return);
|
|
|
|
|
|
|
|
|
|
setupUi();
|
|
|
|
|
|
2009-10-27 14:16:28 +01:00
|
|
|
foreach(BuildStepsWidgetStruct s, m_buildSteps) {
|
|
|
|
|
delete s.widget;
|
|
|
|
|
delete s.detailsWidget;
|
|
|
|
|
}
|
|
|
|
|
m_buildSteps.clear();
|
|
|
|
|
|
2009-11-24 15:36:31 +01:00
|
|
|
m_configuration = bc;
|
2009-10-27 14:16:28 +01:00
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
const QList<BuildStep *> &steps = m_clean ? m_configuration->cleanSteps() : m_configuration->buildSteps();
|
2009-10-27 14:16:28 +01:00
|
|
|
int i = 0;
|
|
|
|
|
foreach (BuildStep *bs, steps) {
|
|
|
|
|
addBuildStepWidget(i, bs);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_noStepsLabel->setVisible(steps.isEmpty());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// make sure widget is updated
|
2009-08-06 15:31:32 +02:00
|
|
|
foreach(BuildStepsWidgetStruct s, m_buildSteps) {
|
2009-10-27 14:16:28 +01:00
|
|
|
s.widget->init();
|
2009-10-01 14:24:44 +02:00
|
|
|
s.detailsWidget->setSummaryText(s.widget->summaryText());
|
2008-12-02 17:59:38 +01:00
|
|
|
}
|
2009-10-27 14:16:28 +01:00
|
|
|
updateBuildStepButtonsState();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuildStepsPage::updateAddBuildStepMenu()
|
|
|
|
|
{
|
|
|
|
|
QMap<QString, QPair<QString, IBuildStepFactory *> > map;
|
|
|
|
|
//Build up a list of possible steps and save map the display names to the (internal) name and factories.
|
|
|
|
|
QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IBuildStepFactory>();
|
2009-11-30 16:44:22 +01:00
|
|
|
foreach (IBuildStepFactory *factory, factories) {
|
2009-11-25 20:00:28 +01:00
|
|
|
QStringList names = factory->canCreateForBuildConfiguration(m_configuration);
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (const QString &name, names) {
|
|
|
|
|
map.insert(factory->displayNameForName(name), QPair<QString, IBuildStepFactory *>(name, factory));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ask the user which one to add
|
2009-08-06 15:31:32 +02:00
|
|
|
QMenu *menu = m_addButton->menu();
|
2008-12-02 12:01:29 +01:00
|
|
|
m_addBuildStepHash.clear();
|
|
|
|
|
menu->clear();
|
2008-12-09 11:07:24 +01:00
|
|
|
if (!map.isEmpty()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QStringList names;
|
|
|
|
|
QMap<QString, QPair<QString, IBuildStepFactory *> >::const_iterator it, end;
|
|
|
|
|
end = map.constEnd();
|
2008-12-09 11:07:24 +01:00
|
|
|
for (it = map.constBegin(); it != end; ++it) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QAction *action = menu->addAction(it.key());
|
|
|
|
|
connect(action, SIGNAL(triggered()),
|
|
|
|
|
this, SLOT(addBuildStep()));
|
|
|
|
|
m_addBuildStepHash.insert(action, it.value());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
void BuildStepsPage::addBuildStepWidget(int pos, BuildStep *step)
|
|
|
|
|
{
|
|
|
|
|
// create everything
|
|
|
|
|
BuildStepsWidgetStruct s;
|
|
|
|
|
s.widget = step->createConfigWidget();
|
2009-10-01 14:24:44 +02:00
|
|
|
s.detailsWidget = new Utils::DetailsWidget(this);
|
|
|
|
|
s.detailsWidget->setSummaryText(s.widget->summaryText());
|
|
|
|
|
s.detailsWidget->setWidget(s.widget);
|
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
s.upButton = new QToolButton(this);
|
|
|
|
|
s.upButton->setArrowType(Qt::UpArrow);
|
2009-10-05 15:27:55 +02:00
|
|
|
s.upButton->setMaximumHeight(22);
|
|
|
|
|
s.upButton->setMaximumWidth(22);
|
2009-08-06 15:31:32 +02:00
|
|
|
s.downButton = new QToolButton(this);
|
|
|
|
|
s.downButton->setArrowType(Qt::DownArrow);
|
2009-10-05 15:27:55 +02:00
|
|
|
s.downButton->setMaximumHeight(22);
|
|
|
|
|
s.downButton->setMaximumWidth(22);
|
2009-08-20 20:04:58 +02:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
s.upButton->setIconSize(QSize(10, 10));
|
|
|
|
|
s.downButton->setIconSize(QSize(10, 10));
|
|
|
|
|
#endif
|
2009-11-30 16:44:22 +01:00
|
|
|
s.removeButton = new QPushButton(this);
|
|
|
|
|
s.removeButton->setText(QChar('X'));
|
|
|
|
|
s.removeButton->setMaximumHeight(22);
|
|
|
|
|
s.removeButton->setMaximumWidth(22);
|
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
// layout
|
2009-10-01 14:24:44 +02:00
|
|
|
QWidget *toolWidget = new QWidget(s.detailsWidget);
|
|
|
|
|
toolWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2009-11-30 16:44:22 +01:00
|
|
|
QHBoxLayout *hbox = new QHBoxLayout();
|
|
|
|
|
toolWidget->setLayout(hbox);
|
|
|
|
|
hbox->setMargin(0);
|
|
|
|
|
hbox->setSpacing(0);
|
|
|
|
|
hbox->addWidget(s.upButton);
|
|
|
|
|
hbox->addWidget(s.downButton);
|
|
|
|
|
hbox->addWidget(s.removeButton);
|
|
|
|
|
|
2009-10-01 14:24:44 +02:00
|
|
|
s.detailsWidget->setToolWidget(toolWidget);
|
2009-08-06 15:31:32 +02:00
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
const int leftMargin(qMax(m_leftMargin - toolWidget->width(), 0));
|
|
|
|
|
s.detailsWidget->setContentsMargins(leftMargin, 0, 0, 1);
|
|
|
|
|
|
2009-10-27 14:16:28 +01:00
|
|
|
m_buildSteps.insert(pos, s);
|
2009-11-30 16:44:22 +01:00
|
|
|
|
2009-10-27 14:16:28 +01:00
|
|
|
m_vbox->insertWidget(pos, s.detailsWidget);
|
2009-08-06 15:31:32 +02:00
|
|
|
|
|
|
|
|
connect(s.widget, SIGNAL(updateSummary()),
|
|
|
|
|
this, SLOT(updateSummary()));
|
|
|
|
|
|
|
|
|
|
connect(s.upButton, SIGNAL(clicked()),
|
2009-11-30 16:44:22 +01:00
|
|
|
m_upMapper, SLOT(map()));
|
2009-08-06 15:31:32 +02:00
|
|
|
connect(s.downButton, SIGNAL(clicked()),
|
2009-11-30 16:44:22 +01:00
|
|
|
m_downMapper, SLOT(map()));
|
|
|
|
|
connect(s.removeButton, SIGNAL(clicked()),
|
|
|
|
|
m_removeMapper, SLOT(map()));
|
2009-08-06 15:31:32 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void BuildStepsPage::addBuildStep()
|
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
if (QAction *action = qobject_cast<QAction *>(sender())) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QPair<QString, IBuildStepFactory *> pair = m_addBuildStepHash.value(action);
|
2009-11-30 16:44:22 +01:00
|
|
|
BuildStep *newStep = pair.second->create(m_configuration, pair.first);
|
|
|
|
|
int pos = m_clean ? m_configuration->cleanSteps().count() : m_configuration->buildSteps().count();
|
|
|
|
|
m_clean ? m_configuration->insertCleanStep(pos, newStep) : m_configuration->insertBuildStep(pos, newStep);
|
2009-08-06 15:31:32 +02:00
|
|
|
|
|
|
|
|
addBuildStepWidget(pos, newStep);
|
|
|
|
|
const BuildStepsWidgetStruct s = m_buildSteps.at(pos);
|
2009-10-27 14:16:28 +01:00
|
|
|
s.widget->init();
|
2009-10-01 14:24:44 +02:00
|
|
|
s.detailsWidget->setSummaryText(s.widget->summaryText());
|
2009-11-30 16:44:22 +01:00
|
|
|
s.detailsWidget->setExpanded(true);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-11-30 16:44:22 +01:00
|
|
|
|
2009-08-11 18:09:52 +02:00
|
|
|
updateBuildStepButtonsState();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
void BuildStepsPage::stepMoveUp(int pos)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-30 16:44:22 +01:00
|
|
|
m_clean ? m_configuration->moveCleanStepUp(pos) : m_configuration->moveBuildStepUp(pos);
|
|
|
|
|
|
|
|
|
|
m_vbox->insertWidget(pos - 1, m_buildSteps.at(pos).detailsWidget);
|
|
|
|
|
|
|
|
|
|
m_buildSteps.swap(pos - 1, pos);
|
2009-08-06 15:31:32 +02:00
|
|
|
|
2009-08-11 18:09:52 +02:00
|
|
|
updateBuildStepButtonsState();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
void BuildStepsPage::stepMoveDown(int pos)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-30 16:44:22 +01:00
|
|
|
stepMoveUp(pos + 1);
|
|
|
|
|
}
|
2009-08-06 15:31:32 +02:00
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
void BuildStepsPage::stepRemove(int pos)
|
|
|
|
|
{
|
|
|
|
|
BuildStepsWidgetStruct s = m_buildSteps.at(pos);
|
|
|
|
|
delete s.widget;
|
|
|
|
|
delete s.detailsWidget;
|
|
|
|
|
m_buildSteps.removeAt(pos);
|
|
|
|
|
m_clean ? m_configuration->removeCleanStep(pos) : m_configuration->removeBuildStep(pos);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
updateBuildStepButtonsState();
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
void BuildStepsPage::setupUi()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-30 16:44:22 +01:00
|
|
|
if (0 != m_addButton)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
2009-08-06 15:31:32 +02:00
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
QMargins margins(contentsMargins());
|
|
|
|
|
m_leftMargin = margins.left();
|
|
|
|
|
margins.setLeft(0);
|
|
|
|
|
setContentsMargins(margins);
|
|
|
|
|
|
|
|
|
|
m_upMapper = new QSignalMapper(this);
|
|
|
|
|
connect(m_upMapper, SIGNAL(mapped(int)),
|
|
|
|
|
this, SLOT(stepMoveUp(int)));
|
|
|
|
|
m_downMapper = new QSignalMapper(this);
|
|
|
|
|
connect(m_downMapper, SIGNAL(mapped(int)),
|
|
|
|
|
this, SLOT(stepMoveDown(int)));
|
|
|
|
|
m_removeMapper = new QSignalMapper(this);
|
|
|
|
|
connect(m_removeMapper, SIGNAL(mapped(int)),
|
|
|
|
|
this, SLOT(stepRemove(int)));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
m_vbox = new QVBoxLayout(this);
|
|
|
|
|
m_vbox->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_vbox->setSpacing(0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
m_noStepsLabel = new QLabel(tr("No Build Steps"), this);
|
|
|
|
|
m_noStepsLabel->setContentsMargins(m_leftMargin, 0, 0, 0);
|
|
|
|
|
m_vbox->addWidget(m_noStepsLabel);
|
2009-08-06 15:31:32 +02:00
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
QHBoxLayout *hboxLayout = new QHBoxLayout();
|
|
|
|
|
hboxLayout->setContentsMargins(m_leftMargin, 4, 0, 0);
|
|
|
|
|
m_addButton = new QPushButton(this);
|
|
|
|
|
m_addButton->setText(m_clean ? tr("Add clean step") : tr("Add build step"));
|
|
|
|
|
m_addButton->setMenu(new QMenu(this));
|
|
|
|
|
hboxLayout->addWidget(m_addButton);
|
|
|
|
|
|
|
|
|
|
hboxLayout->addStretch(10);
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
m_addButton->setAttribute(Qt::WA_MacSmallSize);
|
|
|
|
|
#endif
|
2009-08-06 15:31:32 +02:00
|
|
|
|
2009-11-30 16:44:22 +01:00
|
|
|
m_vbox->addLayout(hboxLayout);
|
|
|
|
|
|
|
|
|
|
connect(m_addButton->menu(), SIGNAL(aboutToShow()),
|
|
|
|
|
this, SLOT(updateAddBuildStepMenu()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuildStepsPage::updateBuildStepButtonsState()
|
|
|
|
|
{
|
2009-11-24 15:36:31 +01:00
|
|
|
const QList<BuildStep *> &steps = m_clean ? m_configuration->cleanSteps() : m_configuration->buildSteps();
|
2009-11-30 16:44:22 +01:00
|
|
|
for(int i = 0; i < m_buildSteps.count(); ++i) {
|
2009-08-06 15:31:32 +02:00
|
|
|
BuildStepsWidgetStruct s = m_buildSteps.at(i);
|
2009-11-30 16:44:22 +01:00
|
|
|
s.removeButton->setEnabled(!steps.at(i)->immutable());
|
|
|
|
|
m_removeMapper->setMapping(s.removeButton, i);
|
|
|
|
|
s.upButton->setEnabled((i > 0) && !(steps.at(i)->immutable() && steps.at(i - 1)));
|
|
|
|
|
m_upMapper->setMapping(s.upButton, i);
|
|
|
|
|
s.downButton->setEnabled((i + 1 < steps.count()) && !(steps.at(i)->immutable() && steps.at(i + 1)->immutable()));
|
|
|
|
|
m_downMapper->setMapping(s.downButton, i);
|
2009-07-27 16:37:06 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|