forked from qt-creator/qt-creator
Handle IDeviceFactory restoring in base class
Change-Id: Idb892bcff6b91dbc11a8271915e5cc86d1669e74 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -38,12 +38,7 @@ AndroidDeviceFactory::AndroidDeviceFactory()
|
|||||||
setDisplayName(tr("Android Device"));
|
setDisplayName(tr("Android Device"));
|
||||||
setCombinedIcon(":/android/images/androiddevicesmall.png",
|
setCombinedIcon(":/android/images/androiddevicesmall.png",
|
||||||
":/android/images/androiddevice.png");
|
":/android/images/androiddevice.png");
|
||||||
}
|
setConstructionFunction([] { return ProjectExplorer::IDevice::Ptr(new AndroidDevice); });
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr AndroidDeviceFactory::restore(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(map)
|
|
||||||
return ProjectExplorer::IDevice::Ptr(new AndroidDevice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -35,8 +35,6 @@ class AndroidDeviceFactory : public ProjectExplorer::IDeviceFactory
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AndroidDeviceFactory();
|
AndroidDeviceFactory();
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr restore(const QVariantMap &map) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -43,6 +43,7 @@ BareMetalDeviceConfigurationFactory::BareMetalDeviceConfigurationFactory()
|
|||||||
setCombinedIcon(":/baremetal/images/baremetaldevicesmall.png",
|
setCombinedIcon(":/baremetal/images/baremetaldevicesmall.png",
|
||||||
":/baremetal/images/baremetaldevice.png");
|
":/baremetal/images/baremetaldevice.png");
|
||||||
setCanCreate(true);
|
setCanCreate(true);
|
||||||
|
setConstructionFunction([] { return BareMetalDevice::create(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
IDevice::Ptr BareMetalDeviceConfigurationFactory::create() const
|
IDevice::Ptr BareMetalDeviceConfigurationFactory::create() const
|
||||||
@@ -53,13 +54,5 @@ IDevice::Ptr BareMetalDeviceConfigurationFactory::create() const
|
|||||||
return wizard.device();
|
return wizard.device();
|
||||||
}
|
}
|
||||||
|
|
||||||
IDevice::Ptr BareMetalDeviceConfigurationFactory::restore(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(canRestore(map), return IDevice::Ptr());
|
|
||||||
const IDevice::Ptr device = BareMetalDevice::create();
|
|
||||||
device->fromMap(map);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace BareMetal
|
} // namespace BareMetal
|
||||||
|
@@ -39,7 +39,6 @@ public:
|
|||||||
BareMetalDeviceConfigurationFactory();
|
BareMetalDeviceConfigurationFactory();
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr create() const override;
|
ProjectExplorer::IDevice::Ptr create() const override;
|
||||||
ProjectExplorer::IDevice::Ptr restore(const QVariantMap &map) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -38,6 +38,7 @@ IosDeviceFactory::IosDeviceFactory()
|
|||||||
setDisplayName(IosDevice::name());
|
setDisplayName(IosDevice::name());
|
||||||
setCombinedIcon(":/ios/images/iosdevicesmall.png",
|
setCombinedIcon(":/ios/images/iosdevicesmall.png",
|
||||||
":/ios/images/iosdevice.png");
|
":/ios/images/iosdevice.png");
|
||||||
|
setConstructionFunction([] { return ProjectExplorer::IDevice::Ptr(new IosDevice); });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IosDeviceFactory::canRestore(const QVariantMap &map) const
|
bool IosDeviceFactory::canRestore(const QVariantMap &map) const
|
||||||
@@ -49,14 +50,5 @@ bool IosDeviceFactory::canRestore(const QVariantMap &map) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr IosDeviceFactory::restore(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
IosDevice *newDev = new IosDevice;
|
|
||||||
newDev->fromMap(map);
|
|
||||||
// updating the active ones should be enough...
|
|
||||||
//IosDeviceManager::instance()->updateInfo(newDev->uniqueDeviceID());
|
|
||||||
return ProjectExplorer::IDevice::Ptr(newDev);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Ios
|
} // namespace Ios
|
||||||
|
@@ -37,7 +37,6 @@ public:
|
|||||||
IosDeviceFactory();
|
IosDeviceFactory();
|
||||||
|
|
||||||
bool canRestore(const QVariantMap &map) const override;
|
bool canRestore(const QVariantMap &map) const override;
|
||||||
ProjectExplorer::IDevice::Ptr restore(const QVariantMap &map) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -40,14 +40,7 @@ IosSimulatorFactory::IosSimulatorFactory()
|
|||||||
setDisplayName(tr("iOS Simulator"));
|
setDisplayName(tr("iOS Simulator"));
|
||||||
setCombinedIcon(":/ios/images/iosdevicesmall.png",
|
setCombinedIcon(":/ios/images/iosdevicesmall.png",
|
||||||
":/ios/images/iosdevice.png");
|
":/ios/images/iosdevice.png");
|
||||||
}
|
setConstructionFunction([] { return ProjectExplorer::IDevice::Ptr(new IosSimulator()); });
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr IosSimulatorFactory::restore(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(canRestore(map), return ProjectExplorer::IDevice::Ptr());
|
|
||||||
const ProjectExplorer::IDevice::Ptr device = ProjectExplorer::IDevice::Ptr(new IosSimulator());
|
|
||||||
device->fromMap(map);
|
|
||||||
return device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -35,8 +35,6 @@ class IosSimulatorFactory : public ProjectExplorer::IDeviceFactory
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
IosSimulatorFactory();
|
IosSimulatorFactory();
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr restore(const QVariantMap &map) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -40,6 +40,7 @@ namespace Internal {
|
|||||||
DesktopDeviceFactory::DesktopDeviceFactory()
|
DesktopDeviceFactory::DesktopDeviceFactory()
|
||||||
: IDeviceFactory(Constants::DESKTOP_DEVICE_TYPE)
|
: IDeviceFactory(Constants::DESKTOP_DEVICE_TYPE)
|
||||||
{
|
{
|
||||||
|
setConstructionFunction([] { return IDevice::Ptr(new DesktopDevice); });
|
||||||
setDisplayName(tr("Desktop"));
|
setDisplayName(tr("Desktop"));
|
||||||
setIcon(Utils::creatorTheme()->flag(Utils::Theme::FlatSideBarIcons)
|
setIcon(Utils::creatorTheme()->flag(Utils::Theme::FlatSideBarIcons)
|
||||||
? Utils::Icon::combinedIcon({Icons::DESKTOP_DEVICE.icon(),
|
? Utils::Icon::combinedIcon({Icons::DESKTOP_DEVICE.icon(),
|
||||||
@@ -47,13 +48,5 @@ DesktopDeviceFactory::DesktopDeviceFactory()
|
|||||||
: QApplication::style()->standardIcon(QStyle::SP_ComputerIcon));
|
: QApplication::style()->standardIcon(QStyle::SP_ComputerIcon));
|
||||||
}
|
}
|
||||||
|
|
||||||
IDevice::Ptr DesktopDeviceFactory::restore(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(canRestore(map), return ProjectExplorer::IDevice::Ptr());
|
|
||||||
const ProjectExplorer::IDevice::Ptr device = IDevice::Ptr(new DesktopDevice);
|
|
||||||
device->fromMap(map);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
@@ -34,8 +34,6 @@ class DesktopDeviceFactory : public IDeviceFactory
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DesktopDeviceFactory();
|
DesktopDeviceFactory();
|
||||||
|
|
||||||
IDevice::Ptr restore(const QVariantMap &map) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -199,8 +199,9 @@ QList<IDevice::Ptr> DeviceManager::fromMap(const QVariantMap &map,
|
|||||||
const IDeviceFactory * const factory = restoreFactory(map);
|
const IDeviceFactory * const factory = restoreFactory(map);
|
||||||
if (!factory)
|
if (!factory)
|
||||||
continue;
|
continue;
|
||||||
const IDevice::Ptr device = factory->restore(map);
|
const IDevice::Ptr device = factory->construct();
|
||||||
QTC_ASSERT(device, continue);
|
QTC_ASSERT(device, continue);
|
||||||
|
device->fromMap(map);
|
||||||
devices << device;
|
devices << device;
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
|
@@ -79,6 +79,11 @@ bool IDeviceFactory::canCreate() const
|
|||||||
return m_canCreate;
|
return m_canCreate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IDevice::Ptr IDeviceFactory::construct() const
|
||||||
|
{
|
||||||
|
return m_constructor ? m_constructor() : IDevice::Ptr();
|
||||||
|
}
|
||||||
|
|
||||||
static QList<IDeviceFactory *> g_deviceFactories;
|
static QList<IDeviceFactory *> g_deviceFactories;
|
||||||
|
|
||||||
IDeviceFactory *IDeviceFactory::find(Core::Id type)
|
IDeviceFactory *IDeviceFactory::find(Core::Id type)
|
||||||
@@ -112,6 +117,11 @@ void IDeviceFactory::setCanCreate(bool canCreate)
|
|||||||
m_canCreate = canCreate;
|
m_canCreate = canCreate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IDeviceFactory::setConstructionFunction(const std::function<IDevice::Ptr ()> &constructor)
|
||||||
|
{
|
||||||
|
m_constructor = constructor;
|
||||||
|
}
|
||||||
|
|
||||||
void IDeviceFactory::setDisplayName(const QString &displayName)
|
void IDeviceFactory::setDisplayName(const QString &displayName)
|
||||||
{
|
{
|
||||||
m_displayName = displayName;
|
m_displayName = displayName;
|
||||||
|
@@ -45,11 +45,11 @@ public:
|
|||||||
QString displayName() const { return m_displayName; }
|
QString displayName() const { return m_displayName; }
|
||||||
QIcon icon() const { return m_icon; }
|
QIcon icon() const { return m_icon; }
|
||||||
bool canCreate() const;
|
bool canCreate() const;
|
||||||
|
IDevice::Ptr construct() const;
|
||||||
|
|
||||||
virtual IDevice::Ptr create() const { return IDevice::Ptr(); }
|
virtual IDevice::Ptr create() const { return IDevice::Ptr(); }
|
||||||
|
|
||||||
virtual bool canRestore(const QVariantMap &) const { return true; }
|
virtual bool canRestore(const QVariantMap &) const { return true; }
|
||||||
virtual IDevice::Ptr restore(const QVariantMap &map) const = 0;
|
|
||||||
|
|
||||||
static IDeviceFactory *find(Core::Id type);
|
static IDeviceFactory *find(Core::Id type);
|
||||||
|
|
||||||
@@ -60,12 +60,14 @@ protected:
|
|||||||
void setIcon(const QIcon &icon);
|
void setIcon(const QIcon &icon);
|
||||||
void setCombinedIcon(const QString &small, const QString &large);
|
void setCombinedIcon(const QString &small, const QString &large);
|
||||||
void setCanCreate(bool canCreate);
|
void setCanCreate(bool canCreate);
|
||||||
|
void setConstructionFunction(const std::function<IDevice::Ptr ()> &constructor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Core::Id m_deviceType;
|
const Core::Id m_deviceType;
|
||||||
QString m_displayName;
|
QString m_displayName;
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
bool m_canCreate = false;
|
bool m_canCreate = false;
|
||||||
|
std::function<IDevice::Ptr()> m_constructor;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
@@ -41,6 +41,7 @@ QnxDeviceFactory::QnxDeviceFactory()
|
|||||||
setCombinedIcon(":/qnx/images/qnxdevicesmall.png",
|
setCombinedIcon(":/qnx/images/qnxdevicesmall.png",
|
||||||
":/qnx/images/qnxdevice.png");
|
":/qnx/images/qnxdevice.png");
|
||||||
setCanCreate(true);
|
setCanCreate(true);
|
||||||
|
setConstructionFunction([] { return QnxDevice::create(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr QnxDeviceFactory::create() const
|
ProjectExplorer::IDevice::Ptr QnxDeviceFactory::create() const
|
||||||
@@ -51,14 +52,6 @@ ProjectExplorer::IDevice::Ptr QnxDeviceFactory::create() const
|
|||||||
return wizard.device();
|
return wizard.device();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr QnxDeviceFactory::restore(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(canRestore(map), return QnxDevice::Ptr());
|
|
||||||
const QnxDevice::Ptr device = QnxDevice::create();
|
|
||||||
device->fromMap(map);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::Id QnxDeviceFactory::deviceType()
|
Core::Id QnxDeviceFactory::deviceType()
|
||||||
{
|
{
|
||||||
return Core::Id(Constants::QNX_QNX_OS_TYPE);
|
return Core::Id(Constants::QNX_QNX_OS_TYPE);
|
||||||
|
@@ -38,7 +38,6 @@ public:
|
|||||||
QnxDeviceFactory();
|
QnxDeviceFactory();
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr create() const override;
|
ProjectExplorer::IDevice::Ptr create() const override;
|
||||||
ProjectExplorer::IDevice::Ptr restore(const QVariantMap &map) const override;
|
|
||||||
|
|
||||||
static Core::Id deviceType();
|
static Core::Id deviceType();
|
||||||
};
|
};
|
||||||
|
@@ -43,6 +43,7 @@ GenericLinuxDeviceConfigurationFactory::GenericLinuxDeviceConfigurationFactory()
|
|||||||
setDisplayName(tr("Generic Linux Device"));
|
setDisplayName(tr("Generic Linux Device"));
|
||||||
setIcon(QIcon());
|
setIcon(QIcon());
|
||||||
setCanCreate(true);
|
setCanCreate(true);
|
||||||
|
setConstructionFunction([] { return LinuxDevice::create(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
IDevice::Ptr GenericLinuxDeviceConfigurationFactory::create() const
|
IDevice::Ptr GenericLinuxDeviceConfigurationFactory::create() const
|
||||||
@@ -53,12 +54,4 @@ IDevice::Ptr GenericLinuxDeviceConfigurationFactory::create() const
|
|||||||
return wizard.device();
|
return wizard.device();
|
||||||
}
|
}
|
||||||
|
|
||||||
IDevice::Ptr GenericLinuxDeviceConfigurationFactory::restore(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(canRestore(map), return IDevice::Ptr());
|
|
||||||
const IDevice::Ptr device = LinuxDevice::create();
|
|
||||||
device->fromMap(map);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace RemoteLinux
|
} // namespace RemoteLinux
|
||||||
|
@@ -40,7 +40,6 @@ public:
|
|||||||
GenericLinuxDeviceConfigurationFactory();
|
GenericLinuxDeviceConfigurationFactory();
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr create() const override;
|
ProjectExplorer::IDevice::Ptr create() const override;
|
||||||
ProjectExplorer::IDevice::Ptr restore(const QVariantMap &map) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace RemoteLinux
|
} // namespace RemoteLinux
|
||||||
|
@@ -59,17 +59,11 @@ WinRtDeviceFactory::WinRtDeviceFactory(Core::Id deviceType)
|
|||||||
this, &WinRtDeviceFactory::onPrerequisitesLoaded, Qt::QueuedConnection);
|
this, &WinRtDeviceFactory::onPrerequisitesLoaded, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
setDisplayName(WinRtDevice::displayNameForType(deviceType));
|
setDisplayName(WinRtDevice::displayNameForType(deviceType));
|
||||||
|
setConstructionFunction([] { return IDevice::Ptr(new WinRtDevice); });
|
||||||
setCombinedIcon(":/winrt/images/winrtdevicesmall.png",
|
setCombinedIcon(":/winrt/images/winrtdevicesmall.png",
|
||||||
":/winrt/images/winrtdevice.png");
|
":/winrt/images/winrtdevice.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
IDevice::Ptr WinRtDeviceFactory::restore(const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
const IDevice::Ptr device(new WinRtDevice);
|
|
||||||
device->fromMap(map);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WinRtDeviceFactory::autoDetect()
|
void WinRtDeviceFactory::autoDetect()
|
||||||
{
|
{
|
||||||
MessageManager::write(tr("Running Windows Runtime device detection."));
|
MessageManager::write(tr("Running Windows Runtime device detection."));
|
||||||
|
@@ -37,8 +37,6 @@ class WinRtDeviceFactory : public ProjectExplorer::IDeviceFactory
|
|||||||
public:
|
public:
|
||||||
explicit WinRtDeviceFactory(Core::Id deviceType);
|
explicit WinRtDeviceFactory(Core::Id deviceType);
|
||||||
|
|
||||||
ProjectExplorer::IDevice::Ptr restore(const QVariantMap &map) const override;
|
|
||||||
|
|
||||||
void autoDetect();
|
void autoDetect();
|
||||||
void onPrerequisitesLoaded();
|
void onPrerequisitesLoaded();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user