forked from qt-creator/qt-creator
ProjectExplorer: Use a lambda for DeviceFactory::create()
Somewhat slimmer interface on the user code side and follows existing practice. Change-Id: I20ed8f5a00591265d32ea9ce93e1f1bbc76d2437 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -663,34 +663,33 @@ AndroidDeviceManager::AndroidDeviceManager(QObject *parent)
|
||||
}
|
||||
|
||||
// Factory
|
||||
|
||||
AndroidDeviceFactory::AndroidDeviceFactory()
|
||||
: ProjectExplorer::IDeviceFactory(Constants::ANDROID_DEVICE_TYPE),
|
||||
: IDeviceFactory(Constants::ANDROID_DEVICE_TYPE),
|
||||
m_androidConfig(AndroidConfigurations::currentConfig())
|
||||
{
|
||||
setDisplayName(AndroidDevice::tr("Android Device"));
|
||||
setCombinedIcon(":/android/images/androiddevicesmall.png",
|
||||
":/android/images/androiddevice.png");
|
||||
|
||||
setConstructionFunction(&AndroidDevice::create);
|
||||
setCanCreate(m_androidConfig.sdkToolsOk());
|
||||
}
|
||||
setCreator([this] {
|
||||
AvdDialog dialog = AvdDialog(m_androidConfig, Core::ICore::dialogParent());
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
|
||||
IDevice::Ptr AndroidDeviceFactory::create() const
|
||||
{
|
||||
AvdDialog dialog = AvdDialog(m_androidConfig, Core::ICore::dialogParent());
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
return ProjectExplorer::IDevice::Ptr();
|
||||
const IDevice::Ptr dev = dialog.device();
|
||||
if (const auto androidDev = static_cast<AndroidDevice *>(dev.data())) {
|
||||
qCDebug(androidDeviceLog, "Created new Android AVD id \"%s\".",
|
||||
qPrintable(androidDev->avdName()));
|
||||
} else {
|
||||
AndroidDeviceWidget::criticalDialog(
|
||||
AndroidDevice::tr("The device info returned from AvdDialog is invalid."));
|
||||
}
|
||||
|
||||
const ProjectExplorer::IDevice::Ptr dev = dialog.device();
|
||||
const AndroidDevice *androidDev = static_cast<AndroidDevice*>(dev.data());
|
||||
if (androidDev) {
|
||||
qCDebug(androidDeviceLog, "Created new Android AVD id \"%s\".",
|
||||
qPrintable(androidDev->avdName()));
|
||||
} else {
|
||||
AndroidDeviceWidget::criticalDialog(
|
||||
QObject::tr("The device info returned from AvdDialog is invalid."));
|
||||
}
|
||||
|
||||
return IDevice::Ptr(dev);
|
||||
return IDevice::Ptr(dev);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -88,7 +88,6 @@ class AndroidDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
||||
{
|
||||
public:
|
||||
AndroidDeviceFactory();
|
||||
ProjectExplorer::IDevice::Ptr create() const override;
|
||||
|
||||
private:
|
||||
const AndroidConfig &m_androidConfig;
|
||||
|
@@ -125,16 +125,14 @@ BareMetalDeviceFactory::BareMetalDeviceFactory()
|
||||
setDisplayName(BareMetalDevice::tr("Bare Metal Device"));
|
||||
setCombinedIcon(":/baremetal/images/baremetaldevicesmall.png",
|
||||
":/baremetal/images/baremetaldevice.png");
|
||||
setCanCreate(true);
|
||||
setConstructionFunction(&BareMetalDevice::create);
|
||||
}
|
||||
|
||||
IDevice::Ptr BareMetalDeviceFactory::create() const
|
||||
{
|
||||
BareMetalDeviceConfigurationWizard wizard;
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return {};
|
||||
return wizard.device();
|
||||
setCanCreate(true);
|
||||
setCreator([] {
|
||||
BareMetalDeviceConfigurationWizard wizard;
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
return wizard.device();
|
||||
});
|
||||
}
|
||||
|
||||
} //namespace Internal
|
||||
|
@@ -71,9 +71,7 @@ private:
|
||||
class BareMetalDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
||||
{
|
||||
public:
|
||||
explicit BareMetalDeviceFactory();
|
||||
|
||||
ProjectExplorer::IDevice::Ptr create() const final;
|
||||
BareMetalDeviceFactory();
|
||||
};
|
||||
|
||||
} //namespace Internal
|
||||
|
@@ -286,17 +286,14 @@ QdbLinuxDeviceFactory::QdbLinuxDeviceFactory()
|
||||
{
|
||||
setDisplayName(QdbDevice::tr("Boot2Qt Device"));
|
||||
setCombinedIcon(":/qdb/images/qdbdevicesmall.png", ":/qdb/images/qdbdevice.png");
|
||||
setCanCreate(true);
|
||||
setConstructionFunction(&QdbDevice::create);
|
||||
}
|
||||
|
||||
IDevice::Ptr QdbLinuxDeviceFactory::create() const
|
||||
{
|
||||
QdbDeviceWizard wizard(Core::ICore::dialogParent());
|
||||
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
return wizard.device();
|
||||
setCanCreate(true);
|
||||
setCreator([] {
|
||||
QdbDeviceWizard wizard(Core::ICore::dialogParent());
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
return wizard.device();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -65,9 +65,6 @@ class QdbLinuxDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
||||
{
|
||||
public:
|
||||
QdbLinuxDeviceFactory();
|
||||
|
||||
private:
|
||||
ProjectExplorer::IDevice::Ptr create() const final;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -1803,15 +1803,6 @@ QString DockerDevicePrivate::outputForRunInShell(const CommandLine &cmd) const
|
||||
|
||||
// Factory
|
||||
|
||||
DockerDeviceFactory::DockerDeviceFactory()
|
||||
: IDeviceFactory(Constants::DOCKER_DEVICE_TYPE)
|
||||
{
|
||||
setDisplayName(DockerDevice::tr("Docker Device"));
|
||||
setIcon(QIcon());
|
||||
setCanCreate(true);
|
||||
setConstructionFunction([] { return DockerDevice::create({}); });
|
||||
}
|
||||
|
||||
class DockerImageItem final : public TreeItem, public DockerDeviceData
|
||||
{
|
||||
public:
|
||||
@@ -1915,7 +1906,7 @@ public:
|
||||
m_process->start();
|
||||
}
|
||||
|
||||
DockerDevice::Ptr device() const
|
||||
IDevice::Ptr device() const
|
||||
{
|
||||
const QModelIndexList selectedRows = m_view->selectionModel()->selectedRows();
|
||||
QTC_ASSERT(selectedRows.size() == 1, return {});
|
||||
@@ -1940,14 +1931,6 @@ public:
|
||||
QString m_selectedId;
|
||||
};
|
||||
|
||||
IDevice::Ptr DockerDeviceFactory::create() const
|
||||
{
|
||||
DockerDeviceSetupWizard wizard;
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
return wizard.device();
|
||||
}
|
||||
|
||||
void DockerDeviceWidget::updateDaemonStateTexts()
|
||||
{
|
||||
Utils::optional<bool> daemonState = DockerPlugin::isDaemonRunning();
|
||||
@@ -1963,5 +1946,22 @@ void DockerDeviceWidget::updateDaemonStateTexts()
|
||||
}
|
||||
}
|
||||
|
||||
// Factory
|
||||
|
||||
DockerDeviceFactory::DockerDeviceFactory()
|
||||
: IDeviceFactory(Constants::DOCKER_DEVICE_TYPE)
|
||||
{
|
||||
setDisplayName(DockerDevice::tr("Docker Device"));
|
||||
setIcon(QIcon());
|
||||
setCanCreate(true);
|
||||
setCreator([] {
|
||||
DockerDeviceSetupWizard wizard;
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
return wizard.device();
|
||||
});
|
||||
setConstructionFunction([] { return DockerDevice::create({}); });
|
||||
}
|
||||
|
||||
} // Internal
|
||||
} // Docker
|
||||
|
@@ -157,8 +157,6 @@ class DockerDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
||||
{
|
||||
public:
|
||||
DockerDeviceFactory();
|
||||
|
||||
ProjectExplorer::IDevice::Ptr create() const override;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
|
@@ -59,13 +59,9 @@ McuSupportDeviceFactory::McuSupportDeviceFactory()
|
||||
setDisplayName(McuSupportDevice::tr("MCU Device"));
|
||||
setCombinedIcon(":/mcusupport/images/mcusupportdevicesmall.png",
|
||||
":/mcusupport/images/mcusupportdevice.png");
|
||||
setCanCreate(true);
|
||||
setConstructionFunction(&McuSupportDevice::create);
|
||||
}
|
||||
|
||||
ProjectExplorer::IDevice::Ptr McuSupportDeviceFactory::create() const
|
||||
{
|
||||
return McuSupportDevice::create();
|
||||
setCanCreate(true);
|
||||
setCreator(&McuSupportDevice::create);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -45,8 +45,6 @@ class McuSupportDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
||||
{
|
||||
public:
|
||||
McuSupportDeviceFactory();
|
||||
|
||||
ProjectExplorer::IDevice::Ptr create() const override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -81,6 +81,11 @@ bool IDeviceFactory::canCreate() const
|
||||
return m_canCreate;
|
||||
}
|
||||
|
||||
IDevice::Ptr IDeviceFactory::create() const
|
||||
{
|
||||
return m_creator ? m_creator() : IDevice::Ptr();
|
||||
}
|
||||
|
||||
IDevice::Ptr IDeviceFactory::construct() const
|
||||
{
|
||||
return m_constructor ? m_constructor() : IDevice::Ptr();
|
||||
@@ -119,6 +124,11 @@ void IDeviceFactory::setCanCreate(bool canCreate)
|
||||
m_canCreate = canCreate;
|
||||
}
|
||||
|
||||
void IDeviceFactory::setCreator(const std::function<IDevice::Ptr ()> &creator)
|
||||
{
|
||||
m_creator = creator;
|
||||
}
|
||||
|
||||
void IDeviceFactory::setConstructionFunction(const std::function<IDevice::Ptr ()> &constructor)
|
||||
{
|
||||
m_constructor = constructor;
|
||||
|
@@ -44,8 +44,7 @@ public:
|
||||
QIcon icon() const { return m_icon; }
|
||||
bool canCreate() const;
|
||||
IDevice::Ptr construct() const;
|
||||
|
||||
virtual IDevice::Ptr create() const { return IDevice::Ptr(); }
|
||||
IDevice::Ptr create() const;
|
||||
|
||||
virtual bool canRestore(const QVariantMap &) const { return true; }
|
||||
|
||||
@@ -61,8 +60,10 @@ protected:
|
||||
void setCombinedIcon(const Utils::FilePath &small, const Utils::FilePath &large);
|
||||
void setCanCreate(bool canCreate);
|
||||
void setConstructionFunction(const std::function<IDevice::Ptr ()> &constructor);
|
||||
void setCreator(const std::function<IDevice::Ptr()> &creator);
|
||||
|
||||
private:
|
||||
std::function<IDevice::Ptr()> m_creator;
|
||||
const Utils::Id m_deviceType;
|
||||
QString m_displayName;
|
||||
QIcon m_icon;
|
||||
|
@@ -172,22 +172,19 @@ DeviceProcessSignalOperation::Ptr QnxDevice::signalOperation() const
|
||||
|
||||
// Factory
|
||||
|
||||
QnxDeviceFactory::QnxDeviceFactory()
|
||||
: ProjectExplorer::IDeviceFactory(Constants::QNX_QNX_OS_TYPE)
|
||||
QnxDeviceFactory::QnxDeviceFactory() : IDeviceFactory(Constants::QNX_QNX_OS_TYPE)
|
||||
{
|
||||
setDisplayName(QnxDevice::tr("QNX Device"));
|
||||
setCombinedIcon(":/qnx/images/qnxdevicesmall.png",
|
||||
":/qnx/images/qnxdevice.png");
|
||||
setCanCreate(true);
|
||||
setConstructionFunction(&QnxDevice::create);
|
||||
}
|
||||
|
||||
ProjectExplorer::IDevice::Ptr QnxDeviceFactory::create() const
|
||||
{
|
||||
QnxDeviceWizard wizard;
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return ProjectExplorer::IDevice::Ptr();
|
||||
return wizard.device();
|
||||
setCanCreate(true);
|
||||
setCreator([] {
|
||||
QnxDeviceWizard wizard;
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
return wizard.device();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -70,8 +70,6 @@ class QnxDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
||||
{
|
||||
public:
|
||||
QnxDeviceFactory();
|
||||
|
||||
ProjectExplorer::IDevice::Ptr create() const override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -51,20 +51,18 @@ TestLinuxDeviceFactory::TestLinuxDeviceFactory()
|
||||
{
|
||||
setDisplayName("Generic Linux Device");
|
||||
setIcon(QIcon());
|
||||
setCanCreate(true);
|
||||
setConstructionFunction(&LinuxDevice::create);
|
||||
}
|
||||
|
||||
IDevice::Ptr TestLinuxDeviceFactory::create() const
|
||||
{
|
||||
LinuxDevice::Ptr newDev = LinuxDevice::create();
|
||||
qDebug() << "device : " << newDev->type();
|
||||
newDev->setType("test");
|
||||
QSsh::SshConnectionParameters sshParams = newDev->sshParameters();
|
||||
sshParams.setHost(TEST_IP);
|
||||
sshParams.setPort(22);
|
||||
newDev->setSshParameters(sshParams);
|
||||
return newDev;
|
||||
setCanCreate(true);
|
||||
setCreator([] {
|
||||
LinuxDevice::Ptr newDev = LinuxDevice::create();
|
||||
qDebug() << "device : " << newDev->type();
|
||||
newDev->setType("test");
|
||||
QSsh::SshConnectionParameters sshParams = newDev->sshParameters();
|
||||
sshParams.setHost(TEST_IP);
|
||||
sshParams.setPort(22);
|
||||
newDev->setSshParameters(sshParams);
|
||||
return newDev;
|
||||
});
|
||||
}
|
||||
|
||||
FilePath createFile(const QString &name)
|
||||
|
@@ -37,8 +37,6 @@ class TestLinuxDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
||||
{
|
||||
public:
|
||||
TestLinuxDeviceFactory();
|
||||
|
||||
ProjectExplorer::IDevice::Ptr create() const override;
|
||||
};
|
||||
|
||||
class FileSystemAccessTest : public QObject
|
||||
|
@@ -754,17 +754,15 @@ LinuxDeviceFactory::LinuxDeviceFactory()
|
||||
{
|
||||
setDisplayName(LinuxDevice::tr("Generic Linux Device"));
|
||||
setIcon(QIcon());
|
||||
setCanCreate(true);
|
||||
setConstructionFunction(&LinuxDevice::create);
|
||||
setCanCreate(true);
|
||||
setCreator([] {
|
||||
GenericLinuxDeviceConfigurationWizard wizard(Core::ICore::dialogParent());
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
return wizard.device();
|
||||
});
|
||||
}
|
||||
|
||||
IDevice::Ptr LinuxDeviceFactory::create() const
|
||||
{
|
||||
GenericLinuxDeviceConfigurationWizard wizard(Core::ICore::dialogParent());
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return IDevice::Ptr();
|
||||
return wizard.device();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Internal
|
||||
} // namespace RemoteLinux
|
||||
|
@@ -100,8 +100,6 @@ class LinuxDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
||||
{
|
||||
public:
|
||||
LinuxDeviceFactory();
|
||||
|
||||
ProjectExplorer::IDevice::Ptr create() const override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -47,10 +47,9 @@ WebAssemblyDevice::WebAssemblyDevice()
|
||||
setOsType(OsTypeOther);
|
||||
}
|
||||
|
||||
ProjectExplorer::IDevice::Ptr WebAssemblyDevice::create()
|
||||
IDevice::Ptr WebAssemblyDevice::create()
|
||||
{
|
||||
auto device = new WebAssemblyDevice;
|
||||
return ProjectExplorer::IDevice::Ptr(device);
|
||||
return IDevice::Ptr(new WebAssemblyDevice);
|
||||
}
|
||||
|
||||
WebAssemblyDeviceFactory::WebAssemblyDeviceFactory()
|
||||
@@ -59,13 +58,9 @@ WebAssemblyDeviceFactory::WebAssemblyDeviceFactory()
|
||||
setDisplayName(WebAssemblyDevice::tr("WebAssembly Runtime"));
|
||||
setCombinedIcon(":/webassembly/images/webassemblydevicesmall.png",
|
||||
":/webassembly/images/webassemblydevice.png");
|
||||
setCanCreate(true);
|
||||
setConstructionFunction(&WebAssemblyDevice::create);
|
||||
}
|
||||
|
||||
ProjectExplorer::IDevice::Ptr WebAssemblyDeviceFactory::create() const
|
||||
{
|
||||
return WebAssemblyDevice::create();
|
||||
setCanCreate(true);
|
||||
setCreator(&WebAssemblyDevice::create);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -45,8 +45,6 @@ class WebAssemblyDeviceFactory final : public ProjectExplorer::IDeviceFactory
|
||||
{
|
||||
public:
|
||||
WebAssemblyDeviceFactory();
|
||||
|
||||
ProjectExplorer::IDevice::Ptr create() const override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
Reference in New Issue
Block a user