From 221bc24105e3254a93c68c45933634b73b500bdc Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 12 Jun 2013 14:36:02 +0200 Subject: Qbs: Allow setting of properties This enables support for e.g. setting CFLAGS, custom defines, etc. Task-number: QTCREATORBUG-9380 Change-Id: I9d4a560ac5ba8a40c51c15fdf8009c0dba5eeef1 Reviewed-by: Eike Ziller Reviewed-by: Tobias Hunger --- src/plugins/qbsprojectmanager/qbsbuildstep.cpp | 64 ++++++++++- src/plugins/qbsprojectmanager/qbsbuildstep.h | 3 + .../qbsprojectmanager/qbsbuildstepconfigwidget.ui | 126 ++++++++++++--------- .../qbsprojectmanager/qbsprojectmanager.pro | 2 + .../qbsprojectmanager/qbsprojectmanager.qbs | 2 + .../qbsprojectmanager/qbspropertylineedit.cpp | 83 ++++++++++++++ .../qbsprojectmanager/qbspropertylineedit.h | 62 ++++++++++ 7 files changed, 282 insertions(+), 60 deletions(-) create mode 100644 src/plugins/qbsprojectmanager/qbspropertylineedit.cpp create mode 100644 src/plugins/qbsprojectmanager/qbspropertylineedit.h diff --git a/src/plugins/qbsprojectmanager/qbsbuildstep.cpp b/src/plugins/qbsprojectmanager/qbsbuildstep.cpp index 68d23c1c26..03323156f1 100644 --- a/src/plugins/qbsprojectmanager/qbsbuildstep.cpp +++ b/src/plugins/qbsprojectmanager/qbsbuildstep.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include @@ -332,7 +333,8 @@ void QbsBuildStep::setMaxJobs(int jobcount) // -------------------------------------------------------------------- QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step) : - m_step(step) + m_step(step), + m_ignoreChange(false) { connect(m_step, SIGNAL(displayNameChanged()), this, SLOT(updateState())); connect(m_step, SIGNAL(qbsConfigurationChanged()), this, SLOT(updateState())); @@ -348,6 +350,7 @@ QbsBuildStepConfigWidget::QbsBuildStepConfigWidget(QbsBuildStep *step) : connect(m_ui->dryRunCheckBox, SIGNAL(toggled(bool)), this, SLOT(changeDryRun(bool))); connect(m_ui->keepGoingCheckBox, SIGNAL(toggled(bool)), this, SLOT(changeKeepGoing(bool))); connect(m_ui->jobSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeJobCount(int))); + connect(m_ui->propertyEdit, SIGNAL(propertiesChanged()), this, SLOT(changeProperties())); updateState(); } @@ -364,9 +367,12 @@ QString QbsBuildStepConfigWidget::displayName() const void QbsBuildStepConfigWidget::updateState() { - m_ui->dryRunCheckBox->setChecked(m_step->dryRun()); - m_ui->keepGoingCheckBox->setChecked(m_step->keepGoing()); - m_ui->jobSpinBox->setValue(m_step->maxJobs()); + if (!m_ignoreChange) { + m_ui->dryRunCheckBox->setChecked(m_step->dryRun()); + m_ui->keepGoingCheckBox->setChecked(m_step->keepGoing()); + m_ui->jobSpinBox->setValue(m_step->maxJobs()); + updatePropertyEdit(m_step->qbsConfiguration()); + } const QString buildVariant = m_step->buildVariant(); const int idx = (buildVariant == QLatin1String(Constants::QBS_VARIANT_DEBUG)) ? 0 : 1; @@ -380,13 +386,34 @@ void QbsBuildStepConfigWidget::updateState() command += QString::fromLatin1("--jobs %1 ").arg(m_step->maxJobs()); command += QString::fromLatin1("profile:%1 %2").arg(m_step->profile(), buildVariant); + QList > propertyList = m_ui->propertyEdit->properties(); + for (int i = 0; i < propertyList.count(); ++i) { + command += QLatin1Char(' ') + propertyList.at(i).first + + QLatin1Char(':') + propertyList.at(i).second; + } + QString summary = tr("Qbs: %1").arg(command); - if (m_summary != summary) { + if (m_summary != summary) { m_summary = summary; emit updateSummary(); } } +void QbsBuildStepConfigWidget::updatePropertyEdit(const QVariantMap &data) +{ + QVariantMap editable = data; + + // remove data that is edited with special UIs: + editable.remove(QLatin1String(Constants::QBS_CONFIG_PROFILE_KEY)); + editable.remove(QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY)); + + QStringList propertyList; + for (QVariantMap::const_iterator i = editable.constBegin(); i != editable.constEnd(); ++i) + propertyList.append(i.key() + QLatin1Char(':') + i.value().toString()); + + m_ui->propertyEdit->setText(Utils::QtcProcess::joinArgs(propertyList)); +} + void QbsBuildStepConfigWidget::changeBuildVariant(int idx) { QString variant; @@ -394,22 +421,49 @@ void QbsBuildStepConfigWidget::changeBuildVariant(int idx) variant = QLatin1String(Constants::QBS_VARIANT_RELEASE); else variant = QLatin1String(Constants::QBS_VARIANT_DEBUG); + m_ignoreChange = true; m_step->setBuildVariant(variant); + m_ignoreChange = false; } void QbsBuildStepConfigWidget::changeDryRun(bool dr) { + m_ignoreChange = true; m_step->setDryRun(dr); + m_ignoreChange = false; } void QbsBuildStepConfigWidget::changeKeepGoing(bool kg) { + m_ignoreChange = true; m_step->setKeepGoing(kg); + m_ignoreChange = false; } void QbsBuildStepConfigWidget::changeJobCount(int count) { + m_ignoreChange = true; m_step->setMaxJobs(count); + m_ignoreChange = false; +} + +void QbsBuildStepConfigWidget::changeProperties() +{ + QVariantMap data; + QVariantMap tmp = m_step->qbsConfiguration(); + + // Insert values set up with special UIs: + data.insert(QLatin1String(Constants::QBS_CONFIG_PROFILE_KEY), + tmp.value(QLatin1String(Constants::QBS_CONFIG_PROFILE_KEY))); + data.insert(QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY), + tmp.value(QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY))); + QList > propertyList = m_ui->propertyEdit->properties(); + for (int i = 0; i < propertyList.count(); ++i) + data.insert(propertyList.at(i).first, propertyList.at(i).second); + + m_ignoreChange = true; + m_step->setQbsConfiguration(data); + m_ignoreChange = false; } // -------------------------------------------------------------------- diff --git a/src/plugins/qbsprojectmanager/qbsbuildstep.h b/src/plugins/qbsprojectmanager/qbsbuildstep.h index 433d2478b1..6921a33978 100644 --- a/src/plugins/qbsprojectmanager/qbsbuildstep.h +++ b/src/plugins/qbsprojectmanager/qbsbuildstep.h @@ -118,17 +118,20 @@ public: private slots: void updateState(); + void updatePropertyEdit(const QVariantMap &data); void changeBuildVariant(int); void changeDryRun(bool dr); void changeKeepGoing(bool kg); void changeJobCount(int count); + void changeProperties(); private: Ui::QbsBuildStepConfigWidget *m_ui; QbsBuildStep *m_step; QString m_summary; + bool m_ignoreChange; }; diff --git a/src/plugins/qbsprojectmanager/qbsbuildstepconfigwidget.ui b/src/plugins/qbsprojectmanager/qbsbuildstepconfigwidget.ui index 9e2b0b0c6d..4f4702c32f 100644 --- a/src/plugins/qbsprojectmanager/qbsbuildstepconfigwidget.ui +++ b/src/plugins/qbsprojectmanager/qbsbuildstepconfigwidget.ui @@ -6,11 +6,11 @@ 0 0 - 428 - 102 + 281 + 79 - + 0 @@ -23,61 +23,70 @@ 0 - - - - - - Build variant: - - - - - - - - 0 - 0 - - - - - Debug - - - - - Release - - - - + + 12 + + + + + Build variant: + + + + + + + + 0 + 0 + + - + + Debug + - - - jobs - - + + Release + - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + + + + + + jobs + + + + + + + Qt::Horizontal + + + + 15 + 5 + + + + + + + + Properties: + + + + + - + @@ -94,14 +103,14 @@ - + Qt::Horizontal 40 - 20 + 5 @@ -110,6 +119,13 @@ + + + QbsPropertyLineEdit + QLineEdit +
qbspropertylineedit.h
+
+
diff --git a/src/plugins/qbsprojectmanager/qbsprojectmanager.pro b/src/plugins/qbsprojectmanager/qbsprojectmanager.pro index 708a23f24d..5cdd7a1fcb 100644 --- a/src/plugins/qbsprojectmanager/qbsprojectmanager.pro +++ b/src/plugins/qbsprojectmanager/qbsprojectmanager.pro @@ -29,6 +29,7 @@ HEADERS = \ qbsprojectmanager_global.h \ qbsprojectmanagerconstants.h \ qbsprojectmanagerplugin.h \ + qbspropertylineedit.h \ qbsrunconfiguration.h \ qbsstep.h @@ -46,6 +47,7 @@ SOURCES = \ qbsprojectfile.cpp \ qbsprojectmanager.cpp \ qbsprojectmanagerplugin.cpp \ + qbspropertylineedit.cpp \ qbsrunconfiguration.cpp \ qbsstep.cpp diff --git a/src/plugins/qbsprojectmanager/qbsprojectmanager.qbs b/src/plugins/qbsprojectmanager/qbsprojectmanager.qbs index ffb14bee5c..e6d84007d0 100644 --- a/src/plugins/qbsprojectmanager/qbsprojectmanager.qbs +++ b/src/plugins/qbsprojectmanager/qbsprojectmanager.qbs @@ -79,6 +79,8 @@ QtcPlugin { "qbsprojectmanagerconstants.h", "qbsprojectmanagerplugin.cpp", "qbsprojectmanagerplugin.h", + "qbspropertylineedit.cpp", + "qbspropertylineedit.h", "qbsrunconfiguration.cpp", "qbsrunconfiguration.h", "qbsstep.cpp", diff --git a/src/plugins/qbsprojectmanager/qbspropertylineedit.cpp b/src/plugins/qbsprojectmanager/qbspropertylineedit.cpp new file mode 100644 index 0000000000..99e2490762 --- /dev/null +++ b/src/plugins/qbsprojectmanager/qbspropertylineedit.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 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. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "qbspropertylineedit.h" + +#include + +#include + +namespace QbsProjectManager { +namespace Internal { + +QbsPropertyLineEdit::QbsPropertyLineEdit(QWidget *parent) : + Utils::BaseValidatingLineEdit(parent) +{ } + +QList > QbsPropertyLineEdit::properties() const +{ + return m_propertyCache; +} + +bool QbsPropertyLineEdit::validate(const QString &value, QString *errorMessage) const +{ + Utils::QtcProcess::SplitError err; + QStringList argList = Utils::QtcProcess::splitArgs(value, false, &err); + if (err != Utils::QtcProcess::SplitOk) { + if (errorMessage) + *errorMessage = tr("Could not split properties."); + return false; + } + + QList > properties; + foreach (const QString &arg, argList) { + int pos = arg.indexOf(QLatin1Char(':')); + QString key; + QString value; + if (pos > 0) { + key = arg.left(pos); + value = arg.mid(pos + 1); + properties.append(qMakePair(key, value)); + } else { + if (errorMessage) + *errorMessage = tr("No ':' found in property definition."); + return false; + } + } + + if (m_propertyCache != properties) { + m_propertyCache = properties; + emit propertiesChanged(); + } + return true; +} + +} // namespace Internal +} // namespace QbsProjectManager + diff --git a/src/plugins/qbsprojectmanager/qbspropertylineedit.h b/src/plugins/qbsprojectmanager/qbspropertylineedit.h new file mode 100644 index 0000000000..399c4d2845 --- /dev/null +++ b/src/plugins/qbsprojectmanager/qbspropertylineedit.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 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. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef QBSPROPERTYLINEEDIT_H +#define QBSPROPERTYLINEEDIT_H + +#include + +#include +#include + +namespace QbsProjectManager { +namespace Internal { + +class QbsPropertyLineEdit : public Utils::BaseValidatingLineEdit +{ + Q_OBJECT + +public: + explicit QbsPropertyLineEdit(QWidget *parent = 0); + + QList > properties() const; + +signals: + void propertiesChanged() const; + +private: + bool validate(const QString &value, QString *errorMessage) const; + + mutable QList > m_propertyCache; +}; + +} // namespace Internal +} // namespace QbsProjectManager + +#endif // QBSPROPERTYLINEEDIT_H -- cgit v1.2.1