forked from qt-creator/qt-creator
QtSupport et al: Centralize QtVersionFactory::restore
Similar to the various types of project *ConfigurationFactory Change-Id: I7b721f127c8bcc13c7db6880d36c79dd091bc037 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -38,6 +38,7 @@ namespace Internal {
|
||||
AndroidQtVersionFactory::AndroidQtVersionFactory(QObject *parent)
|
||||
: QtSupport::QtVersionFactory(parent)
|
||||
{
|
||||
setQtVersionCreator([] { return new AndroidQtVersion; });
|
||||
}
|
||||
|
||||
bool AndroidQtVersionFactory::canRestore(const QString &type)
|
||||
@@ -45,15 +46,6 @@ bool AndroidQtVersionFactory::canRestore(const QString &type)
|
||||
return type == QLatin1String(Constants::ANDROIDQT);
|
||||
}
|
||||
|
||||
QtSupport::BaseQtVersion *AndroidQtVersionFactory::restore(const QString &type,
|
||||
const QVariantMap &data)
|
||||
{
|
||||
QTC_ASSERT(canRestore(type), return nullptr);
|
||||
auto v = new AndroidQtVersion;
|
||||
v->fromMap(data);
|
||||
return v;
|
||||
}
|
||||
|
||||
int AndroidQtVersionFactory::priority() const
|
||||
{
|
||||
return 90;
|
||||
|
@@ -36,7 +36,6 @@ public:
|
||||
explicit AndroidQtVersionFactory(QObject *parent = nullptr);
|
||||
|
||||
bool canRestore(const QString &type) override;
|
||||
QtSupport::BaseQtVersion *restore(const QString &type, const QVariantMap &data) override;
|
||||
|
||||
int priority() const override;
|
||||
QtSupport::BaseQtVersion *create(const Utils::FileName &qmakePath, ProFileEvaluator *evaluator,
|
||||
|
@@ -27,7 +27,6 @@
|
||||
#include "iosqtversion.h"
|
||||
#include "iosconstants.h"
|
||||
#include <qtsupport/qtsupportconstants.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <proparser/profileevaluator.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
@@ -38,6 +37,7 @@ namespace Internal {
|
||||
IosQtVersionFactory::IosQtVersionFactory(QObject *parent)
|
||||
: QtSupport::QtVersionFactory(parent)
|
||||
{
|
||||
setQtVersionCreator([] { return new IosQtVersion; });
|
||||
}
|
||||
|
||||
bool IosQtVersionFactory::canRestore(const QString &type)
|
||||
@@ -45,15 +45,6 @@ bool IosQtVersionFactory::canRestore(const QString &type)
|
||||
return type == QLatin1String(Constants::IOSQT);
|
||||
}
|
||||
|
||||
QtSupport::BaseQtVersion *IosQtVersionFactory::restore(const QString &type,
|
||||
const QVariantMap &data)
|
||||
{
|
||||
QTC_ASSERT(canRestore(type), return nullptr);
|
||||
auto v = new IosQtVersion;
|
||||
v->fromMap(data);
|
||||
return v;
|
||||
}
|
||||
|
||||
int IosQtVersionFactory::priority() const
|
||||
{
|
||||
return 90;
|
||||
|
@@ -36,7 +36,6 @@ public:
|
||||
explicit IosQtVersionFactory(QObject *parent = nullptr);
|
||||
|
||||
bool canRestore(const QString &type) override;
|
||||
QtSupport::BaseQtVersion *restore(const QString &type, const QVariantMap &data) override;
|
||||
|
||||
int priority() const override;
|
||||
QtSupport::BaseQtVersion *create(const Utils::FileName &qmakePath, ProFileEvaluator *evaluator,
|
||||
|
@@ -39,6 +39,7 @@ using namespace Qnx::Internal;
|
||||
QnxQtVersionFactory::QnxQtVersionFactory(QObject *parent) :
|
||||
QtSupport::QtVersionFactory(parent)
|
||||
{
|
||||
setQtVersionCreator([] { return new QnxQtVersion; });
|
||||
}
|
||||
|
||||
QnxQtVersionFactory::~QnxQtVersionFactory() = default;
|
||||
@@ -48,15 +49,6 @@ bool QnxQtVersionFactory::canRestore(const QString &type)
|
||||
return type == QLatin1String(Constants::QNX_QNX_QT);
|
||||
}
|
||||
|
||||
QtSupport::BaseQtVersion *QnxQtVersionFactory::restore(const QString &type, const QVariantMap &data)
|
||||
{
|
||||
if (!canRestore(type))
|
||||
return nullptr;
|
||||
auto v = new QnxQtVersion;
|
||||
v->fromMap(data);
|
||||
return v;
|
||||
}
|
||||
|
||||
int QnxQtVersionFactory::priority() const
|
||||
{
|
||||
return 50;
|
||||
|
@@ -38,7 +38,6 @@ public:
|
||||
~QnxQtVersionFactory() override;
|
||||
|
||||
bool canRestore(const QString &type) override;
|
||||
QtSupport::BaseQtVersion *restore(const QString &type, const QVariantMap &data) override;
|
||||
|
||||
int priority() const override;
|
||||
QtSupport::BaseQtVersion *create(const Utils::FileName &qmakePath,
|
||||
|
@@ -35,7 +35,7 @@ using namespace QtSupport::Internal;
|
||||
DesktopQtVersionFactory::DesktopQtVersionFactory(QObject *parent)
|
||||
: QtVersionFactory(parent)
|
||||
{
|
||||
|
||||
setQtVersionCreator([] { return new DesktopQtVersion; });
|
||||
}
|
||||
|
||||
DesktopQtVersionFactory::~DesktopQtVersionFactory() = default;
|
||||
@@ -45,15 +45,6 @@ bool DesktopQtVersionFactory::canRestore(const QString &type)
|
||||
return type == QLatin1String(Constants::DESKTOPQT);
|
||||
}
|
||||
|
||||
BaseQtVersion *DesktopQtVersionFactory::restore(const QString &type, const QVariantMap &data)
|
||||
{
|
||||
if (!canRestore(type))
|
||||
return nullptr;
|
||||
auto v = new DesktopQtVersion;
|
||||
v->fromMap(data);
|
||||
return v;
|
||||
}
|
||||
|
||||
int DesktopQtVersionFactory::priority() const
|
||||
{
|
||||
// Lowest of all, we want to be the fallback
|
||||
|
@@ -37,7 +37,6 @@ public:
|
||||
~DesktopQtVersionFactory() override;
|
||||
|
||||
bool canRestore(const QString &type) override;
|
||||
BaseQtVersion *restore(const QString &type, const QVariantMap &data) override;
|
||||
|
||||
int priority() const override;
|
||||
BaseQtVersion *create(const Utils::FileName &qmakePath, ProFileEvaluator *evaluator,
|
||||
|
@@ -30,8 +30,10 @@
|
||||
#include <proparser/qmakevfs.h>
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using namespace QtSupport;
|
||||
using namespace QtSupport::Internal;
|
||||
@@ -54,6 +56,15 @@ const QList<QtVersionFactory *> QtVersionFactory::allQtVersionFactories()
|
||||
return g_qtVersionFactories;
|
||||
}
|
||||
|
||||
BaseQtVersion *QtVersionFactory::restore(const QString &type, const QVariantMap &data)
|
||||
{
|
||||
QTC_ASSERT(canRestore(type), return nullptr);
|
||||
QTC_ASSERT(m_creator, return nullptr);
|
||||
BaseQtVersion *version = m_creator();
|
||||
version->fromMap(data);
|
||||
return version;
|
||||
}
|
||||
|
||||
BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileName &qmakePath, bool isAutoDetected, const QString &autoDetectionSource, QString *error)
|
||||
{
|
||||
QHash<ProKey, ProString> versionInfo;
|
||||
@@ -88,3 +99,8 @@ BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileN
|
||||
*error = tr("No factory found for qmake: \"%1\"").arg(qmakePath.toUserOutput());
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QtVersionFactory::setQtVersionCreator(const std::function<BaseQtVersion *()> &creator)
|
||||
{
|
||||
m_creator = creator;
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ public:
|
||||
static const QList<QtVersionFactory *> allQtVersionFactories();
|
||||
|
||||
virtual bool canRestore(const QString &type) = 0;
|
||||
virtual BaseQtVersion *restore(const QString &type, const QVariantMap &data) = 0;
|
||||
BaseQtVersion *restore(const QString &type, const QVariantMap &data);
|
||||
|
||||
/// factories with higher priority are asked first to identify
|
||||
/// a qtversion, the priority of the desktop factory is 0 and
|
||||
@@ -66,6 +66,12 @@ public:
|
||||
static BaseQtVersion *createQtVersionFromQMakePath(
|
||||
const Utils::FileName &qmakePath, bool isAutoDetected = false,
|
||||
const QString &autoDetectionSource = QString(), QString *error = nullptr);
|
||||
|
||||
protected:
|
||||
void setQtVersionCreator(const std::function<BaseQtVersion *()> &creator);
|
||||
|
||||
private:
|
||||
std::function<BaseQtVersion *()> m_creator;
|
||||
};
|
||||
|
||||
} // namespace QtSupport
|
||||
|
@@ -36,6 +36,7 @@ namespace Internal {
|
||||
EmbeddedLinuxQtVersionFactory::EmbeddedLinuxQtVersionFactory(QObject *parent)
|
||||
: QtSupport::QtVersionFactory(parent)
|
||||
{
|
||||
setQtVersionCreator([] { return new EmbeddedLinuxQtVersion; });
|
||||
}
|
||||
|
||||
EmbeddedLinuxQtVersionFactory::~EmbeddedLinuxQtVersionFactory() = default;
|
||||
@@ -45,15 +46,6 @@ bool EmbeddedLinuxQtVersionFactory::canRestore(const QString &type)
|
||||
return type == QLatin1String(RemoteLinux::Constants::EMBEDDED_LINUX_QT);
|
||||
}
|
||||
|
||||
QtSupport::BaseQtVersion *EmbeddedLinuxQtVersionFactory::restore(const QString &type, const QVariantMap &data)
|
||||
{
|
||||
if (!canRestore(type))
|
||||
return nullptr;
|
||||
auto v = new EmbeddedLinuxQtVersion;
|
||||
v->fromMap(data);
|
||||
return v;
|
||||
}
|
||||
|
||||
int EmbeddedLinuxQtVersionFactory::priority() const
|
||||
{
|
||||
return 10;
|
||||
|
@@ -37,7 +37,6 @@ public:
|
||||
~EmbeddedLinuxQtVersionFactory() override;
|
||||
|
||||
bool canRestore(const QString &type) override;
|
||||
QtSupport::BaseQtVersion *restore(const QString &type, const QVariantMap &data) override;
|
||||
|
||||
int priority() const override;
|
||||
QtSupport::BaseQtVersion *create(const Utils::FileName &qmakePath, ProFileEvaluator *evaluator,
|
||||
|
@@ -38,6 +38,7 @@ namespace Internal {
|
||||
WinRtQtVersionFactory::WinRtQtVersionFactory(QObject *parent)
|
||||
: QtSupport::QtVersionFactory(parent)
|
||||
{
|
||||
setQtVersionCreator([] { return new WinRtQtVersion; });
|
||||
}
|
||||
|
||||
WinRtQtVersionFactory::~WinRtQtVersionFactory()
|
||||
@@ -49,16 +50,6 @@ bool WinRtQtVersionFactory::canRestore(const QString &type)
|
||||
return type == QLatin1String(Constants::WINRT_WINRTQT);
|
||||
}
|
||||
|
||||
QtSupport::BaseQtVersion *WinRtQtVersionFactory::restore(const QString &type,
|
||||
const QVariantMap &data)
|
||||
{
|
||||
if (!canRestore(type))
|
||||
return nullptr;
|
||||
WinRtQtVersion *v = new WinRtQtVersion;
|
||||
v->fromMap(data);
|
||||
return v;
|
||||
}
|
||||
|
||||
int WinRtQtVersionFactory::priority() const
|
||||
{
|
||||
return 10;
|
||||
@@ -84,6 +75,7 @@ QtSupport::BaseQtVersion *WinRtQtVersionFactory::create(const Utils::FileName &q
|
||||
WinRtPhoneQtVersionFactory::WinRtPhoneQtVersionFactory(QObject *parent)
|
||||
: QtSupport::QtVersionFactory(parent)
|
||||
{
|
||||
setQtVersionCreator([] { return new WinRtPhoneQtVersion; });
|
||||
}
|
||||
|
||||
bool WinRtPhoneQtVersionFactory::canRestore(const QString &type)
|
||||
@@ -91,16 +83,6 @@ bool WinRtPhoneQtVersionFactory::canRestore(const QString &type)
|
||||
return type == QLatin1String(Constants::WINRT_WINPHONEQT);
|
||||
}
|
||||
|
||||
QtSupport::BaseQtVersion *WinRtPhoneQtVersionFactory::restore(const QString &type,
|
||||
const QVariantMap &data)
|
||||
{
|
||||
if (!canRestore(type))
|
||||
return nullptr;
|
||||
WinRtQtVersion *v = new WinRtPhoneQtVersion;
|
||||
v->fromMap(data);
|
||||
return v;
|
||||
}
|
||||
|
||||
int WinRtPhoneQtVersionFactory::priority() const
|
||||
{
|
||||
return 10;
|
||||
|
@@ -37,7 +37,6 @@ public:
|
||||
~WinRtQtVersionFactory();
|
||||
|
||||
bool canRestore(const QString &type);
|
||||
QtSupport::BaseQtVersion *restore(const QString &type, const QVariantMap &data);
|
||||
|
||||
int priority() const;
|
||||
QtSupport::BaseQtVersion *create(const Utils::FileName &qmakePath, ProFileEvaluator *evaluator,
|
||||
@@ -50,7 +49,6 @@ public:
|
||||
explicit WinRtPhoneQtVersionFactory(QObject *parent = nullptr);
|
||||
|
||||
bool canRestore(const QString &type);
|
||||
QtSupport::BaseQtVersion *restore(const QString &type, const QVariantMap &data);
|
||||
|
||||
int priority() const;
|
||||
QtSupport::BaseQtVersion *create(const Utils::FileName &qmakePath, ProFileEvaluator *evaluator,
|
||||
|
Reference in New Issue
Block a user