Commit 0224ec0a authored by Tobias Hunger's avatar Tobias Hunger

Kit: Add constructor to restore Kit from QVariantMap

Do not trust kits with an invalid id, as there is no way those
could have ended up being saved out by creator. Safe all other kits
that were constructed using Kit(const QVariantMap &).

This new constructor uses the code that used to be in fromMap(...),
with some simplifications.

Remove fromMap(...) method from kit as it is no longer used.

Change-Id: Iac28ea9b85670e03088a4b7c5283af6b4b70c0fc
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent b63f3f80
......@@ -80,6 +80,9 @@ public:
{
if (!id.isValid())
m_id = Id::fromString(QUuid::createUuid().toString());
m_displayName = QCoreApplication::translate("ProjectExplorer::Kit", "Unnamed");
m_iconPath = Utils::FileName::fromString(QLatin1String(":///DESKTOP///"));
}
QString m_displayName;
......@@ -112,11 +115,40 @@ Kit::Kit(Core::Id id) :
foreach (KitInformation *sti, KitManager::kitInformation())
d->m_data.insert(sti->id(), sti->defaultValue(this));
d->m_displayName = QCoreApplication::translate("ProjectExplorer::Kit", "Unnamed");
d->m_iconPath = Utils::FileName::fromString(QLatin1String(":///DESKTOP///"));
d->m_icon = icon(d->m_iconPath);
}
Kit::Kit(const QVariantMap &data) :
d(new Internal::KitPrivate(Core::Id()))
{
d->m_id = Id::fromSetting(data.value(QLatin1String(ID_KEY)));
d->m_autodetected = data.value(QLatin1String(AUTODETECTED_KEY)).toBool();
// if we don't have that setting assume that autodetected implies sdk
QVariant value = data.value(QLatin1String(SDK_PROVIDED_KEY));
if (value.isValid())
d->m_sdkProvided = value.toBool();
else
d->m_sdkProvided = d->m_autodetected;
d->m_displayName = data.value(QLatin1String(DISPLAYNAME_KEY),
d->m_displayName).toString();
d->m_iconPath = Utils::FileName::fromString(data.value(QLatin1String(ICON_KEY),
d->m_iconPath.toString()).toString());
d->m_icon = icon(d->m_iconPath);
QVariantMap extra = data.value(QLatin1String(DATA_KEY)).toMap();
d->m_data.clear(); // remove default values
const QVariantMap::ConstIterator cend = extra.constEnd();
for (QVariantMap::ConstIterator it = extra.constBegin(); it != cend; ++it)
d->m_data.insert(Id::fromString(it.key()), it.value());
QStringList mutableInfoList = data.value(QLatin1String(MUTABLE_INFO_KEY)).toStringList();
foreach (const QString &mutableInfo, mutableInfoList)
d->m_mutable.insert(Core::Id::fromString(mutableInfo));
}
Kit::~Kit()
{
delete d;
......@@ -459,39 +491,6 @@ QString Kit::toHtml() const
return rc;
}
bool Kit::fromMap(const QVariantMap &data)
{
KitGuard g(this);
Id id = Id::fromSetting(data.value(QLatin1String(ID_KEY)));
if (!id.isValid())
return false;
d->m_id = id;
d->m_autodetected = data.value(QLatin1String(AUTODETECTED_KEY)).toBool();
// if we don't have that setting assume that autodetected implies sdk
QVariant value = data.value(QLatin1String(SDK_PROVIDED_KEY));
if (value.isValid())
d->m_sdkProvided = value.toBool();
else
d->m_sdkProvided = d->m_autodetected;
d->m_displayName = data.value(QLatin1String(DISPLAYNAME_KEY)).toString();
d->m_iconPath = Utils::FileName::fromString(data.value(QLatin1String(ICON_KEY)).toString());
d->m_icon = icon(d->m_iconPath);
QVariantMap extra = data.value(QLatin1String(DATA_KEY)).toMap();
d->m_data.clear(); // remove default values
const QVariantMap::ConstIterator cend = extra.constEnd();
for (QVariantMap::ConstIterator it = extra.constBegin(); it != cend; ++it)
d->m_data.insert(Id::fromString(it.key()), it.value());
QStringList mutableInfoList = data.value(QLatin1String(MUTABLE_INFO_KEY)).toStringList();
foreach (const QString &mutableInfo, mutableInfoList) {
d->m_mutable.insert(Core::Id::fromString(mutableInfo));
}
return true;
}
void Kit::setAutoDetected(bool detected)
{
d->m_autodetected = detected;
......
......@@ -113,6 +113,7 @@ private:
void setSdkProvided(bool sdkProvided);
~Kit();
Kit(const QVariantMap &data);
// Unimplemented.
Kit(const Kit &other);
......@@ -122,7 +123,6 @@ private:
void kitUpdated();
QVariantMap toMap() const;
bool fromMap(const QVariantMap &value);
Internal::KitPrivate *const d;
......
......@@ -358,10 +358,11 @@ KitManager::KitList KitManager::restoreKits(const Utils::FileName &fileName)
const QVariantMap stMap = data.value(key).toMap();
Kit *k = new Kit;
if (k->fromMap(stMap)) {
Kit *k = new Kit(stMap);
if (k->id().isValid()) {
result.kits.append(k);
} else {
// If the Id is broken, then do not trust the rest of the data either.
delete k;
qWarning("Warning: Unable to restore kits stored in %s at position %d.",
qPrintable(fileName.toUserOutput()), i);
......@@ -493,6 +494,8 @@ void KitManager::notifyAboutUpdate(ProjectExplorer::Kit *k)
bool KitManager::registerKit(ProjectExplorer::Kit *k)
{
QTC_ASSERT(isLoaded(), return false);
QTC_ASSERT(k->id().isValid(), return false);
if (!k)
return true;
foreach (Kit *current, kits()) {
......
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