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
|
||||
{
|
||||
if (!BaseQtVersion::isValid())
|
||||
|
@@ -40,8 +40,6 @@ class AndroidQtVersion : public QtSupport::BaseQtVersion
|
||||
public:
|
||||
AndroidQtVersion();
|
||||
|
||||
AndroidQtVersion *clone() const override;
|
||||
QString type() const override;
|
||||
bool isValid() const override;
|
||||
QString invalidReason() const override;
|
||||
|
||||
|
@@ -42,16 +42,6 @@ using namespace ProjectExplorer;
|
||||
|
||||
IosQtVersion::IosQtVersion() = default;
|
||||
|
||||
IosQtVersion *IosQtVersion::clone() const
|
||||
{
|
||||
return new IosQtVersion(*this);
|
||||
}
|
||||
|
||||
QString IosQtVersion::type() const
|
||||
{
|
||||
return QLatin1String(Constants::IOSQT);
|
||||
}
|
||||
|
||||
bool IosQtVersion::isValid() const
|
||||
{
|
||||
if (!BaseQtVersion::isValid())
|
||||
|
@@ -40,8 +40,6 @@ class IosQtVersion : public QtSupport::BaseQtVersion
|
||||
public:
|
||||
IosQtVersion();
|
||||
|
||||
IosQtVersion *clone() const override;
|
||||
QString type() const override;
|
||||
bool isValid() const override;
|
||||
QString invalidReason() const override;
|
||||
|
||||
|
@@ -46,16 +46,6 @@ static char SDP_PATH_KEY[] = "SDKPath";
|
||||
|
||||
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
|
||||
{
|
||||
//: Qt Version is meant for QNX
|
||||
|
@@ -41,10 +41,6 @@ class QnxQtVersion : public QtSupport::BaseQtVersion
|
||||
public:
|
||||
QnxQtVersion();
|
||||
|
||||
QnxQtVersion *clone() const override;
|
||||
|
||||
QString type() const override;
|
||||
|
||||
QString description() const override;
|
||||
|
||||
QSet<Core::Id> availableFeatures() const override;
|
||||
|
@@ -28,8 +28,10 @@
|
||||
#include "qmldumptool.h"
|
||||
#include "qtkitinformation.h"
|
||||
|
||||
#include "qtversionfactory.h"
|
||||
#include "qtversionmanager.h"
|
||||
#include "profilereader.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <proparser/qmakevfs.h>
|
||||
@@ -193,7 +195,6 @@ bool QtVersionNumber::operator >=(const QtVersionNumber &b) const
|
||||
// BaseQtVersion
|
||||
///////////////
|
||||
|
||||
BaseQtVersion::BaseQtVersion(const BaseQtVersion &other) = default;
|
||||
BaseQtVersion::BaseQtVersion() = default;
|
||||
|
||||
BaseQtVersion::~BaseQtVersion() = default;
|
||||
@@ -645,6 +646,12 @@ int BaseQtVersion::uniqueId() const
|
||||
return m_id;
|
||||
}
|
||||
|
||||
QString BaseQtVersion::type() const
|
||||
{
|
||||
QTC_ASSERT(m_factory, return QString());
|
||||
return m_factory->supportedType();
|
||||
}
|
||||
|
||||
bool BaseQtVersion::isAutodetected() const
|
||||
{
|
||||
return m_isAutodetected;
|
||||
|
@@ -64,6 +64,7 @@ namespace QtSupport
|
||||
class QtConfigWidget;
|
||||
|
||||
class BaseQtVersion;
|
||||
class QtVersionFactory;
|
||||
|
||||
// Wrapper to make the std::unique_ptr<Utils::MacroExpander> "copyable":
|
||||
class MacroExpanderWrapper
|
||||
@@ -113,7 +114,6 @@ public:
|
||||
virtual ~BaseQtVersion();
|
||||
|
||||
virtual void fromMap(const QVariantMap &map);
|
||||
virtual BaseQtVersion *clone() const = 0;
|
||||
virtual bool equals(BaseQtVersion *other);
|
||||
|
||||
bool isAutodetected() const;
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
// All valid Ids are >= 0
|
||||
int uniqueId() const;
|
||||
|
||||
virtual QString type() const = 0;
|
||||
QString type() const;
|
||||
|
||||
virtual QVariantMap toMap() const;
|
||||
virtual bool isValid() const;
|
||||
@@ -259,7 +259,7 @@ protected:
|
||||
virtual QSet<Core::Id> availableFeatures() const;
|
||||
|
||||
BaseQtVersion();
|
||||
BaseQtVersion(const BaseQtVersion &other);
|
||||
BaseQtVersion(const BaseQtVersion &other) = delete;
|
||||
|
||||
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
|
||||
|
||||
int m_id = -1;
|
||||
const QtVersionFactory *m_factory = nullptr; // The factory that created us.
|
||||
|
||||
bool m_isAutodetected = false;
|
||||
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 ret = BaseQtVersion::warningReason();
|
||||
@@ -112,9 +102,6 @@ QString DesktopQtVersion::qmlsceneCommand() const
|
||||
return m_qmlsceneCommand;
|
||||
}
|
||||
|
||||
DesktopQtVersion::DesktopQtVersion(const DesktopQtVersion &other) = default;
|
||||
|
||||
|
||||
namespace Internal {
|
||||
|
||||
// Factory
|
||||
|
@@ -36,10 +36,6 @@ class QTSUPPORT_EXPORT DesktopQtVersion : public BaseQtVersion
|
||||
public:
|
||||
DesktopQtVersion();
|
||||
|
||||
DesktopQtVersion *clone() const override;
|
||||
|
||||
QString type() const override;
|
||||
|
||||
QStringList warningReason() const override;
|
||||
|
||||
QString description() const override;
|
||||
@@ -51,9 +47,6 @@ public:
|
||||
|
||||
QString qmlsceneCommand() const;
|
||||
|
||||
protected:
|
||||
DesktopQtVersion(const DesktopQtVersion &other);
|
||||
|
||||
private:
|
||||
mutable QString m_qmlsceneCommand;
|
||||
};
|
||||
|
@@ -522,7 +522,7 @@ void QtOptionsPageWidget::updateQtVersions(const QList<int> &additions, const QL
|
||||
|
||||
// Add changed/added items:
|
||||
foreach (int a, toAdd) {
|
||||
BaseQtVersion *version = QtVersionManager::version(a)->clone();
|
||||
BaseQtVersion *version = QtVersionFactory::cloneQtVersion(QtVersionManager::version(a));
|
||||
auto *item = new QtVersionItem(version);
|
||||
|
||||
// Insert in the right place:
|
||||
@@ -753,7 +753,7 @@ void QtOptionsPageWidget::apply()
|
||||
|
||||
m_model->forItemsAtLevel<2>([&versions](QtVersionItem *item) {
|
||||
item->setChanged(false);
|
||||
versions.append(item->version()->clone());
|
||||
versions.append(QtVersionFactory::cloneQtVersion(item->version()));
|
||||
});
|
||||
|
||||
QtVersionManager::setNewQtVersions(versions);
|
||||
|
@@ -66,7 +66,7 @@ BaseQtVersion *QtVersionFactory::restore(const QString &type, const QVariantMap
|
||||
{
|
||||
QTC_ASSERT(canRestore(type), return nullptr);
|
||||
QTC_ASSERT(m_creator, return nullptr);
|
||||
BaseQtVersion *version = m_creator();
|
||||
BaseQtVersion *version = create();
|
||||
version->fromMap(data);
|
||||
return version;
|
||||
}
|
||||
@@ -104,8 +104,7 @@ BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileN
|
||||
|
||||
foreach (QtVersionFactory *factory, factories) {
|
||||
if (!factory->m_restrictionChecker || factory->m_restrictionChecker(setup)) {
|
||||
QTC_ASSERT(factory->m_creator, continue);
|
||||
BaseQtVersion *ver = factory->m_creator();
|
||||
BaseQtVersion *ver = factory->create();
|
||||
QTC_ASSERT(ver, continue);
|
||||
ver->setupQmakePathAndId(qmakePath);
|
||||
ver->setAutoDetectionSource(autoDetectionSource);
|
||||
@@ -122,6 +121,35 @@ BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileN
|
||||
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)
|
||||
{
|
||||
m_creator = creator;
|
||||
|
@@ -51,10 +51,14 @@ public:
|
||||
/// the desktop factory claims to handle all paths
|
||||
int priority() const { return m_priority; }
|
||||
|
||||
QString supportedType() const;
|
||||
|
||||
static BaseQtVersion *createQtVersionFromQMakePath(
|
||||
const Utils::FileName &qmakePath, bool isAutoDetected = false,
|
||||
const QString &autoDetectionSource = QString(), QString *error = nullptr);
|
||||
|
||||
static BaseQtVersion *cloneQtVersion(const BaseQtVersion *source);
|
||||
|
||||
protected:
|
||||
struct SetupData
|
||||
{
|
||||
@@ -69,6 +73,8 @@ protected:
|
||||
void setPriority(int priority);
|
||||
|
||||
private:
|
||||
BaseQtVersion *create() const;
|
||||
|
||||
std::function<BaseQtVersion *()> m_creator;
|
||||
std::function<bool(const SetupData &)> m_restrictionChecker;
|
||||
QString m_supportedType;
|
||||
|
@@ -35,16 +35,6 @@
|
||||
namespace RemoteLinux {
|
||||
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
|
||||
{
|
||||
return QCoreApplication::translate("QtVersion", "Embedded Linux", "Qt Version is used for embedded Linux development");
|
||||
|
@@ -36,10 +36,6 @@ class EmbeddedLinuxQtVersion : public QtSupport::BaseQtVersion
|
||||
public:
|
||||
EmbeddedLinuxQtVersion() = default;
|
||||
|
||||
EmbeddedLinuxQtVersion *clone() const override;
|
||||
|
||||
QString type() const override;
|
||||
|
||||
QString description() const override;
|
||||
|
||||
QSet<Core::Id> targetDeviceTypes() const override;
|
||||
|
@@ -40,16 +40,6 @@ QString WinRtPhoneQtVersion::description() const
|
||||
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
|
||||
{
|
||||
return {Constants::WINRT_DEVICE_TYPE_PHONE, Constants::WINRT_DEVICE_TYPE_EMULATOR};
|
||||
|
@@ -39,8 +39,6 @@ public:
|
||||
QSet<Core::Id> availableFeatures() const override;
|
||||
|
||||
QString description() const override;
|
||||
BaseQtVersion *clone() const override;
|
||||
QString type() const override;
|
||||
QSet<Core::Id> targetDeviceTypes() const override;
|
||||
};
|
||||
|
||||
|
@@ -33,16 +33,6 @@
|
||||
namespace WinRt {
|
||||
namespace Internal {
|
||||
|
||||
QtSupport::BaseQtVersion *WinRtQtVersion::clone() const
|
||||
{
|
||||
return new WinRtQtVersion(*this);
|
||||
}
|
||||
|
||||
QString WinRtQtVersion::type() const
|
||||
{
|
||||
return QLatin1String(Constants::WINRT_WINRTQT);
|
||||
}
|
||||
|
||||
QString WinRtQtVersion::description() const
|
||||
{
|
||||
return tr("Windows Runtime");
|
||||
|
@@ -37,8 +37,6 @@ class WinRtQtVersion : public QtSupport::BaseQtVersion
|
||||
public:
|
||||
WinRtQtVersion() = default;
|
||||
|
||||
BaseQtVersion *clone() const override;
|
||||
QString type() const override;
|
||||
QString description() const override;
|
||||
QSet<Core::Id> availableFeatures() const override;
|
||||
|
||||
|
Reference in New Issue
Block a user