Commit 6d817307 authored by Tobias Hunger's avatar Tobias Hunger

ToolChainFactory: Add typeIdFromMap and use it in factories

Change-Id: Id3254bcb3a5c426540bbab49dc61545031af6826
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent 468337c5
......@@ -271,7 +271,7 @@ QList<ToolChain *> AndroidToolChainFactory::autoDetect()
bool AndroidToolChainFactory::canRestore(const QVariantMap &data)
{
return idFromMap(data).startsWith(QByteArray(Constants::ANDROID_TOOLCHAIN_ID) + ':');
return typeIdFromMap(data) == Constants::ANDROID_TOOLCHAIN_ID;
}
ToolChain *AndroidToolChainFactory::restore(const QVariantMap &data)
......
......@@ -394,8 +394,7 @@ ToolChain *CustomToolChainFactory::create()
// Used by the ToolChainManager to restore user-generated tool chains
bool CustomToolChainFactory::canRestore(const QVariantMap &data)
{
const QByteArray id = idFromMap(data);
return id.startsWith(QByteArray(Constants::CUSTOM_TOOLCHAIN_ID) + ':');
return typeIdFromMap(data) == Constants::CUSTOM_TOOLCHAIN_ID;
}
ToolChain *CustomToolChainFactory::restore(const QVariantMap &data)
......
......@@ -795,8 +795,7 @@ QList<ToolChain *> GccToolChainFactory::autoDetect()
// Used by the ToolChainManager to restore user-generated tool chains
bool GccToolChainFactory::canRestore(const QVariantMap &data)
{
const QByteArray id = idFromMap(data);
return id.startsWith(QByteArray(Constants::GCC_TOOLCHAIN_ID) + ':');
return typeIdFromMap(data) == Constants::GCC_TOOLCHAIN_ID;
}
ToolChain *GccToolChainFactory::restore(const QVariantMap &data)
......@@ -1139,7 +1138,7 @@ ToolChain *ClangToolChainFactory::create()
bool ClangToolChainFactory::canRestore(const QVariantMap &data)
{
return idFromMap(data).startsWith(QByteArray(Constants::CLANG_TOOLCHAIN_ID) + ':');
return typeIdFromMap(data) == Constants::CLANG_TOOLCHAIN_ID;
}
ToolChain *ClangToolChainFactory::restore(const QVariantMap &data)
......@@ -1245,7 +1244,7 @@ ToolChain *MingwToolChainFactory::create()
bool MingwToolChainFactory::canRestore(const QVariantMap &data)
{
return idFromMap(data).startsWith(QByteArray(Constants::MINGW_TOOLCHAIN_ID) + ':');
return typeIdFromMap(data) == Constants::MINGW_TOOLCHAIN_ID;
}
ToolChain *MingwToolChainFactory::restore(const QVariantMap &data)
......@@ -1341,7 +1340,7 @@ ToolChain *LinuxIccToolChainFactory::create()
bool LinuxIccToolChainFactory::canRestore(const QVariantMap &data)
{
return idFromMap(data).startsWith(QByteArray(Constants::LINUXICC_TOOLCHAIN_ID) + ':');
return typeIdFromMap(data) == Constants::LINUXICC_TOOLCHAIN_ID;
}
ToolChain *LinuxIccToolChainFactory::restore(const QVariantMap &data)
......
......@@ -632,7 +632,7 @@ bool MsvcToolChain::operator ==(const ToolChain &other) const
bool MsvcToolChainFactory::canRestore(const QVariantMap &data)
{
return idFromMap(data).startsWith(QByteArray(Constants::MSVC_TOOLCHAIN_ID) + ':');
return typeIdFromMap(data) == Constants::MSVC_TOOLCHAIN_ID;
}
} // namespace Internal
......
......@@ -261,9 +261,22 @@ ToolChain *ToolChainFactory::restore(const QVariantMap &)
return 0;
}
static QPair<QString, QString> rawIdData(const QVariantMap &data)
{
const QString raw = data.value(QLatin1String(ID_KEY)).toString();
const int pos = raw.indexOf(QLatin1Char(':'));
QTC_ASSERT(pos > 0, return qMakePair(QString::fromLatin1("unknown"), QString::fromLatin1("unknown")));
return qMakePair(raw.mid(0, pos), raw.mid(pos + 1));
}
QByteArray ToolChainFactory::idFromMap(const QVariantMap &data)
{
return data.value(QLatin1String(ID_KEY)).toByteArray();
return rawIdData(data).second.toUtf8();
}
Core::Id ToolChainFactory::typeIdFromMap(const QVariantMap &data)
{
return Core::Id::fromString(rawIdData(data).first);
}
void ToolChainFactory::autoDetectionToMap(QVariantMap &data, bool detected)
......
......@@ -192,6 +192,7 @@ public:
virtual ToolChain *restore(const QVariantMap &data);
static QByteArray idFromMap(const QVariantMap &data);
static Core::Id typeIdFromMap(const QVariantMap &data);
static void autoDetectionToMap(QVariantMap &data, bool detected);
protected:
......
......@@ -161,9 +161,10 @@ static QList<ToolChain *> restoreFromFile(const FileName &fileName)
}
}
if (!restored)
qWarning("Warning: Unable to restore compiler '%s' stored in %s.",
qPrintable(QString::fromUtf8(ToolChainFactory::idFromMap(tcMap))),
qPrintable(fileName.toUserOutput()));
qWarning("Warning: '%s': Unable to restore compiler type '%s' for tool chain %s.",
qPrintable(fileName.toUserOutput()),
qPrintable(ToolChainFactory::typeIdFromMap(tcMap).toString()),
qPrintable(QString::fromUtf8(ToolChainFactory::idFromMap(tcMap))));
}
return result;
......
......@@ -432,7 +432,7 @@ QString WinCEToolChain::autoDetectCdbDebugger(QStringList *checkedDirectories /*
bool WinCEToolChainFactory::canRestore(const QVariantMap &data)
{
return idFromMap(data).startsWith(QByteArray(Constants::WINCE_TOOLCHAIN_ID) + ':');
return typeIdFromMap(data) == Constants::WINCE_TOOLCHAIN_ID;
}
bool WinCEToolChain::operator ==(const ToolChain &other) const
......
......@@ -163,8 +163,7 @@ QnxToolChainFactory::QnxToolChainFactory()
bool QnxToolChainFactory::canRestore(const QVariantMap &data)
{
const QByteArray id = idFromMap(data);
return id.startsWith(QByteArray(Constants::QNX_TOOLCHAIN_ID) + ':');
return typeIdFromMap(data) == Constants::QNX_TOOLCHAIN_ID;
}
ToolChain *QnxToolChainFactory::restore(const QVariantMap &data)
......
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