forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user