Commit 4a9130a0 authored by Tobias Hunger's avatar Tobias Hunger

KitInformation: Make validate work on const Kits and add fix method

Make sure validate will not modify kits, add a fix method to do that
when kits are loaded/added.

Change-Id: Ib378af0f3470b2caf64177b35fca061089ac4523
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 837d7bfc
......@@ -62,7 +62,7 @@ public:
QVariant defaultValue(ProjectExplorer::Kit *k) const
{ return DebuggerKitInformation::itemToVariant(DebuggerKitInformation::autoDetectItem(k)); }
QList<ProjectExplorer::Task> validate(ProjectExplorer::Kit *k) const
QList<ProjectExplorer::Task> validate(const ProjectExplorer::Kit *k) const
{ return DebuggerKitInformation::validateDebugger(k); }
static QList<ProjectExplorer::Task> validateDebugger(const ProjectExplorer::Kit *k);
......
......@@ -151,7 +151,7 @@ bool Kit::isValid() const
return d->m_id.isValid() && d->m_isValid;
}
QList<Task> Kit::validate()
QList<Task> Kit::validate() const
{
QList<Task> result;
QList<KitInformation *> infoList = KitManager::instance()->kitInformation();
......
......@@ -59,7 +59,7 @@ public:
~Kit();
bool isValid() const;
QList<Task> validate();
QList<Task> validate() const;
QString displayName() const;
void setDisplayName(const QString &name);
......
......@@ -76,7 +76,7 @@ QVariant SysRootKitInformation::defaultValue(Kit *k) const
return QString();
}
QList<Task> SysRootKitInformation::validate(Kit *k) const
QList<Task> SysRootKitInformation::validate(const Kit *k) const
{
QList<Task> result;
const Utils::FileName dir = SysRootKitInformation::sysRoot(k);
......@@ -160,19 +160,26 @@ QVariant ToolChainKitInformation::defaultValue(Kit *k) const
return tcList.at(0)->id();
}
QList<Task> ToolChainKitInformation::validate(Kit *k) const
QList<Task> ToolChainKitInformation::validate(const Kit *k) const
{
QList<Task> result;
if (!toolChain(k)) {
qWarning("Tool chain is no longer known, removing from kit \"%s\".",
qPrintable(k->displayName()));
setToolChain(k, 0); // make sure to clear out no longer known tool chains
result << Task(Task::Error, ToolChainKitInformation::msgNoToolChainInTarget(),
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
}
return result;
}
void ToolChainKitInformation::fix(Kit *k)
{
if (toolChain(k))
return;
qWarning("Tool chain is no longer known, removing from kit \"%s\".",
qPrintable(k->displayName()));
setToolChain(k, 0); // make sure to clear out no longer known tool chains
}
KitConfigWidget *ToolChainKitInformation::createConfigWidget(Kit *k) const
{
Q_ASSERT(k);
......@@ -256,7 +263,7 @@ QVariant DeviceTypeKitInformation::defaultValue(Kit *k) const
return QByteArray(Constants::DESKTOP_DEVICE_TYPE);
}
QList<Task> DeviceTypeKitInformation::validate(Kit *k) const
QList<Task> DeviceTypeKitInformation::validate(const Kit *k) const
{
IDevice::ConstPtr dev = DeviceKitInformation::device(k);
QList<Task> result;
......@@ -333,13 +340,23 @@ QVariant DeviceKitInformation::defaultValue(Kit *k) const
return QByteArray(Constants::DESKTOP_DEVICE_ID);
}
QList<Task> DeviceKitInformation::validate(Kit *k) const
QList<Task> DeviceKitInformation::validate(const Kit *k) const
{
Q_UNUSED(k);
QList<Task> result;
return result;
}
void DeviceKitInformation::fix(Kit *k)
{
IDevice::ConstPtr dev = DeviceKitInformation::device(k);
if (!dev.isNull())
return;
const QString id = defaultValue(k).toString();
setDeviceId(k, id.isEmpty() ? Core::Id() : Core::Id(id));
}
KitConfigWidget *DeviceKitInformation::createConfigWidget(Kit *k) const
{
Q_ASSERT(k);
......
......@@ -60,7 +60,7 @@ public:
QVariant defaultValue(Kit *k) const;
QList<Task> validate(Kit *k) const;
QList<Task> validate(const Kit *k) const;
KitConfigWidget *createConfigWidget(Kit *k) const;
......@@ -102,7 +102,8 @@ public:
QVariant defaultValue(Kit *k) const;
QList<Task> validate(Kit *k) const;
QList<Task> validate(const Kit *k) const;
void fix(Kit *k);
KitConfigWidget *createConfigWidget(Kit *k) const;
......@@ -149,7 +150,7 @@ public:
QVariant defaultValue(Kit *k) const;
QList<Task> validate(Kit *k) const;
QList<Task> validate(const Kit *k) const;
KitConfigWidget *createConfigWidget(Kit *k) const;
......@@ -193,7 +194,8 @@ public:
QVariant defaultValue(Kit *k) const;
QList<Task> validate(Kit *k) const;
QList<Task> validate(const Kit *k) const;
void fix(Kit *k);
KitConfigWidget *createConfigWidget(Kit *k) const;
......
......@@ -247,6 +247,8 @@ void KitManager::registerKitInformation(KitInformation *ki)
foreach (Kit *k, kits()) {
if (!k->hasValue(ki->dataId()))
k->setValue(ki->dataId(), ki->defaultValue(k));
else
ki->fix(k);
}
return;
......@@ -357,9 +359,6 @@ QList<KitInformation *> KitManager::kitInformation() const
Internal::KitManagerConfigWidget *KitManager::createConfigWidget(Kit *k) const
{
if (!k)
return 0;
Internal::KitManagerConfigWidget *result = new Internal::KitManagerConfigWidget(k);
foreach (KitInformation *ki, d->m_informationList)
result->addConfigWidget(ki->createConfigWidget(k));
......@@ -437,6 +436,14 @@ void KitManager::addKit(Kit *k)
{
if (!k)
return;
foreach (KitInformation *ki, d->m_informationList) {
if (!k->hasValue(ki->dataId()))
k->setValue(ki->dataId(), ki->defaultValue(k));
else
ki->fix(k);
}
k->setDisplayName(k->displayName()); // make name unique
d->m_kitList.append(k);
if (!d->m_defaultKit ||
......
......@@ -74,7 +74,8 @@ public:
virtual bool visibleIn(Kit *) { return true; }
virtual QVariant defaultValue(Kit *) const = 0;
virtual QList<Task> validate(Kit *) const = 0;
virtual QList<Task> validate(const Kit *) const = 0;
virtual void fix(Kit *) { return; }
virtual ItemList toUserOutput(Kit *) const = 0;
......
......@@ -64,7 +64,7 @@ QVariant QmakeKitInformation::defaultValue(ProjectExplorer::Kit *k) const
return QString();
}
QList<ProjectExplorer::Task> QmakeKitInformation::validate(ProjectExplorer::Kit *k) const
QList<ProjectExplorer::Task> QmakeKitInformation::validate(const ProjectExplorer::Kit *k) const
{
QList<ProjectExplorer::Task> result;
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k);
......
......@@ -49,7 +49,7 @@ public:
QVariant defaultValue(ProjectExplorer::Kit *k) const;
QList<ProjectExplorer::Task> validate(ProjectExplorer::Kit *k) const;
QList<ProjectExplorer::Task> validate(const ProjectExplorer::Kit *k) const;
ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const;
......
......@@ -84,19 +84,21 @@ QVariant QtKitInformation::defaultValue(ProjectExplorer::Kit *k) const
return -1;
}
QList<ProjectExplorer::Task> QtKitInformation::validate(ProjectExplorer::Kit *k) const
QList<ProjectExplorer::Task> QtKitInformation::validate(const ProjectExplorer::Kit *k) const
{
int id = qtVersionId(k);
if (id == -1)
return QList<ProjectExplorer::Task>();
BaseQtVersion *version = QtVersionManager::instance()->version(id);
if (!version) {
setQtVersionId(k, -1);
BaseQtVersion *version = qtVersion(k);
if (!version)
return QList<ProjectExplorer::Task>();
}
return version->validateKit(k);
}
void QtKitInformation::fix(ProjectExplorer::Kit *k)
{
BaseQtVersion *version = qtVersion(k);
if (!version)
setQtVersionId(k, -1);
}
ProjectExplorer::KitConfigWidget *QtKitInformation::createConfigWidget(ProjectExplorer::Kit *k) const
{
return new Internal::QtKitConfigWidget(k);
......
......@@ -51,7 +51,8 @@ public:
QVariant defaultValue(ProjectExplorer::Kit *k) const;
QList<ProjectExplorer::Task> validate(ProjectExplorer::Kit *k) const;
QList<ProjectExplorer::Task> validate(const ProjectExplorer::Kit *k) const;
void fix(ProjectExplorer::Kit *);
ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment