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