QbsProjectManager: Introduce QbsKitInformation

... and use it to allow users to set custom properties in the
corresponding profile. This replaces the idiosyncratic and more
complicated approach we had before, when that was done in the qbs
profiles settings page. The profiles view is now read-only.

Change-Id: I0c29c1ac0c510e17d685e7bbaa38b54c8100ddb8
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Christian Kandeler
2017-06-16 15:57:56 +02:00
parent 06ef0ed153
commit d5066ac06e
9 changed files with 183 additions and 76 deletions

View File

@@ -24,6 +24,8 @@
****************************************************************************/
#include "defaultpropertyprovider.h"
#include "qbskitinformation.h"
#include "qbsprojectmanagerconstants.h"
#include <coreplugin/messagemanager.h>
@@ -207,7 +209,7 @@ QVariantMap DefaultPropertyProvider::properties(const ProjectExplorer::Kit *k,
{
QTC_ASSERT(k, return defaultData);
QVariantMap data = autoGeneratedProperties(k, defaultData);
const QVariantMap customProperties = k->value(Core::Id(QBS_PROPERTIES_KEY_FOR_KITS)).toMap();
const QVariantMap customProperties = QbsKitInformation::properties(k);
for (QVariantMap::ConstIterator it = customProperties.constBegin();
it != customProperties.constEnd(); ++it) {
data.insert(it.key(), it.value());

View File

@@ -0,0 +1,121 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "qbskitinformation.h"
#include "customqbspropertiesdialog.h"
#include <projectexplorer/kitconfigwidget.h>
#include <projectexplorer/kitmanager.h>
#include <qbs.h>
#include <QLabel>
#include <QPushButton>
using namespace ProjectExplorer;
namespace QbsProjectManager {
namespace Internal {
class ConfigWidget final : public KitConfigWidget
{
Q_OBJECT
public:
ConfigWidget(Kit *kit, const KitInformation *kitInfo)
: KitConfigWidget(kit, kitInfo),
m_contentLabel(new QLabel),
m_changeButton(new QPushButton(tr("Change...")))
{
connect(m_changeButton, &QPushButton::clicked, this, &ConfigWidget::changeProperties);
}
private:
QString displayName() const override { return QbsKitInformation::displayName(); }
void makeReadOnly() override { m_changeButton->setEnabled(false); }
void refresh() override { m_contentLabel->setText(QbsKitInformation::representation(kit())); }
QWidget *mainWidget() const override { return m_contentLabel; }
QWidget *buttonWidget() const override { return m_changeButton; }
void changeProperties()
{
CustomQbsPropertiesDialog dlg(QbsKitInformation::properties(kit()));
if (dlg.exec() == QDialog::Accepted)
QbsKitInformation::setProperties(kit(), dlg.properties());
}
QLabel * const m_contentLabel;
QPushButton * const m_changeButton;
};
QString QbsKitInformation::displayName()
{
return tr("Additional Qbs Profile Settings");
}
QString QbsKitInformation::representation(const Kit *kit)
{
const QVariantMap props = properties(kit);
QString repr;
for (auto it = props.begin(); it != props.end(); ++it) {
if (!repr.isEmpty())
repr += ' ';
repr += it.key() + ':' + qbs::settingsValueToRepresentation(it.value());
}
return repr;
}
QVariantMap QbsKitInformation::properties(const Kit *kit)
{
return kit->value(id()).toMap();
}
void QbsKitInformation::setProperties(Kit *kit, const QVariantMap &properties)
{
kit->setValue(id(), properties);
}
Core::Id QbsKitInformation::id()
{
return "Qbs.KitInformation";
}
QVariant QbsKitInformation::defaultValue(const Kit *) const { return QString(); }
QList<Task> QbsKitInformation::validate(const Kit *) const { return QList<Task>(); }
KitInformation::ItemList QbsKitInformation::toUserOutput(const Kit *k) const
{
return ItemList({qMakePair(displayName(), representation(k))});
}
KitConfigWidget *QbsKitInformation::createConfigWidget(Kit *k) const
{
return new ConfigWidget(k, this);
}
} // namespace Internal
} // namespace QbsProjectManager
#include <qbskitinformation.moc>

View File

@@ -0,0 +1,53 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <projectexplorer/kitinformation.h>
namespace QbsProjectManager {
namespace Internal {
class QbsKitInformation final : public ProjectExplorer::KitInformation
{
public:
static QString displayName();
static QString representation(const ProjectExplorer::Kit *kit);
static QVariantMap properties(const ProjectExplorer::Kit *kit);
static void setProperties(ProjectExplorer::Kit *kit, const QVariantMap &properties);
private:
static Core::Id id();
QVariant defaultValue(const ProjectExplorer::Kit *) const override;
QList<ProjectExplorer::Task> validate(const ProjectExplorer::Kit *) const override;
ItemList toUserOutput(const ProjectExplorer::Kit *) const override;
ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *) const override;
ProjectExplorer::KitConfigWidget *m_widget = nullptr;
};
} // namespace Internal
} // namespace QbsProjectManager

View File

@@ -26,7 +26,6 @@
#include "qbsprofilessettingspage.h"
#include "ui_qbsprofilessettingswidget.h"
#include "customqbspropertiesdialog.h"
#include "qbsprojectmanager.h"
#include "qbsprojectmanagerconstants.h"
#include "qbsprojectmanagersettings.h"
@@ -57,16 +56,9 @@ public:
private:
void refreshKitsList();
void displayCurrentProfile();
void editProfile();
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)
@@ -109,7 +101,6 @@ void QbsProfilesSettingsPage::finish()
QbsProfilesSettingsWidget::QbsProfilesSettingsWidget(QWidget *parent)
: QWidget(parent)
, m_model(QbsProjectManagerSettings::qbsSettingsBaseDir())
, m_applyingProperties(false)
{
m_model.setEditable(false);
m_ui.setupUi(this);
@@ -125,31 +116,17 @@ QbsProfilesSettingsWidget::QbsProfilesSettingsWidget(QWidget *parent)
m_ui.propertiesView, &QTreeView::expandAll);
connect(m_ui.collapseButton, &QAbstractButton::clicked,
m_ui.propertiesView, &QTreeView::collapseAll);
connect(m_ui.editButton, &QAbstractButton::clicked,
this, &QbsProfilesSettingsWidget::editProfile);
refreshKitsList();
}
void QbsProfilesSettingsWidget::apply()
{
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::kit(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();
@@ -162,15 +139,11 @@ void QbsProfilesSettingsWidget::refreshKitsList()
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)
@@ -208,45 +181,6 @@ void QbsProfilesSettingsWidget::displayCurrentProfile()
}
}
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::kit(kitId);
QTC_ASSERT(kit, continue);
const QString keyPrefix = QLatin1String("profiles.")
+ QbsManager::instance()->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

