Commit bdb9a14d authored by Christian Kandeler's avatar Christian Kandeler

QbsProjectManager: Allow users to override profile properties.

Creator derives its qbs profiles from the kits and overwrites
them as it sees fit, which means users cannot set custom properties
by editing the respective settings files or using the normal
qbs command-line tools. Therefore, we need to provide them with
a way to do this from Creator itself. For this purpose, we
introduce a settings page where a user can add or override
qbs properties per kit. The resulting "diff" is then applied
whenever the profiles are written, so qbs will take the
custom properties into account.

Change-Id: I909f5243c65647f62c91a2afa242fd531ddaf915
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
parent 5d8c0f9c
/****************************************************************************
**
** Copyright (C) 2014 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://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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 "customqbspropertiesdialog.h"
#include "ui_customqbspropertiesdialog.h"
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QTableWidgetItem>
namespace QbsProjectManager {
namespace Internal {
CustomQbsPropertiesDialog::CustomQbsPropertiesDialog(const QVariantMap &properties, QWidget *parent)
: QDialog(parent), m_ui(new Ui::CustomQbsPropertiesDialog)
{
m_ui->setupUi(this);
m_ui->propertiesTable->setRowCount(properties.count());
m_ui->propertiesTable->setHorizontalHeaderLabels(QStringList() << tr("Key") << tr("Value"));
int currentRow = 0;
for (QVariantMap::ConstIterator it = properties.constBegin(); it != properties.constEnd();
++it) {
QTableWidgetItem * const nameItem = new QTableWidgetItem;
nameItem->setData(Qt::DisplayRole, it.key());
m_ui->propertiesTable->setItem(currentRow, 0, nameItem);
QTableWidgetItem * const valueItem = new QTableWidgetItem;
valueItem->setData(Qt::DisplayRole, it.value());
m_ui->propertiesTable->setItem(currentRow, 1, valueItem);
++currentRow;
}
connect(m_ui->addButton, SIGNAL(clicked()), SLOT(addProperty()));
connect(m_ui->removeButton, SIGNAL(clicked()), SLOT(removeSelectedProperty()));
connect(m_ui->propertiesTable, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)),
SLOT(handleCurrentItemChanged()));
handleCurrentItemChanged();
}
QVariantMap CustomQbsPropertiesDialog::properties() const
{
QVariantMap properties;
for (int row = 0; row < m_ui->propertiesTable->rowCount(); ++row) {
const QTableWidgetItem * const nameItem = m_ui->propertiesTable->item(row, 0);
const QString name = nameItem->text();
if (name.isEmpty())
continue;
properties.insert(name, m_ui->propertiesTable->item(row, 1)->text());
}
return properties;
}
CustomQbsPropertiesDialog::~CustomQbsPropertiesDialog()
{
delete m_ui;
}
void CustomQbsPropertiesDialog::addProperty()
{
const int row = m_ui->propertiesTable->rowCount();
m_ui->propertiesTable->insertRow(row);
m_ui->propertiesTable->setItem(row, 0, new QTableWidgetItem);
m_ui->propertiesTable->setItem(row, 1, new QTableWidgetItem);
}
void CustomQbsPropertiesDialog::removeSelectedProperty()
{
const QTableWidgetItem * const currentItem = m_ui->propertiesTable->currentItem();
QTC_ASSERT(currentItem, return);
m_ui->propertiesTable->removeRow(currentItem->row());
}
void CustomQbsPropertiesDialog::handleCurrentItemChanged()
{
m_ui->removeButton->setEnabled(m_ui->propertiesTable->currentItem());
}
} // namespace Internal
} // namespace QbsProjectManager
/****************************************************************************
**
** Copyright (C) 2014 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://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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 QTC_CUSTOMQBSPROPERTIESDIALOG_H
#define QTC_CUSTOMQBSPROPERTIESDIALOG_H
#include <QVariantMap>
#include <QDialog>
namespace QbsProjectManager {
namespace Internal {
namespace Ui { class CustomQbsPropertiesDialog; }
class CustomQbsPropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit CustomQbsPropertiesDialog(const QVariantMap &properties, QWidget *parent = 0);
QVariantMap properties() const;
~CustomQbsPropertiesDialog();
private slots:
void addProperty();
void removeSelectedProperty();
void handleCurrentItemChanged();
private:
Ui::CustomQbsPropertiesDialog * const m_ui;
};
} // namespace Internal
} // namespace QbsProjectManager
#endif // Include guard.
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QbsProjectManager::Internal::CustomQbsPropertiesDialog</class>
<widget class="QDialog" name="QbsProjectManager::Internal::CustomQbsPropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Custom Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTableWidget" name="propertiesTable">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<property name="columnCount">
<number>2</number>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column/>
<column/>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>&amp;Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>&amp;Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QbsProjectManager::Internal::CustomQbsPropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QbsProjectManager::Internal::CustomQbsPropertiesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -141,9 +141,22 @@ static QStringList toolchainList(const ProjectExplorer::ToolChain *tc)
return list;
}
QVariantMap DefaultPropertyProvider::properties(const ProjectExplorer::Kit *k, const QVariantMap &defaultData) const
QVariantMap DefaultPropertyProvider::properties(const ProjectExplorer::Kit *k,
const QVariantMap &defaultData) const
{
QTC_ASSERT(k, return defaultData);
QVariantMap data = autoGeneratedProperties(k, defaultData);
const QVariantMap customProperties = k->value(Core::Id(QBS_PROPERTIES_KEY_FOR_KITS)).toMap();
for (QVariantMap::ConstIterator it = customProperties.constBegin();
it != customProperties.constEnd(); ++it) {
data.insert(it.key(), it.value());
}
return data;
}
QVariantMap DefaultPropertyProvider::autoGeneratedProperties(const ProjectExplorer::Kit *k,
const QVariantMap &defaultData) const
{
QVariantMap data = defaultData;
const QString sysroot = ProjectExplorer::SysRootKitInformation::sysRoot(k).toUserOutput();
......
......@@ -42,6 +42,10 @@ class DefaultPropertyProvider : public PropertyProvider
public:
bool canHandle(const ProjectExplorer::Kit *k) const { return k; }
QVariantMap properties(const ProjectExplorer::Kit *k, const QVariantMap &defaultData) const;
private:
QVariantMap autoGeneratedProperties(const ProjectExplorer::Kit *k,
const QVariantMap &defaultData) const;
};
} // namespace QbsProjectManager
......
......@@ -50,6 +50,13 @@ const char CPP_PLATFORMPATH[] = "cpp.platformPath";
const char CPP_XCODESDKNAME[] = "cpp.xcodeSdkName";
const char CPP_XCODESDKVERSION[] = "cpp.xcodeSdkVersion";
// Settings page
const char QBS_SETTINGS_CATEGORY[] = "YM.qbs";
const char QBS_SETTINGS_TR_CATEGORY[] = QT_TRANSLATE_NOOP("QbsProjectManager", "qbs");
const char QBS_SETTINGS_CATEGORY_ICON[] = ":/projectexplorer/images/build.png";
const char QBS_PROPERTIES_KEY_FOR_KITS[] = "QbsProjectManager.qbs-properties";
} // namespace Constants
} // namespace QbsProjectManager
......
/****************************************************************************
**
** Copyright (C) 2014 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://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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 "qbsprofilessettingspage.h"
#include "ui_qbsprofilessettingswidget.h"
#include "customqbspropertiesdialog.h"
#include "qbsconstants.h"
#include "qbsprojectmanager.h"
#include <coreplugin/icore.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/kitmanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <qbs.h>
#include <QCoreApplication>
#include <QHash>
#include <QWidget>
namespace QbsProjectManager {
namespace Internal {
class QbsProfilesSettingsWidget : public QWidget
{
Q_OBJECT
public:
QbsProfilesSettingsWidget(QWidget *parent = 0);
void applyCustomProperties();
private slots:
void refreshKitsList();
void displayCurrentProfile();
void editProfile();
private:
void setupCustomProperties(const ProjectExplorer::Kit *kit);
void mergeCustomPropertiesIntoModel();
Ui::QbsProfilesSettingsWidget m_ui;
qbs::SettingsModel m_model;
typedef QHash<Core::Id, QVariantMap> CustomProperties;
CustomProperties m_customProperties;
bool m_applyingProperties;
};
QbsProfilesSettingsPage::QbsProfilesSettingsPage(QObject *parent)
: Core::IOptionsPage(parent), m_widget(0)
{
setId("AA.QbsProfiles");
setDisplayName(tr("Profiles"));
setCategory(Constants::QBS_SETTINGS_CATEGORY);
setDisplayCategory(QCoreApplication::translate("QbsProjectManager",
Constants::QBS_SETTINGS_TR_CATEGORY));
setCategoryIcon(QLatin1String(Constants::QBS_SETTINGS_CATEGORY_ICON));
}
QWidget *QbsProfilesSettingsPage::widget()
{
if (!m_widget)
m_widget = new QbsProfilesSettingsWidget;
return m_widget;
}
void QbsProfilesSettingsPage::apply()
{
if (m_widget)
m_widget->applyCustomProperties();
}
void QbsProfilesSettingsPage::finish()
{
delete m_widget;
m_widget = 0;
}
QbsProfilesSettingsWidget::QbsProfilesSettingsWidget(QWidget *parent)
: QWidget(parent)
, m_model(Core::ICore::userResourcePath())
, m_applyingProperties(false)
{
m_model.setEditable(false);
m_ui.setupUi(this);
connect(ProjectExplorer::KitManager::instance(), &ProjectExplorer::KitManager::kitsChanged,
this, &QbsProfilesSettingsWidget::refreshKitsList);
connect(m_ui.expandButton, SIGNAL(clicked()), m_ui.propertiesView, SLOT(expandAll()));
connect(m_ui.collapseButton, SIGNAL(clicked()), m_ui.propertiesView, SLOT(collapseAll()));
connect(m_ui.editButton, SIGNAL(clicked()), SLOT(editProfile()));
refreshKitsList();
}
void QbsProfilesSettingsWidget::applyCustomProperties()
{
QTC_ASSERT(!m_applyingProperties, return);
m_applyingProperties = true; // The following will cause kitsChanged() to be emitted.
for (CustomProperties::ConstIterator it = m_customProperties.constBegin();
it != m_customProperties.constEnd(); ++it) {
ProjectExplorer::Kit * const kit = ProjectExplorer::KitManager::find(it.key());
QTC_ASSERT(kit, continue);
kit->setValue(Core::Id(Constants::QBS_PROPERTIES_KEY_FOR_KITS), it.value());
}
m_applyingProperties = false;
m_model.reload();
displayCurrentProfile();
}
void QbsProfilesSettingsWidget::refreshKitsList()
{
if (m_applyingProperties)
return;
m_ui.kitsComboBox->disconnect(this);
m_ui.propertiesView->setModel(0);
m_model.reload();
m_ui.profileValueLabel->clear();
Core::Id currentId;
if (m_ui.kitsComboBox->count() > 0)
currentId = Core::Id::fromSetting(m_ui.kitsComboBox->currentData());
m_ui.kitsComboBox->clear();
int newCurrentIndex = -1;
QList<ProjectExplorer::Kit *> validKits = ProjectExplorer::KitManager::kits();
Utils::erase(validKits, [](const ProjectExplorer::Kit *k) { return !k->isValid(); });
const bool hasKits = !validKits.isEmpty();
m_customProperties.clear();
foreach (const ProjectExplorer::Kit * const kit, validKits) {
if (kit->id() == currentId)
newCurrentIndex = m_ui.kitsComboBox->count();
m_ui.kitsComboBox->addItem(kit->displayName(), kit->id().toSetting());
setupCustomProperties(kit);
}
mergeCustomPropertiesIntoModel();
m_ui.editButton->setEnabled(hasKits);
if (newCurrentIndex != -1)
m_ui.kitsComboBox->setCurrentIndex(newCurrentIndex);
else if (hasKits)
m_ui.kitsComboBox->setCurrentIndex(0);
displayCurrentProfile();
connect(m_ui.kitsComboBox, SIGNAL(currentIndexChanged(int)), SLOT(displayCurrentProfile()));
}
void QbsProfilesSettingsWidget::displayCurrentProfile()
{
m_ui.propertiesView->setModel(0);
if (m_ui.kitsComboBox->currentIndex() == -1)
return;
const Core::Id kitId = Core::Id::fromSetting(m_ui.kitsComboBox->currentData());
const ProjectExplorer::Kit * const kit = ProjectExplorer::KitManager::find(kitId);
const QString profileName = QbsManager::profileForKit(kit);
m_ui.profileValueLabel->setText(profileName);
for (int i = 0; i < m_model.rowCount(); ++i) {
const QModelIndex profilesIndex = m_model.index(i, 0);
if (m_model.data(profilesIndex).toString() != QLatin1String("profiles"))
continue;
for (int i = 0; i < m_model.rowCount(profilesIndex); ++i) {
const QModelIndex currentProfileIndex = m_model.index(i, 0, profilesIndex);
if (m_model.data(currentProfileIndex).toString() != profileName)
continue;
m_ui.propertiesView->setModel(&m_model);
m_ui.propertiesView->header()->setSectionResizeMode(m_model.keyColumn(),
QHeaderView::ResizeToContents);
m_ui.propertiesView->setRootIndex(currentProfileIndex);
return;
}
}
}
void QbsProfilesSettingsWidget::editProfile()
{
QTC_ASSERT(m_ui.kitsComboBox->currentIndex() != -1, return);
const Core::Id kitId = Core::Id::fromSetting(m_ui.kitsComboBox->currentData());
CustomQbsPropertiesDialog dlg(m_customProperties.value(kitId), this);
if (dlg.exec() != QDialog::Accepted)
return;
m_customProperties.insert(kitId, dlg.properties());
mergeCustomPropertiesIntoModel();
displayCurrentProfile();
}
void QbsProfilesSettingsWidget::setupCustomProperties(const ProjectExplorer::Kit *kit)
{
const QVariantMap &properties
= kit->value(Core::Id(Constants::QBS_PROPERTIES_KEY_FOR_KITS)).toMap();
m_customProperties.insert(kit->id(), properties);
}
void QbsProfilesSettingsWidget::mergeCustomPropertiesIntoModel()
{
QVariantMap customProperties;
for (CustomProperties::ConstIterator it = m_customProperties.constBegin();
it != m_customProperties.constEnd(); ++it) {
const Core::Id kitId = it.key();
const ProjectExplorer::Kit * const kit = ProjectExplorer::KitManager::find(kitId);
QTC_ASSERT(kit, continue);
const QString keyPrefix = QLatin1String("profiles.") + QbsManager::profileForKit(kit)
+ QLatin1Char('.');
for (QVariantMap::ConstIterator it2 = it.value().constBegin(); it2 != it.value().constEnd();
++it2) {
customProperties.insert(keyPrefix + it2.key(), it2.value());
}
}
m_model.setAdditionalProperties(customProperties);
}
} // namespace Internal
} // namespace QbsProjectManager
#include "qbsprofilessettingspage.moc"
/****************************************************************************
**
** Copyright (C) 2014 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://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** 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 QBSPROFILESSETTINGSPAGE_H
#define QBSPROFILESSETTINGSPAGE_H
#include <coreplugin/dialogs/ioptionspage.h>
namespace QbsProjectManager {
namespace Internal {
class QbsProfilesSettingsWidget;
class QbsProfilesSettingsPage : public Core::IOptionsPage
{
public:
QbsProfilesSettingsPage(QObject *parent = 0);
private:
QWidget *widget() Q_DECL_OVERRIDE;
void apply() Q_DECL_OVERRIDE;
void finish() Q_DECL_OVERRIDE;
QbsProfilesSettingsWidget *m_widget;
};
} // namespace Internal
} // namespace QbsProjectManager
#endif // Include guard.
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QbsProjectManager::Internal::QbsProfilesSettingsWidget</class>
<widget class="QWidget" name="QbsProjectManager::Internal::QbsProfilesSettingsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>421</width>
<height>315</height>
</rect>
</property>
<property<