Commit d3c299cb authored by hjk's avatar hjk
Browse files

ProjectExplorer: Streamline ToolchainFactory interface



Change-Id: I70dba496c4d1eeb9c6767080d179f86f20c1b107
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent bf6685bc
......@@ -243,18 +243,10 @@ AndroidToolChainConfigWidget::AndroidToolChainConfigWidget(AndroidToolChain *tc)
// ToolChainFactory
// --------------------------------------------------------------------------
AndroidToolChainFactory::AndroidToolChainFactory() :
ToolChainFactory()
{ }
QString AndroidToolChainFactory::displayName() const
{
return tr("Android GCC");
}
QString AndroidToolChainFactory::id() const
AndroidToolChainFactory::AndroidToolChainFactory()
{
return QLatin1String(Constants::ANDROID_TOOLCHAIN_ID);
setId(Constants::ANDROID_TOOLCHAIN_ID);
setDisplayName(tr("Android GCC"));
}
QList<ToolChain *> AndroidToolChainFactory::autoDetect()
......
......@@ -96,9 +96,6 @@ class AndroidToolChainFactory : public ProjectExplorer::ToolChainFactory
public:
AndroidToolChainFactory();
QString displayName() const;
QString id() const;
QList<ProjectExplorer::ToolChain *> autoDetect();
bool canRestore(const QVariantMap &data);
ProjectExplorer::ToolChain *restore(const QVariantMap &data);
......
......@@ -391,14 +391,10 @@ namespace Internal {
// CustomToolChainFactory
// --------------------------------------------------------------------------
QString CustomToolChainFactory::displayName() const
CustomToolChainFactory::CustomToolChainFactory()
{
return tr("Custom");
}
QString CustomToolChainFactory::id() const
{
return QLatin1String(Constants::CUSTOM_TOOLCHAIN_ID);
setId(Constants::CUSTOM_TOOLCHAIN_ID);
setDisplayName(tr("Custom"));
}
bool CustomToolChainFactory::canCreate()
......
......@@ -151,9 +151,7 @@ class CustomToolChainFactory : public ToolChainFactory
Q_OBJECT
public:
// Name used to display the name of the tool chain that will be created.
QString displayName() const;
QString id() const;
CustomToolChainFactory();
bool canCreate();
ToolChain *create();
......
......@@ -55,6 +55,8 @@ using namespace Utils;
namespace ProjectExplorer {
using namespace Internal;
// --------------------------------------------------------------------------
// Helpers:
// --------------------------------------------------------------------------
......@@ -371,7 +373,7 @@ QString GccToolChain::type() const
QString GccToolChain::typeDisplayName() const
{
return Internal::GccToolChainFactory::tr("GCC");
return GccToolChainFactory::tr("GCC");
}
Abi GccToolChain::targetAbi() const
......@@ -734,7 +736,7 @@ bool GccToolChain::operator ==(const ToolChain &other) const
ToolChainConfigWidget *GccToolChain::configurationWidget()
{
return new Internal::GccToolChainConfigWidget(this);
return new GccToolChainConfigWidget(this);
}
void GccToolChain::updateSupportedAbis() const
......@@ -761,27 +763,23 @@ QString GccToolChain::detectVersion() const
// GccToolChainFactory
// --------------------------------------------------------------------------
QString Internal::GccToolChainFactory::displayName() const
{
return tr("GCC");
}
QString Internal::GccToolChainFactory::id() const
GccToolChainFactory::GccToolChainFactory()
{
return QLatin1String(Constants::GCC_TOOLCHAIN_ID);
setId(Constants::GCC_TOOLCHAIN_ID);
setDisplayName(tr("GCC"));
}
bool Internal::GccToolChainFactory::canCreate()
bool GccToolChainFactory::canCreate()
{
return true;
}
ToolChain *Internal::GccToolChainFactory::create()
ToolChain *GccToolChainFactory::create()
{
return createToolChain(false);
}
QList<ToolChain *> Internal::GccToolChainFactory::autoDetect()
QList<ToolChain *> GccToolChainFactory::autoDetect()
{
QList<ToolChain *> tcs;
if (Utils::HostOsInfo::isMacHost()) {
......@@ -795,14 +793,14 @@ QList<ToolChain *> Internal::GccToolChainFactory::autoDetect()
}
// Used by the ToolChainManager to restore user-generated tool chains
bool Internal::GccToolChainFactory::canRestore(const QVariantMap &data)
bool GccToolChainFactory::canRestore(const QVariantMap &data)
{
const QString id = idFromMap(data);
return id.startsWith(QLatin1String(Constants::GCC_TOOLCHAIN_ID) + QLatin1Char(':'))
|| id.startsWith(QLatin1String(LEGACY_MAEMO_ID));
}
ToolChain *Internal::GccToolChainFactory::restore(const QVariantMap &data)
ToolChain *GccToolChainFactory::restore(const QVariantMap &data)
{
GccToolChain *tc = new GccToolChain(false);
// Updating from 2.5:
......@@ -820,12 +818,12 @@ ToolChain *Internal::GccToolChainFactory::restore(const QVariantMap &data)
return 0;
}
GccToolChain *Internal::GccToolChainFactory::createToolChain(bool autoDetect)
GccToolChain *GccToolChainFactory::createToolChain(bool autoDetect)
{
return new GccToolChain(autoDetect);
}
QList<ToolChain *> Internal::GccToolChainFactory::autoDetectToolchains(const QString &compiler,
QList<ToolChain *> GccToolChainFactory::autoDetectToolchains(const QString &compiler,
const Abi &requiredAbi)
{
QList<ToolChain *> result;
......@@ -862,7 +860,7 @@ QList<ToolChain *> Internal::GccToolChainFactory::autoDetectToolchains(const QSt
// GccToolChainConfigWidget
// --------------------------------------------------------------------------
Internal::GccToolChainConfigWidget::GccToolChainConfigWidget(GccToolChain *tc) :
GccToolChainConfigWidget::GccToolChainConfigWidget(GccToolChain *tc) :
ToolChainConfigWidget(tc),
m_compilerCommand(new PathChooser),
m_abiWidget(new AbiWidget),
......@@ -894,7 +892,7 @@ Internal::GccToolChainConfigWidget::GccToolChainConfigWidget(GccToolChain *tc) :
connect(m_abiWidget, SIGNAL(abiChanged()), this, SIGNAL(dirty()));
}
void Internal::GccToolChainConfigWidget::applyImpl()
void GccToolChainConfigWidget::applyImpl()
{
if (toolChain()->isAutoDetected())
return;
......@@ -909,7 +907,7 @@ void Internal::GccToolChainConfigWidget::applyImpl()
tc->setPlatformLinkerFlags(splitString(m_platformLinkerFlagsLineEdit->text()));
}
void Internal::GccToolChainConfigWidget::setFromToolchain()
void GccToolChainConfigWidget::setFromToolchain()
{
// subwidgets are not yet connected!
bool blocked = blockSignals(true);
......@@ -923,7 +921,7 @@ void Internal::GccToolChainConfigWidget::setFromToolchain()
blockSignals(blocked);
}
bool Internal::GccToolChainConfigWidget::isDirtyImpl() const
bool GccToolChainConfigWidget::isDirtyImpl() const
{
GccToolChain *tc = static_cast<GccToolChain *>(toolChain());
Q_ASSERT(tc);
......@@ -933,14 +931,14 @@ bool Internal::GccToolChainConfigWidget::isDirtyImpl() const
|| m_abiWidget->currentAbi() != tc->targetAbi();
}
void Internal::GccToolChainConfigWidget::makeReadOnlyImpl()
void GccToolChainConfigWidget::makeReadOnlyImpl()
{
m_compilerCommand->setEnabled(false);
m_abiWidget->setEnabled(false);
m_isReadOnly = true;
}
QStringList Internal::GccToolChainConfigWidget::splitString(const QString &s)
QStringList GccToolChainConfigWidget::splitString(const QString &s)
{
QtcProcess::SplitError splitError;
QStringList res = QtcProcess::splitArgs(s, false, &splitError);
......@@ -955,7 +953,7 @@ QStringList Internal::GccToolChainConfigWidget::splitString(const QString &s)
return res;
}
void Internal::GccToolChainConfigWidget::handleCompilerCommandChange()
void GccToolChainConfigWidget::handleCompilerCommandChange()
{
FileName path = m_compilerCommand->fileName();
QList<Abi> abiList;
......@@ -973,7 +971,7 @@ void Internal::GccToolChainConfigWidget::handleCompilerCommandChange()
emit dirty();
}
void Internal::GccToolChainConfigWidget::handlePlatformCodeGenFlagsChange()
void GccToolChainConfigWidget::handlePlatformCodeGenFlagsChange()
{
QString str1 = m_platformCodeGenFlagsLineEdit->text();
QString str2 = QtcProcess::joinArgs(splitString(str1));
......@@ -983,7 +981,7 @@ void Internal::GccToolChainConfigWidget::handlePlatformCodeGenFlagsChange()
handleCompilerCommandChange();
}
void Internal::GccToolChainConfigWidget::handlePlatformLinkerFlagsChange()
void GccToolChainConfigWidget::handlePlatformLinkerFlagsChange()
{
QString str1 = m_platformLinkerFlagsLineEdit->text();
QString str2 = QtcProcess::joinArgs(splitString(str1));
......@@ -1008,7 +1006,7 @@ QString ClangToolChain::type() const
QString ClangToolChain::typeDisplayName() const
{
return Internal::ClangToolChainFactory::tr("Clang");
return ClangToolChainFactory::tr("Clang");
}
QString ClangToolChain::makeCommand(const Utils::Environment &environment) const
......@@ -1097,38 +1095,34 @@ ToolChain *ClangToolChain::clone() const
// ClangToolChainFactory
// --------------------------------------------------------------------------
QString Internal::ClangToolChainFactory::displayName() const
{
return tr("Clang");
}
QString Internal::ClangToolChainFactory::id() const
ClangToolChainFactory::ClangToolChainFactory()
{
return QLatin1String(Constants::CLANG_TOOLCHAIN_ID);
setDisplayName(tr("Clang"));
setId(Constants::CLANG_TOOLCHAIN_ID);
}
QList<ToolChain *> Internal::ClangToolChainFactory::autoDetect()
QList<ToolChain *> ClangToolChainFactory::autoDetect()
{
Abi ha = Abi::hostAbi();
return autoDetectToolchains(QLatin1String("clang++"), ha);
}
bool Internal::ClangToolChainFactory::canCreate()
bool ClangToolChainFactory::canCreate()
{
return true;
}
ToolChain *Internal::ClangToolChainFactory::create()
ToolChain *ClangToolChainFactory::create()
{
return createToolChain(false);
}
bool Internal::ClangToolChainFactory::canRestore(const QVariantMap &data)
bool ClangToolChainFactory::canRestore(const QVariantMap &data)
{
return idFromMap(data).startsWith(QLatin1String(Constants::CLANG_TOOLCHAIN_ID) + QLatin1Char(':'));
}
ToolChain *Internal::ClangToolChainFactory::restore(const QVariantMap &data)
ToolChain *ClangToolChainFactory::restore(const QVariantMap &data)
{
ClangToolChain *tc = new ClangToolChain(false);
if (tc->fromMap(data))
......@@ -1138,7 +1132,7 @@ ToolChain *Internal::ClangToolChainFactory::restore(const QVariantMap &data)
return 0;
}
GccToolChain *Internal::ClangToolChainFactory::createToolChain(bool autoDetect)
GccToolChain *ClangToolChainFactory::createToolChain(bool autoDetect)
{
return new ClangToolChain(autoDetect);
}
......@@ -1158,7 +1152,7 @@ QString MingwToolChain::type() const
QString MingwToolChain::typeDisplayName() const
{
return Internal::MingwToolChainFactory::tr("MinGW");
return MingwToolChainFactory::tr("MinGW");
}
QList<FileName> MingwToolChain::suggestedMkspecList() const
......@@ -1206,39 +1200,35 @@ ToolChain *MingwToolChain::clone() const
// MingwToolChainFactory
// --------------------------------------------------------------------------
QString Internal::MingwToolChainFactory::displayName() const
MingwToolChainFactory::MingwToolChainFactory()
{
return tr("MinGW");
setId(Constants::MINGW_TOOLCHAIN_ID);
setDisplayName(tr("MinGW"));
}
QString Internal::MingwToolChainFactory::id() const
{
return QLatin1String(Constants::MINGW_TOOLCHAIN_ID);
}
QList<ToolChain *> Internal::MingwToolChainFactory::autoDetect()
QList<ToolChain *> MingwToolChainFactory::autoDetect()
{
Abi ha = Abi::hostAbi();
return autoDetectToolchains(QLatin1String("g++"),
Abi(ha.architecture(), Abi::WindowsOS, Abi::WindowsMSysFlavor, Abi::PEFormat, ha.wordWidth()));
}
bool Internal::MingwToolChainFactory::canCreate()
bool MingwToolChainFactory::canCreate()
{
return true;
}
ToolChain *Internal::MingwToolChainFactory::create()
ToolChain *MingwToolChainFactory::create()
{
return createToolChain(false);
}
bool Internal::MingwToolChainFactory::canRestore(const QVariantMap &data)
bool MingwToolChainFactory::canRestore(const QVariantMap &data)
{
return idFromMap(data).startsWith(QLatin1String(Constants::MINGW_TOOLCHAIN_ID) + QLatin1Char(':'));
}
ToolChain *Internal::MingwToolChainFactory::restore(const QVariantMap &data)
ToolChain *MingwToolChainFactory::restore(const QVariantMap &data)
{
MingwToolChain *tc = new MingwToolChain(false);
if (tc->fromMap(data))
......@@ -1248,7 +1238,7 @@ ToolChain *Internal::MingwToolChainFactory::restore(const QVariantMap &data)
return 0;
}
GccToolChain *Internal::MingwToolChainFactory::createToolChain(bool autoDetect)
GccToolChain *MingwToolChainFactory::createToolChain(bool autoDetect)
{
return new MingwToolChain(autoDetect);
}
......@@ -1268,7 +1258,7 @@ QString LinuxIccToolChain::type() const
QString LinuxIccToolChain::typeDisplayName() const
{
return Internal::LinuxIccToolChainFactory::tr("Linux ICC");
return LinuxIccToolChainFactory::tr("Linux ICC");
}
/**
......@@ -1313,32 +1303,28 @@ ToolChain *LinuxIccToolChain::clone() const
// LinuxIccToolChainFactory
// --------------------------------------------------------------------------
QString Internal::LinuxIccToolChainFactory::displayName() const
{
return tr("Linux ICC");
}
QString Internal::LinuxIccToolChainFactory::id() const
LinuxIccToolChainFactory::LinuxIccToolChainFactory()
{
return QLatin1String(Constants::LINUXICC_TOOLCHAIN_ID);
setDisplayName(tr("Linux ICC"));
setId(Constants::LINUXICC_TOOLCHAIN_ID);
}
QList<ToolChain *> Internal::LinuxIccToolChainFactory::autoDetect()
QList<ToolChain *> LinuxIccToolChainFactory::autoDetect()
{
return autoDetectToolchains(QLatin1String("icpc"), Abi::hostAbi());
}
ToolChain *Internal::LinuxIccToolChainFactory::create()
ToolChain *LinuxIccToolChainFactory::create()
{
return createToolChain(false);
}
bool Internal::LinuxIccToolChainFactory::canRestore(const QVariantMap &data)
bool LinuxIccToolChainFactory::canRestore(const QVariantMap &data)
{
return idFromMap(data).startsWith(QLatin1String(Constants::LINUXICC_TOOLCHAIN_ID) + QLatin1Char(':'));
}
ToolChain *Internal::LinuxIccToolChainFactory::restore(const QVariantMap &data)
ToolChain *LinuxIccToolChainFactory::restore(const QVariantMap &data)
{
LinuxIccToolChain *tc = new LinuxIccToolChain(false);
if (tc->fromMap(data))
......@@ -1348,7 +1334,7 @@ ToolChain *Internal::LinuxIccToolChainFactory::restore(const QVariantMap &data)
return 0;
}
GccToolChain *Internal::LinuxIccToolChainFactory::createToolChain(bool autoDetect)
GccToolChain *LinuxIccToolChainFactory::createToolChain(bool autoDetect)
{
return new LinuxIccToolChain(autoDetect);
}
......
......@@ -55,16 +55,13 @@ class GccToolChainFactory : public ToolChainFactory
Q_OBJECT
public:
// Name used to display the name of the tool chain that will be created.
QString displayName() const;
QString id() const;
GccToolChainFactory();
QList<ToolChain *> autoDetect();
bool canCreate();
ToolChain *create();
// Used by the ToolChainManager to restore user-generated tool chains
bool canRestore(const QVariantMap &data);
ToolChain *restore(const QVariantMap &data);
......@@ -116,16 +113,13 @@ class ClangToolChainFactory : public GccToolChainFactory
Q_OBJECT
public:
// Name used to display the name of the tool chain that will be created.
QString displayName() const;
QString id() const;
ClangToolChainFactory();
QList<ToolChain *> autoDetect();
bool canCreate();
ToolChain *create();
// Used by the ToolChainManager to restore user-generated tool chains
bool canRestore(const QVariantMap &data);
ToolChain *restore(const QVariantMap &data);
......@@ -142,16 +136,13 @@ class MingwToolChainFactory : public GccToolChainFactory
Q_OBJECT
public:
// Name used to display the name of the tool chain that will be created.
QString displayName() const;
QString id() const;
MingwToolChainFactory();
QList<ToolChain *> autoDetect();
bool canCreate();
ToolChain *create();
// Used by the ToolChainManager to restore user-generated tool chains
bool canRestore(const QVariantMap &data);
ToolChain *restore(const QVariantMap &data);
......@@ -168,15 +159,12 @@ class LinuxIccToolChainFactory : public GccToolChainFactory
Q_OBJECT
public:
// Name used to display the name of the tool chain that will be created.
QString displayName() const;
QString id() const;
LinuxIccToolChainFactory();
QList<ToolChain *> autoDetect();
ToolChain *create();
// Used by the ToolChainManager to restore user-generated tool chains
bool canRestore(const QVariantMap &data);
ToolChain *restore(const QVariantMap &data);
......
......@@ -429,14 +429,10 @@ void MsvcToolChainConfigWidget::setFromToolChain()
// MsvcToolChainFactory
// --------------------------------------------------------------------------
QString MsvcToolChainFactory::displayName() const
MsvcToolChainFactory::MsvcToolChainFactory()
{
return tr("MSVC");
}
QString MsvcToolChainFactory::id() const
{
return QLatin1String(Constants::MSVC_TOOLCHAIN_ID);
setId(Constants::MSVC_TOOLCHAIN_ID);
setDisplayName(tr("MSVC"));
}
bool MsvcToolChainFactory::checkForVisualStudioInstallation(const QString &vsName)
......
......@@ -94,13 +94,12 @@ class MsvcToolChainFactory : public ToolChainFactory
Q_OBJECT
public:
QString displayName() const;
QString id() const;
MsvcToolChainFactory();
QList<ToolChain *> autoDetect();
virtual bool canRestore(const QVariantMap &data);
virtual ToolChain *restore(const QVariantMap &data)
bool canRestore(const QVariantMap &data);
ToolChain *restore(const QVariantMap &data)
{ return MsvcToolChain::readFromMap(data); }
ToolChainConfigWidget *configurationWidget(ToolChain *);
......
......@@ -31,6 +31,7 @@
#define TOOLCHAIN_H
#include "projectexplorer_export.h"
#include <coreplugin/id.h>
#include <QObject>
#include <QString>
......@@ -167,8 +168,8 @@ class PROJECTEXPLORER_EXPORT ToolChainFactory : public QObject
Q_OBJECT
public:
virtual QString displayName() const = 0;
virtual QString id() const = 0;
Core::Id id() const { return m_id; }
QString displayName() const { return m_displayName; }
virtual QList<ToolChain *> autoDetect();
......@@ -181,6 +182,14 @@ public:
static QString idFromMap(const QVariantMap &data);
static void idToMap(QVariantMap &data, const QString id);
static void autoDetectionToMap(QVariantMap &data, bool detected);
protected:
void setId(Core::Id id) { m_id = id; }
void setDisplayName(const QString &name) { m_displayName = name; }
private:
QString m_displayName;
Core::Id m_id;
};
} // namespace ProjectExplorer
......
......@@ -351,14 +351,10 @@ ToolChain *WinCEToolChain::clone() const
// WinCEToolChainFactory
// --------------------------------------------------------------------------
QString WinCEToolChainFactory::displayName() const
WinCEToolChainFactory::WinCEToolChainFactory()
{
return tr("WinCE");
}
QString WinCEToolChainFactory::id() const
{
return QLatin1String(Constants::WINCE_TOOLCHAIN_ID);
setId(Constants::WINCE_TOOLCHAIN_ID);
setDisplayName(tr("WinCE"));
}
......
......@@ -104,8 +104,7 @@ class WinCEToolChainFactory : public ToolChainFactory
Q_OBJECT
public:
QString displayName() const;
QString id() const;
WinCEToolChainFactory();
QList<ToolChain *> autoDetect();
......
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