View File

@@ -101,13 +101,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>&amp;Edit...</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@@ -28,6 +28,7 @@ HEADERS = \
qbscleanstep.h \
qbsdeployconfigurationfactory.h \
qbsinfopage.h \
qbskitinformation.h \
qbsinstallstep.h \
qbslogsink.h \
qbsnodes.h \
@@ -56,6 +57,7 @@ SOURCES = \
qbsdeployconfigurationfactory.cpp \
qbsinfopage.cpp \
qbsinstallstep.cpp \
qbskitinformation.cpp \
qbslogsink.cpp \
qbsnodes.cpp \
qbsnodetreebuilder.cpp \

View File

@@ -84,6 +84,8 @@ QtcPlugin {
"qbsinstallstep.cpp",
"qbsinstallstep.h",
"qbsinstallstepconfigwidget.ui",
"qbskitinformation.cpp",
"qbskitinformation.h",
"qbslogsink.cpp",
"qbslogsink.h",
"qbsnodes.cpp",

View File

@@ -93,8 +93,6 @@ 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";
const char QBS_PROFILING_ENV[] = "QTC_QBS_PROFILING";
} // namespace Constants

View File

@@ -31,6 +31,7 @@
#include "qbsdeployconfigurationfactory.h"
#include "qbsinfopage.h"
#include "qbsinstallstep.h"
#include "qbskitinformation.h"
#include "qbsnodes.h"
#include "qbsprofilessettingspage.h"
#include "qbsproject.h"
@@ -93,6 +94,7 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
Core::FileIconProvider::registerIconOverlayForSuffix(ProjectExplorer::Constants::FILEOVERLAY_QT, "qbs");
ProjectManager::registerProjectType<QbsProject>(QmlJSTools::Constants::QBS_MIMETYPE);
KitManager::registerKitInformation(new QbsKitInformation);
//create and register objects
addAutoReleasedObject(new QbsManager);