2014-10-31 14:51:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-10-31 14:51:55 +01:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2014-10-31 14:51:55 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2014-10-31 14:51:55 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qbsprofilessettingspage.h"
|
|
|
|
|
#include "ui_qbsprofilessettingswidget.h"
|
|
|
|
|
|
2019-06-28 14:30:32 +02:00
|
|
|
#include "qbsprofilemanager.h"
|
2016-10-25 17:14:28 +02:00
|
|
|
#include "qbsprojectmanagerconstants.h"
|
2019-06-28 14:30:32 +02:00
|
|
|
#include "qbssettings.h"
|
2014-10-31 14:51:55 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <projectexplorer/kit.h>
|
|
|
|
|
#include <projectexplorer/kitmanager.h>
|
2017-06-15 15:42:33 -07:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2018-02-28 18:15:57 +01:00
|
|
|
#include <projectexplorer/projectexplorericons.h>
|
2019-06-28 14:30:32 +02:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2014-10-31 14:51:55 +01:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2019-06-28 14:30:32 +02:00
|
|
|
#include <utils/treemodel.h>
|
2014-10-31 14:51:55 +01:00
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
2019-06-28 14:30:32 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2014-10-31 14:51:55 +01:00
|
|
|
namespace QbsProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2019-06-28 14:30:32 +02:00
|
|
|
class ProfileTreeItem : public Utils::TypedTreeItem<ProfileTreeItem, ProfileTreeItem>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ProfileTreeItem() = default;
|
|
|
|
|
ProfileTreeItem(const QString &key, const QString &value) : m_key(key), m_value(value) { }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QVariant data(int column, int role) const override
|
|
|
|
|
{
|
|
|
|
|
if (role != Qt::DisplayRole)
|
|
|
|
|
return {};
|
|
|
|
|
if (column == 0)
|
|
|
|
|
return m_key;
|
|
|
|
|
if (column == 1)
|
|
|
|
|
return m_value;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString m_key;
|
|
|
|
|
const QString m_value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ProfileModel : public Utils::TreeModel<ProfileTreeItem>
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
ProfileModel() : TreeModel(static_cast<QObject *>(nullptr))
|
|
|
|
|
{
|
|
|
|
|
setHeader(QStringList{tr("Key"), tr("Value")});
|
|
|
|
|
reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reload()
|
|
|
|
|
{
|
|
|
|
|
ProfileTreeItem * const newRoot = new ProfileTreeItem(QString(), QString());
|
|
|
|
|
QHash<QStringList, ProfileTreeItem *> itemMap;
|
|
|
|
|
const QStringList output = QbsProfileManager::runQbsConfig(
|
2020-07-21 09:48:14 +02:00
|
|
|
QbsProfileManager::QbsConfigOp::Get, "profiles").split('\n', Qt::SkipEmptyParts);
|
2019-06-28 14:30:32 +02:00
|
|
|
for (QString line : output) {
|
|
|
|
|
line = line.trimmed();
|
|
|
|
|
line = line.mid(QString("profiles.").length());
|
|
|
|
|
const int colonIndex = line.indexOf(':');
|
|
|
|
|
if (colonIndex == -1)
|
|
|
|
|
continue;
|
2020-07-21 09:48:14 +02:00
|
|
|
const QStringList key = line.left(colonIndex).trimmed().split('.', Qt::SkipEmptyParts);
|
2019-06-28 14:30:32 +02:00
|
|
|
const QString value = line.mid(colonIndex + 1).trimmed();
|
|
|
|
|
QStringList partialKey;
|
|
|
|
|
ProfileTreeItem *parent = newRoot;
|
|
|
|
|
for (const QString &keyComponent : key) {
|
|
|
|
|
partialKey << keyComponent;
|
|
|
|
|
ProfileTreeItem *&item = itemMap[partialKey];
|
|
|
|
|
if (!item) {
|
|
|
|
|
item = new ProfileTreeItem(keyComponent, partialKey == key ? value : QString());
|
|
|
|
|
parent->appendChild(item);
|
|
|
|
|
}
|
|
|
|
|
parent = item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setRootItem(newRoot);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-31 14:51:55 +01:00
|
|
|
class QbsProfilesSettingsWidget : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2019-03-21 08:09:35 +01:00
|
|
|
QbsProfilesSettingsWidget();
|
2014-10-31 14:51:55 +01:00
|
|
|
|
2016-06-28 23:29:21 +03:00
|
|
|
private:
|
2014-10-31 14:51:55 +01:00
|
|
|
void refreshKitsList();
|
|
|
|
|
void displayCurrentProfile();
|
|
|
|
|
|
|
|
|
|
Ui::QbsProfilesSettingsWidget m_ui;
|
2019-06-28 14:30:32 +02:00
|
|
|
ProfileModel m_model;
|
2014-10-31 14:51:55 +01:00
|
|
|
};
|
|
|
|
|
|
2019-03-21 08:09:35 +01:00
|
|
|
QbsProfilesSettingsPage::QbsProfilesSettingsPage()
|
2014-10-31 14:51:55 +01:00
|
|
|
{
|
2017-06-15 15:42:33 -07:00
|
|
|
setId("Y.QbsProfiles");
|
2019-06-28 14:30:32 +02:00
|
|
|
setDisplayName(QCoreApplication::translate("QbsProjectManager", "Profiles"));
|
|
|
|
|
setCategory(Constants::QBS_SETTINGS_CATEGORY);
|
2014-10-31 14:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *QbsProfilesSettingsPage::widget()
|
|
|
|
|
{
|
|
|
|
|
if (!m_widget)
|
|
|
|
|
m_widget = new QbsProfilesSettingsWidget;
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QbsProfilesSettingsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
delete m_widget;
|
2018-07-27 12:10:20 +02:00
|
|
|
m_widget = nullptr;
|
2014-10-31 14:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-21 08:09:35 +01:00
|
|
|
QbsProfilesSettingsWidget::QbsProfilesSettingsWidget()
|
2014-10-31 14:51:55 +01:00
|
|
|
{
|
|
|
|
|
m_ui.setupUi(this);
|
2019-06-28 14:30:32 +02:00
|
|
|
connect(QbsProfileManager::instance(), &QbsProfileManager::qbsProfilesUpdated,
|
2014-10-31 14:51:55 +01:00
|
|
|
this, &QbsProfilesSettingsWidget::refreshKitsList);
|
2016-06-28 23:29:21 +03:00
|
|
|
connect(m_ui.expandButton, &QAbstractButton::clicked,
|
|
|
|
|
m_ui.propertiesView, &QTreeView::expandAll);
|
|
|
|
|
connect(m_ui.collapseButton, &QAbstractButton::clicked,
|
|
|
|
|
m_ui.propertiesView, &QTreeView::collapseAll);
|
2014-10-31 14:51:55 +01:00
|
|
|
refreshKitsList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QbsProfilesSettingsWidget::refreshKitsList()
|
|
|
|
|
{
|
|
|
|
|
m_ui.kitsComboBox->disconnect(this);
|
2018-07-27 12:10:20 +02:00
|
|
|
m_ui.propertiesView->setModel(nullptr);
|
2014-10-31 14:51:55 +01:00
|
|
|
m_model.reload();
|
|
|
|
|
m_ui.profileValueLabel->clear();
|
2020-08-25 12:07:49 +02:00
|
|
|
Utils::Id currentId;
|
2014-10-31 14:51:55 +01:00
|
|
|
if (m_ui.kitsComboBox->count() > 0)
|
2020-08-25 12:07:49 +02:00
|
|
|
currentId = Utils::Id::fromSetting(m_ui.kitsComboBox->currentData());
|
2014-10-31 14:51:55 +01:00
|
|
|
m_ui.kitsComboBox->clear();
|
|
|
|
|
int newCurrentIndex = -1;
|
2019-06-28 14:30:32 +02:00
|
|
|
QList<Kit *> validKits = KitManager::kits();
|
|
|
|
|
Utils::erase(validKits, [](const Kit *k) { return !k->isValid(); });
|
2014-10-31 14:51:55 +01:00
|
|
|
const bool hasKits = !validKits.isEmpty();
|
2019-06-28 14:30:32 +02:00
|
|
|
for (const Kit * const kit : qAsConst(validKits)) {
|
2014-10-31 14:51:55 +01:00
|
|
|
if (kit->id() == currentId)
|
|
|
|
|
newCurrentIndex = m_ui.kitsComboBox->count();
|
|
|
|
|
m_ui.kitsComboBox->addItem(kit->displayName(), kit->id().toSetting());
|
|
|
|
|
}
|
|
|
|
|
if (newCurrentIndex != -1)
|
|
|
|
|
m_ui.kitsComboBox->setCurrentIndex(newCurrentIndex);
|
|
|
|
|
else if (hasKits)
|
|
|
|
|
m_ui.kitsComboBox->setCurrentIndex(0);
|
|
|
|
|
displayCurrentProfile();
|
2016-06-28 23:29:21 +03:00
|
|
|
connect(m_ui.kitsComboBox,
|
2019-02-26 09:40:49 +01:00
|
|
|
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
2016-06-28 23:29:21 +03:00
|
|
|
this, &QbsProfilesSettingsWidget::displayCurrentProfile);
|
2014-10-31 14:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QbsProfilesSettingsWidget::displayCurrentProfile()
|
|
|
|
|
{
|
2018-07-27 12:10:20 +02:00
|
|
|
m_ui.propertiesView->setModel(nullptr);
|
2014-10-31 14:51:55 +01:00
|
|
|
if (m_ui.kitsComboBox->currentIndex() == -1)
|
|
|
|
|
return;
|
2020-08-25 12:07:49 +02:00
|
|
|
const Utils::Id kitId = Utils::Id::fromSetting(m_ui.kitsComboBox->currentData());
|
2019-06-28 14:30:32 +02:00
|
|
|
const Kit * const kit = KitManager::kit(kitId);
|
2014-11-24 15:43:48 +01:00
|
|
|
QTC_ASSERT(kit, return);
|
2019-12-05 15:15:35 +01:00
|
|
|
const QString profileName = QbsProfileManager::ensureProfileForKit(kit);
|
2014-10-31 14:51:55 +01:00
|
|
|
m_ui.profileValueLabel->setText(profileName);
|
|
|
|
|
for (int i = 0; i < m_model.rowCount(); ++i) {
|
2019-06-28 14:30:32 +02:00
|
|
|
const QModelIndex currentProfileIndex = m_model.index(i, 0);
|
|
|
|
|
if (m_model.data(currentProfileIndex, Qt::DisplayRole).toString() != profileName)
|
2014-10-31 14:51:55 +01:00
|
|
|
continue;
|
2019-06-28 14:30:32 +02:00
|
|
|
m_ui.propertiesView->setModel(&m_model);
|
|
|
|
|
m_ui.propertiesView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
m_ui.propertiesView->setRootIndex(currentProfileIndex);
|
|
|
|
|
return;
|
2014-10-31 14:51:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QbsProjectManager
|
|
|
|
|
|
|
|
|
|
#include "qbsprofilessettingspage.moc"
|