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"
|
|
|
|
|
|
|
|
|
|
#include "qbsprojectmanager.h"
|
2016-10-25 17:14:28 +02:00
|
|
|
#include "qbsprojectmanagerconstants.h"
|
2016-02-22 17:49:02 +01:00
|
|
|
#include "qbsprojectmanagersettings.h"
|
2014-10-31 14:51:55 +01:00
|
|
|
|
2017-08-29 11:48:48 +02:00
|
|
|
#include <app/app_version.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>
|
2014-10-31 14:51:55 +01:00
|
|
|
#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:
|
2018-07-27 12:10:20 +02:00
|
|
|
QbsProfilesSettingsWidget(QWidget *parent = nullptr);
|
2014-10-31 14:51:55 +01:00
|
|
|
|
2016-02-22 17:49:02 +01:00
|
|
|
void apply();
|
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;
|
|
|
|
|
qbs::SettingsModel m_model;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QbsProfilesSettingsPage::QbsProfilesSettingsPage(QObject *parent)
|
2016-02-22 17:49:02 +01:00
|
|
|
: Core::IOptionsPage(parent)
|
|
|
|
|
, m_useQtcSettingsDirPersistent(QbsProjectManagerSettings::useCreatorSettingsDirForQbs())
|
|
|
|
|
|
2014-10-31 14:51:55 +01:00
|
|
|
{
|
2017-06-15 15:42:33 -07:00
|
|
|
setId("Y.QbsProfiles");
|
|
|
|
|
setDisplayName(QCoreApplication::translate("QbsProjectManager", "Qbs"));
|
2017-09-15 16:40:31 +02:00
|
|
|
setCategory(ProjectExplorer::Constants::KITS_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::apply()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget)
|
2016-02-22 17:49:02 +01:00
|
|
|
m_widget->apply();
|
|
|
|
|
m_useQtcSettingsDirPersistent = QbsProjectManagerSettings::useCreatorSettingsDirForQbs();
|
2014-10-31 14:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QbsProfilesSettingsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
delete m_widget;
|
2018-07-27 12:10:20 +02:00
|
|
|
m_widget = nullptr;
|
2016-02-22 17:49:02 +01:00
|
|
|
QbsProjectManagerSettings::setUseCreatorSettingsDirForQbs(m_useQtcSettingsDirPersistent);
|
|
|
|
|
QbsProjectManagerSettings::writeSettings();
|
2014-10-31 14:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QbsProfilesSettingsWidget::QbsProfilesSettingsWidget(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
2018-06-01 13:08:48 +02:00
|
|
|
, m_model(QbsProjectManagerSettings::qbsSettingsBaseDir(), qbs::Settings::UserScope)
|
2014-10-31 14:51:55 +01:00
|
|
|
{
|
|
|
|
|
m_model.setEditable(false);
|
|
|
|
|
m_ui.setupUi(this);
|
2017-08-29 11:48:48 +02:00
|
|
|
m_ui.settingsDirCheckBox->setText(tr("Store profiles in %1 settings directory")
|
|
|
|
|
.arg(Core::Constants::IDE_DISPLAY_NAME));
|
2016-02-22 17:49:02 +01:00
|
|
|
m_ui.settingsDirCheckBox->setChecked(QbsProjectManagerSettings::useCreatorSettingsDirForQbs());
|
2018-01-22 16:45:49 +01:00
|
|
|
m_ui.versionValueLabel->setText(qbs::LanguageInfo::qbsVersion().toString());
|
2014-10-31 14:51:55 +01:00
|
|
|
connect(ProjectExplorer::KitManager::instance(), &ProjectExplorer::KitManager::kitsChanged,
|
|
|
|
|
this, &QbsProfilesSettingsWidget::refreshKitsList);
|
2016-02-22 17:49:02 +01:00
|
|
|
connect(m_ui.settingsDirCheckBox, &QCheckBox::stateChanged, [this]() {
|
|
|
|
|
QbsProjectManagerSettings::setUseCreatorSettingsDirForQbs(m_ui.settingsDirCheckBox->isChecked());
|
|
|
|
|
m_model.updateSettingsDir(QbsProjectManagerSettings::qbsSettingsBaseDir());
|
|
|
|
|
displayCurrentProfile();
|
|
|
|
|
});
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 17:49:02 +01:00
|
|
|
void QbsProfilesSettingsWidget::apply()
|
2014-10-31 14:51:55 +01:00
|
|
|
{
|
|
|
|
|
m_model.reload();
|
|
|
|
|
displayCurrentProfile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
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();
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
const Core::Id kitId = Core::Id::fromSetting(m_ui.kitsComboBox->currentData());
|
2017-01-11 17:25:58 +01:00
|
|
|
const ProjectExplorer::Kit * const kit = ProjectExplorer::KitManager::kit(kitId);
|
2014-11-24 15:43:48 +01:00
|
|
|
QTC_ASSERT(kit, return);
|
2018-02-01 17:25:14 +01:00
|
|
|
const QString profileName = QbsManager::profileForKit(kit);
|
2014-10-31 14:51:55 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QbsProjectManager
|
|
|
|
|
|
|
|
|
|
#include "qbsprofilessettingspage.moc"
|