ProjectExplorer: Remove IDeviceFactory::setCanCreate

That's implicit now by using setCreator()

The Android case looks odd as this is (and was) effectively static
information at startup. This will be addressed in a follow-up patch,
for now keep it functionally equivalent.

Change-Id: I4e6082f88dcd21379186340189acb581caef172a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-01-26 10:00:24 +01:00
parent 41fee90d8e
commit 75ef67615d
11 changed files with 19 additions and 31 deletions

View File

@@ -673,23 +673,24 @@ AndroidDeviceFactory::AndroidDeviceFactory()
":/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();
if (m_androidConfig.sdkToolsOk()) {
setCreator([this] {
AvdDialog dialog = AvdDialog(m_androidConfig, Core::ICore::dialogParent());
if (dialog.exec() != QDialog::Accepted)
return 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 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."));
}
return IDevice::Ptr(dev);
});
return IDevice::Ptr(dev);
});
}
}
} // namespace Internal

View File

@@ -126,7 +126,6 @@ BareMetalDeviceFactory::BareMetalDeviceFactory()
setCombinedIcon(":/baremetal/images/baremetaldevicesmall.png",
":/baremetal/images/baremetaldevice.png");
setConstructionFunction(&BareMetalDevice::create);
setCanCreate(true);
setCreator([] {
BareMetalDeviceConfigurationWizard wizard;
if (wizard.exec() != QDialog::Accepted)

View File

@@ -287,7 +287,6 @@ QdbLinuxDeviceFactory::QdbLinuxDeviceFactory()
setDisplayName(QdbDevice::tr("Boot2Qt Device"));
setCombinedIcon(":/qdb/images/qdbdevicesmall.png", ":/qdb/images/qdbdevice.png");
setConstructionFunction(&QdbDevice::create);
setCanCreate(true);
setCreator([] {
QdbDeviceWizard wizard(Core::ICore::dialogParent());
if (wizard.exec() != QDialog::Accepted)

View File

@@ -1892,7 +1892,6 @@ DockerDeviceFactory::DockerDeviceFactory()
{
setDisplayName(DockerDevice::tr("Docker Device"));
setIcon(QIcon());
setCanCreate(true);
setCreator([] {
DockerDeviceSetupWizard wizard;
if (wizard.exec() != QDialog::Accepted)

View File

@@ -60,7 +60,6 @@ McuSupportDeviceFactory::McuSupportDeviceFactory()
setCombinedIcon(":/mcusupport/images/mcusupportdevicesmall.png",
":/mcusupport/images/mcusupportdevice.png");
setConstructionFunction(&McuSupportDevice::create);
setCanCreate(true);
setCreator(&McuSupportDevice::create);
}

View File

@@ -27,6 +27,7 @@
#include <utils/algorithm.h>
#include <utils/icon.h>
#include <utils/qtcassert.h>
using namespace Utils;
@@ -78,7 +79,7 @@ namespace ProjectExplorer {
bool IDeviceFactory::canCreate() const
{
return m_canCreate;
return bool(m_creator);
}
IDevice::Ptr IDeviceFactory::create() const
@@ -119,13 +120,9 @@ void IDeviceFactory::setCombinedIcon(const FilePath &small, const FilePath &larg
Icon({{large, Theme::IconsBaseColor}})});
}
void IDeviceFactory::setCanCreate(bool canCreate)
{
m_canCreate = canCreate;
}
void IDeviceFactory::setCreator(const std::function<IDevice::Ptr ()> &creator)
{
QTC_ASSERT(creator, return);
m_creator = creator;
}

View File

@@ -58,7 +58,6 @@ protected:
void setDisplayName(const QString &displayName);
void setIcon(const QIcon &icon);
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);
@@ -67,7 +66,6 @@ private:
const Utils::Id m_deviceType;
QString m_displayName;
QIcon m_icon;
bool m_canCreate = false;
std::function<IDevice::Ptr()> m_constructor;
};

View File

@@ -176,7 +176,6 @@ QnxDeviceFactory::QnxDeviceFactory() : IDeviceFactory(Constants::QNX_QNX_OS_TYPE
setCombinedIcon(":/qnx/images/qnxdevicesmall.png",
":/qnx/images/qnxdevice.png");
setConstructionFunction(&QnxDevice::create);
setCanCreate(true);
setCreator([] {
QnxDeviceWizard wizard;
if (wizard.exec() != QDialog::Accepted)

View File

@@ -52,7 +52,6 @@ TestLinuxDeviceFactory::TestLinuxDeviceFactory()
setDisplayName("Generic Linux Device");
setIcon(QIcon());
setConstructionFunction(&LinuxDevice::create);
setCanCreate(true);
setCreator([] {
LinuxDevice::Ptr newDev = LinuxDevice::create();
qDebug() << "device : " << newDev->type();

View File

@@ -800,7 +800,6 @@ LinuxDeviceFactory::LinuxDeviceFactory()
setDisplayName(LinuxDevice::tr("Generic Linux Device"));
setIcon(QIcon());
setConstructionFunction(&LinuxDevice::create);
setCanCreate(true);
setCreator([] {
GenericLinuxDeviceConfigurationWizard wizard(Core::ICore::dialogParent());
if (wizard.exec() != QDialog::Accepted)

View File

@@ -59,7 +59,6 @@ WebAssemblyDeviceFactory::WebAssemblyDeviceFactory()
setCombinedIcon(":/webassembly/images/webassemblydevicesmall.png",
":/webassembly/images/webassemblydevice.png");
setConstructionFunction(&WebAssemblyDevice::create);
setCanCreate(true);
setCreator(&WebAssemblyDevice::create);
}