forked from qt-creator/qt-creator
QtSupport: Replace BaseQtVersion::clone()
... by a mechanism that doesn't require re-implementation in each derived class. A QtVersion's type() is uniquely defined by the supported type of the factory creating it, so that factory can be found and used for cloning. Non-base data is copied by a fromMap(toMap()) dance as done in the project configurations. As a side-effect, the *QtVersion copy constructors are not used and not needed anymore. Change-Id: I3aa5a0fd90a27dd115769e0573647cb5669641a0 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -52,16 +52,6 @@ AndroidQtVersion::AndroidQtVersion()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AndroidQtVersion *AndroidQtVersion::clone() const
|
|
||||||
{
|
|
||||||
return new AndroidQtVersion(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString AndroidQtVersion::type() const
|
|
||||||
{
|
|
||||||
return QLatin1String(Constants::ANDROIDQT);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AndroidQtVersion::isValid() const
|
bool AndroidQtVersion::isValid() const
|
||||||
{
|
{
|
||||||
if (!BaseQtVersion::isValid())
|
if (!BaseQtVersion::isValid())
|
||||||
|
@@ -40,8 +40,6 @@ class AndroidQtVersion : public QtSupport::BaseQtVersion
|
|||||||
public:
|
public:
|
||||||
AndroidQtVersion();
|
AndroidQtVersion();
|
||||||
|
|
||||||
AndroidQtVersion *clone() const override;
|
|
||||||
QString type() const override;
|
|
||||||
bool isValid() const override;
|
bool isValid() const override;
|
||||||
QString invalidReason() const override;
|
QString invalidReason() const override;
|
||||||
|
|
||||||
|
@@ -42,16 +42,6 @@ using namespace ProjectExplorer;
|
|||||||
|
|
||||||
IosQtVersion::IosQtVersion() = default;
|
IosQtVersion::IosQtVersion() = default;
|
||||||
|
|
||||||
IosQtVersion *IosQtVersion::clone() const
|
|
||||||
{
|
|
||||||
return new IosQtVersion(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString IosQtVersion::type() const
|
|
||||||
{
|
|
||||||
return QLatin1String(Constants::IOSQT);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IosQtVersion::isValid() const
|
bool IosQtVersion::isValid() const
|
||||||
{
|
{
|
||||||
if (!BaseQtVersion::isValid())
|
if (!BaseQtVersion::isValid())
|
||||||
|
@@ -40,8 +40,6 @@ class IosQtVersion : public QtSupport::BaseQtVersion
|
|||||||
public:
|
public:
|
||||||
IosQtVersion();
|
IosQtVersion();
|
||||||
|
|
||||||
IosQtVersion *clone() const override;
|
|
||||||
QString type() const override;
|
|
||||||
bool isValid() const override;
|
bool isValid() const override;
|
||||||
QString invalidReason() const override;
|
QString invalidReason() const override;
|
||||||
|
|
||||||
|
@@ -46,16 +46,6 @@ static char SDP_PATH_KEY[] = "SDKPath";
|
|||||||
|
|
||||||
QnxQtVersion::QnxQtVersion() = default;
|
QnxQtVersion::QnxQtVersion() = default;
|
||||||
|
|
||||||
QnxQtVersion *QnxQtVersion::clone() const
|
|
||||||
{
|
|
||||||
return new QnxQtVersion(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QnxQtVersion::type() const
|
|
||||||
{
|
|
||||||
return QLatin1String(Constants::QNX_QNX_QT);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QnxQtVersion::description() const
|
QString QnxQtVersion::description() const
|
||||||
{
|
{
|
||||||
//: Qt Version is meant for QNX
|
//: Qt Version is meant for QNX
|
||||||
|
@@ -41,10 +41,6 @@ class QnxQtVersion : public QtSupport::BaseQtVersion
|
|||||||
public:
|
public:
|
||||||
QnxQtVersion();
|
QnxQtVersion();
|
||||||
|
|
||||||
QnxQtVersion *clone() const override;
|
|
||||||
|
|
||||||
QString type() const override;
|
|
||||||
|
|
||||||
QString description() const override;
|
QString description() const override;
|
||||||
|
|
||||||
QSet<Core::Id> availableFeatures() const override;
|
QSet<Core::Id> availableFeatures() const override;
|
||||||
|
@@ -28,8 +28,10 @@
|
|||||||
#include "qmldumptool.h"
|
#include "qmldumptool.h"
|
||||||
#include "qtkitinformation.h"
|
#include "qtkitinformation.h"
|
||||||
|
|
||||||
|
#include "qtversionfactory.h"
|
||||||
#include "qtversionmanager.h"
|
#include "qtversionmanager.h"
|
||||||
#include "profilereader.h"
|
#include "profilereader.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
#include <proparser/qmakevfs.h>
|
#include <proparser/qmakevfs.h>
|
||||||
@@ -193,7 +195,6 @@ bool QtVersionNumber::operator >=(const QtVersionNumber &b) const
|
|||||||
// BaseQtVersion
|
// BaseQtVersion
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
BaseQtVersion::BaseQtVersion(const BaseQtVersion &other) = default;
|
|
||||||
BaseQtVersion::BaseQtVersion() = default;
|
BaseQtVersion::BaseQtVersion() = default;
|
||||||
|
|
||||||
BaseQtVersion::~BaseQtVersion() = default;
|
BaseQtVersion::~BaseQtVersion() = default;
|
||||||
@@ -645,6 +646,12 @@ int BaseQtVersion::uniqueId() const
|
|||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString BaseQtVersion::type() const
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_factory, return QString());
|
||||||
|
return m_factory->supportedType();
|
||||||
|
}
|
||||||
|
|
||||||
bool BaseQtVersion::isAutodetected() const
|
bool BaseQtVersion::isAutodetected() const
|
||||||
{
|
{
|
||||||
return m_isAutodetected;
|
return m_isAutodetected;
|
||||||
|
@@ -64,6 +64,7 @@ namespace QtSupport
|
|||||||
class QtConfigWidget;
|
class QtConfigWidget;
|
||||||
|
|
||||||
class BaseQtVersion;
|
class BaseQtVersion;
|
||||||
|
class QtVersionFactory;
|
||||||
|
|
||||||
// Wrapper to make the std::unique_ptr<Utils::MacroExpander> "copyable":
|
// Wrapper to make the std::unique_ptr<Utils::MacroExpander> "copyable":
|
||||||
class MacroExpanderWrapper
|
class MacroExpanderWrapper
|
||||||
@@ -113,7 +114,6 @@ public:
|
|||||||
virtual ~BaseQtVersion();
|
virtual ~BaseQtVersion();
|
||||||
|
|
||||||
virtual void fromMap(const QVariantMap &map);
|
virtual void fromMap(const QVariantMap &map);
|
||||||
virtual BaseQtVersion *clone() const = 0;
|
|
||||||
virtual bool equals(BaseQtVersion *other);
|
virtual bool equals(BaseQtVersion *other);
|
||||||
|
|
||||||
bool isAutodetected() const;
|
bool isAutodetected() const;
|
||||||
@@ -126,7 +126,7 @@ public:
|
|||||||
// All valid Ids are >= 0
|
// All valid Ids are >= 0
|
||||||
int uniqueId() const;
|
int uniqueId() const;
|
||||||
|
|
||||||
virtual QString type() const = 0;
|
QString type() const;
|
||||||
|
|
||||||
virtual QVariantMap toMap() const;
|
virtual QVariantMap toMap() const;
|
||||||
virtual bool isValid() const;
|
virtual bool isValid() const;
|
||||||
@@ -259,7 +259,7 @@ protected:
|
|||||||
virtual QSet<Core::Id> availableFeatures() const;
|
virtual QSet<Core::Id> availableFeatures() const;
|
||||||
|
|
||||||
BaseQtVersion();
|
BaseQtVersion();
|
||||||
BaseQtVersion(const BaseQtVersion &other);
|
BaseQtVersion(const BaseQtVersion &other) = delete;
|
||||||
|
|
||||||
virtual QList<ProjectExplorer::Task> reportIssuesImpl(const QString &proFile, const QString &buildDir) const;
|
virtual QList<ProjectExplorer::Task> reportIssuesImpl(const QString &proFile, const QString &buildDir) const;
|
||||||
|
|
||||||
@@ -292,6 +292,7 @@ private:
|
|||||||
// and by the qtoptionspage to replace Qt versions
|
// and by the qtoptionspage to replace Qt versions
|
||||||
|
|
||||||
int m_id = -1;
|
int m_id = -1;
|
||||||
|
const QtVersionFactory *m_factory = nullptr; // The factory that created us.
|
||||||
|
|
||||||
bool m_isAutodetected = false;
|
bool m_isAutodetected = false;
|
||||||
mutable bool m_hasQmlDump = false; // controlled by m_versionInfoUpToDate
|
mutable bool m_hasQmlDump = false; // controlled by m_versionInfoUpToDate
|
||||||
|
@@ -46,16 +46,6 @@ DesktopQtVersion::DesktopQtVersion()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopQtVersion *DesktopQtVersion::clone() const
|
|
||||||
{
|
|
||||||
return new DesktopQtVersion(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DesktopQtVersion::type() const
|
|
||||||
{
|
|
||||||
return QLatin1String(Constants::DESKTOPQT);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList DesktopQtVersion::warningReason() const
|
QStringList DesktopQtVersion::warningReason() const
|
||||||
{
|
{
|
||||||
QStringList ret = BaseQtVersion::warningReason();
|
QStringList ret = BaseQtVersion::warningReason();
|
||||||
@@ -112,9 +102,6 @@ QString DesktopQtVersion::qmlsceneCommand() const
|
|||||||
return m_qmlsceneCommand;
|
return m_qmlsceneCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopQtVersion::DesktopQtVersion(const DesktopQtVersion &other) = default;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
// Factory
|
// Factory
|
||||||
|
@@ -36,10 +36,6 @@ class QTSUPPORT_EXPORT DesktopQtVersion : public BaseQtVersion
|
|||||||
public:
|
public:
|
||||||
DesktopQtVersion();
|
DesktopQtVersion();
|
||||||
|
|
||||||
DesktopQtVersion *clone() const override;
|
|
||||||
|
|
||||||
QString type() const override;
|
|
||||||
|
|
||||||
QStringList warningReason() const override;
|
QStringList warningReason() const override;
|
||||||
|
|
||||||
QString description() const override;
|
QString description() const override;
|
||||||
@@ -51,9 +47,6 @@ public:
|
|||||||
|
|
||||||
QString qmlsceneCommand() const;
|
QString qmlsceneCommand() const;
|
||||||
|
|
||||||
protected:
|
|
||||||
DesktopQtVersion(const DesktopQtVersion &other);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable QString m_qmlsceneCommand;
|
mutable QString m_qmlsceneCommand;
|
||||||
};
|
};
|
||||||
|
@@ -522,7 +522,7 @@ void QtOptionsPageWidget::updateQtVersions(const QList<int> &additions, const QL
|
|||||||
|
|
||||||
// Add changed/added items:
|
// Add changed/added items:
|
||||||
foreach (int a, toAdd) {
|
foreach (int a, toAdd) {
|
||||||
BaseQtVersion *version = QtVersionManager::version(a)->clone();
|
BaseQtVersion *version = QtVersionFactory::cloneQtVersion(QtVersionManager::version(a));
|
||||||
auto *item = new QtVersionItem(version);
|
auto *item = new QtVersionItem(version);
|
||||||
|
|
||||||
// Insert in the right place:
|
// Insert in the right place:
|
||||||
@@ -753,7 +753,7 @@ void QtOptionsPageWidget::apply()
|
|||||||
|
|
||||||
m_model->forItemsAtLevel<2>([&versions](QtVersionItem *item) {
|
m_model->forItemsAtLevel<2>([&versions](QtVersionItem *item) {
|
||||||
item->setChanged(false);
|
item->setChanged(false);
|
||||||
versions.append(item->version()->clone());
|
versions.append(QtVersionFactory::cloneQtVersion(item->version()));
|
||||||
});
|
});
|
||||||
|
|
||||||
QtVersionManager::setNewQtVersions(versions);
|
QtVersionManager::setNewQtVersions(versions);
|
||||||
|
@@ -66,7 +66,7 @@ BaseQtVersion *QtVersionFactory::restore(const QString &type, const QVariantMap
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(canRestore(type), return nullptr);
|
QTC_ASSERT(canRestore(type), return nullptr);
|
||||||
QTC_ASSERT(m_creator, return nullptr);
|
QTC_ASSERT(m_creator, return nullptr);
|
||||||
BaseQtVersion *version = m_creator();
|
BaseQtVersion *version = create();
|
||||||
version->fromMap(data);
|
version->fromMap(data);
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
@@ -104,8 +104,7 @@ BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileN
|
|||||||
|
|
||||||
foreach (QtVersionFactory *factory, factories) {
|
foreach (QtVersionFactory *factory, factories) {
|
||||||
if (!factory->m_restrictionChecker || factory->m_restrictionChecker(setup)) {
|
if (!factory->m_restrictionChecker || factory->m_restrictionChecker(setup)) {
|
||||||
QTC_ASSERT(factory->m_creator, continue);
|
BaseQtVersion *ver = factory->create();
|
||||||
BaseQtVersion *ver = factory->m_creator();
|
|
||||||
QTC_ASSERT(ver, continue);
|
QTC_ASSERT(ver, continue);
|
||||||
ver->setupQmakePathAndId(qmakePath);
|
ver->setupQmakePathAndId(qmakePath);
|
||||||
ver->setAutoDetectionSource(autoDetectionSource);
|
ver->setAutoDetectionSource(autoDetectionSource);
|
||||||
@@ -122,6 +121,35 @@ BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileN
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BaseQtVersion *QtVersionFactory::create() const
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_creator, return nullptr);
|
||||||
|
BaseQtVersion *version = m_creator();
|
||||||
|
version->m_factory = this;
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QtVersionFactory::supportedType() const
|
||||||
|
{
|
||||||
|
return m_supportedType;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseQtVersion *QtVersionFactory::cloneQtVersion(const BaseQtVersion *source)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(source, return nullptr);
|
||||||
|
const QString sourceType = source->type();
|
||||||
|
for (QtVersionFactory *factory : g_qtVersionFactories) {
|
||||||
|
if (factory->m_supportedType == sourceType) {
|
||||||
|
BaseQtVersion *version = factory->create();
|
||||||
|
QTC_ASSERT(version, return nullptr);
|
||||||
|
version->fromMap(source->toMap());
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QTC_CHECK(false);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void QtVersionFactory::setQtVersionCreator(const std::function<BaseQtVersion *()> &creator)
|
void QtVersionFactory::setQtVersionCreator(const std::function<BaseQtVersion *()> &creator)
|
||||||
{
|
{
|
||||||
m_creator = creator;
|
m_creator = creator;
|
||||||
|
@@ -51,10 +51,14 @@ public:
|
|||||||
/// the desktop factory claims to handle all paths
|
/// the desktop factory claims to handle all paths
|
||||||
int priority() const { return m_priority; }
|
int priority() const { return m_priority; }
|
||||||
|
|
||||||
|
QString supportedType() const;
|
||||||
|
|
||||||
static BaseQtVersion *createQtVersionFromQMakePath(
|
static BaseQtVersion *createQtVersionFromQMakePath(
|
||||||
const Utils::FileName &qmakePath, bool isAutoDetected = false,
|
const Utils::FileName &qmakePath, bool isAutoDetected = false,
|
||||||
const QString &autoDetectionSource = QString(), QString *error = nullptr);
|
const QString &autoDetectionSource = QString(), QString *error = nullptr);
|
||||||
|
|
||||||
|
static BaseQtVersion *cloneQtVersion(const BaseQtVersion *source);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct SetupData
|
struct SetupData
|
||||||
{
|
{
|
||||||
@@ -69,6 +73,8 @@ protected:
|
|||||||
void setPriority(int priority);
|
void setPriority(int priority);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BaseQtVersion *create() const;
|
||||||
|
|
||||||
std::function<BaseQtVersion *()> m_creator;
|
std::function<BaseQtVersion *()> m_creator;
|
||||||
std::function<bool(const SetupData &)> m_restrictionChecker;
|
std::function<bool(const SetupData &)> m_restrictionChecker;
|
||||||
QString m_supportedType;
|
QString m_supportedType;
|
||||||
|
@@ -35,16 +35,6 @@
|
|||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
EmbeddedLinuxQtVersion *EmbeddedLinuxQtVersion::clone() const
|
|
||||||
{
|
|
||||||
return new EmbeddedLinuxQtVersion(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString EmbeddedLinuxQtVersion::type() const
|
|
||||||
{
|
|
||||||
return QLatin1String(RemoteLinux::Constants::EMBEDDED_LINUX_QT);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString EmbeddedLinuxQtVersion::description() const
|
QString EmbeddedLinuxQtVersion::description() const
|
||||||
{
|
{
|
||||||
return QCoreApplication::translate("QtVersion", "Embedded Linux", "Qt Version is used for embedded Linux development");
|
return QCoreApplication::translate("QtVersion", "Embedded Linux", "Qt Version is used for embedded Linux development");
|
||||||
|
@@ -36,10 +36,6 @@ class EmbeddedLinuxQtVersion : public QtSupport::BaseQtVersion
|
|||||||
public:
|
public:
|
||||||
EmbeddedLinuxQtVersion() = default;
|
EmbeddedLinuxQtVersion() = default;
|
||||||
|
|
||||||
EmbeddedLinuxQtVersion *clone() const override;
|
|
||||||
|
|
||||||
QString type() const override;
|
|
||||||
|
|
||||||
QString description() const override;
|
QString description() const override;
|
||||||
|
|
||||||
QSet<Core::Id> targetDeviceTypes() const override;
|
QSet<Core::Id> targetDeviceTypes() const override;
|
||||||
|
@@ -40,16 +40,6 @@ QString WinRtPhoneQtVersion::description() const
|
|||||||
return tr("Windows Phone");
|
return tr("Windows Phone");
|
||||||
}
|
}
|
||||||
|
|
||||||
QtSupport::BaseQtVersion *WinRtPhoneQtVersion::clone() const
|
|
||||||
{
|
|
||||||
return new WinRtPhoneQtVersion(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString WinRtPhoneQtVersion::type() const
|
|
||||||
{
|
|
||||||
return QLatin1String(Constants::WINRT_WINPHONEQT);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSet<Core::Id> WinRtPhoneQtVersion::targetDeviceTypes() const
|
QSet<Core::Id> WinRtPhoneQtVersion::targetDeviceTypes() const
|
||||||
{
|
{
|
||||||
return {Constants::WINRT_DEVICE_TYPE_PHONE, Constants::WINRT_DEVICE_TYPE_EMULATOR};
|
return {Constants::WINRT_DEVICE_TYPE_PHONE, Constants::WINRT_DEVICE_TYPE_EMULATOR};
|
||||||
|
@@ -39,8 +39,6 @@ public:
|
|||||||
QSet<Core::Id> availableFeatures() const override;
|
QSet<Core::Id> availableFeatures() const override;
|
||||||
|
|
||||||
QString description() const override;
|
QString description() const override;
|
||||||
BaseQtVersion *clone() const override;
|
|
||||||
QString type() const override;
|
|
||||||
QSet<Core::Id> targetDeviceTypes() const override;
|
QSet<Core::Id> targetDeviceTypes() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -33,16 +33,6 @@
|
|||||||
namespace WinRt {
|
namespace WinRt {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
QtSupport::BaseQtVersion *WinRtQtVersion::clone() const
|
|
||||||
{
|
|
||||||
return new WinRtQtVersion(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString WinRtQtVersion::type() const
|
|
||||||
{
|
|
||||||
return QLatin1String(Constants::WINRT_WINRTQT);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString WinRtQtVersion::description() const
|
QString WinRtQtVersion::description() const
|
||||||
{
|
{
|
||||||
return tr("Windows Runtime");
|
return tr("Windows Runtime");
|
||||||
|
@@ -37,8 +37,6 @@ class WinRtQtVersion : public QtSupport::BaseQtVersion
|
|||||||
public:
|
public:
|
||||||
WinRtQtVersion() = default;
|
WinRtQtVersion() = default;
|
||||||
|
|
||||||
BaseQtVersion *clone() const override;
|
|
||||||
QString type() const override;
|
|
||||||
QString description() const override;
|
QString description() const override;
|
||||||
QSet<Core::Id> availableFeatures() const override;
|
QSet<Core::Id> availableFeatures() const override;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user