ProjectExplorer: Allow Devices to be added without using the wizard

This re-organizes the buttons on the main device page a bit: The
topmost one still starts the wizard selection, below that are direct
individual buttons to add specific devices.

Change-Id: I52b2803febf658259dde9589544656fd4c8fc889
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2023-03-23 15:32:42 +01:00
parent 17a482bebe
commit 5996e58ffa
10 changed files with 80 additions and 25 deletions

View File

@@ -847,7 +847,6 @@ AndroidDeviceFactory::AndroidDeviceFactory()
setDisplayName(Tr::tr("Android Device"));
setCombinedIcon(":/android/images/androiddevicesmall.png",
":/android/images/androiddevice.png");
setConstructionFunction(&AndroidDevice::create);
if (m_androidConfig.sdkToolsOk()) {
setCreator([this] {

View File

@@ -24,7 +24,6 @@ const char debugServerProviderIdKeyC[] = "IDebugServerProviderId";
BareMetalDevice::BareMetalDevice()
{
setDisplayType(Tr::tr("Bare Metal"));
setDefaultDisplayName(defaultDisplayName());
setOsType(Utils::OsTypeOther);
}

View File

@@ -104,6 +104,7 @@ private:
QdbDevice::QdbDevice()
{
setDisplayType(Tr::tr("Boot2Qt Device"));
setType(Constants::QdbLinuxOsType);
addDeviceAction({Tr::tr("Reboot Device"), [](const IDevice::Ptr &device, QWidget *) {
(void) new DeviceApplicationObserver(device, {device->filePath("reboot"), {}});
@@ -247,6 +248,7 @@ QdbLinuxDeviceFactory::QdbLinuxDeviceFactory()
{
setDisplayName(Tr::tr("Boot2Qt Device"));
setCombinedIcon(":/qdb/images/qdbdevicesmall.png", ":/qdb/images/qdbdevice.png");
setQuickCreationAllowed(true);
setConstructionFunction(&QdbDevice::create);
setCreator([] {
QdbDeviceWizard wizard(Core::ICore::dialogParent());

View File

@@ -383,7 +383,9 @@ DockerDevice::DockerDevice(DockerSettings *settings, const DockerDeviceData &dat
setDisplayType(Tr::tr("Docker"));
setOsType(OsTypeOtherUnix);
setDefaultDisplayName(Tr::tr("Docker Image"));
setupId(IDevice::ManuallyAdded);
setType(Constants::DOCKER_DEVICE_TYPE);
setMachineType(IDevice::Hardware);
setDisplayName(Tr::tr("Docker Image \"%1\" (%2)").arg(data.repoAndTag()).arg(data.imageId));
setAllowEmptyCommand(true);
@@ -1095,9 +1097,6 @@ public:
QTC_ASSERT(item, return {});
auto device = DockerDevice::create(m_settings, *item);
device->setupId(IDevice::ManuallyAdded);
device->setType(Constants::DOCKER_DEVICE_TYPE);
device->setMachineType(IDevice::Hardware);
return device;
}

View File

@@ -101,14 +101,31 @@ void DeviceSettingsWidget::initGui()
m_deviceStateTextLabel = new QLabel;
m_osSpecificGroupBox = new QGroupBox(Tr::tr("Type Specific"));
m_osSpecificGroupBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
m_addConfigButton = new QPushButton(Tr::tr("&Add..."));
m_addConfigButton = new QPushButton(Tr::tr("&Start Wizard to Add Device..."));
m_removeConfigButton = new QPushButton(Tr::tr("&Remove"));
m_defaultDeviceButton = new QPushButton(Tr::tr("Set As Default"));
auto line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
auto customButtonsContainer = new QWidget;
m_buttonsLayout = new QVBoxLayout(customButtonsContainer);
auto directLayout = new QVBoxLayout;
for (IDeviceFactory *factory : IDeviceFactory::allDeviceFactories()) {
if (!factory->canCreate())
continue;
auto button = new QPushButton(Tr::tr("Add %1").arg(factory->displayName()));
directLayout->addWidget(button);
if (!factory->quickCreationAllowed()) {
button->setEnabled(false);
continue;
}
connect (button, &QPushButton::clicked, this, [factory, this] {
IDevice::Ptr device = factory->construct();
QTC_ASSERT(device, return);
m_deviceManager->addDevice(device);
m_removeConfigButton->setEnabled(true);
m_configurationComboBox->setCurrentIndex(m_deviceManagerModel->indexOf(device));
saveSettings();
});
}
m_buttonsLayout = new QVBoxLayout;
m_buttonsLayout->setContentsMargins({});
auto scrollAreaWidget = new QWidget;
auto scrollArea = new QScrollArea;
@@ -135,10 +152,12 @@ void DeviceSettingsWidget::initGui()
},
Column {
m_addConfigButton,
Space(10),
directLayout,
Space(30),
m_removeConfigButton,
m_defaultDeviceButton,
line,
customButtonsContainer,
m_buttonsLayout,
st,
},
}.attachTo(this);

View File

@@ -63,12 +63,24 @@ bool IDeviceFactory::canCreate() const
IDevice::Ptr IDeviceFactory::create() const
{
return m_creator ? m_creator() : IDevice::Ptr();
if (m_creator)
return {};
IDevice::Ptr device = m_constructor();
QTC_ASSERT(device, return {});
device->setDefaultDisplayName(displayName());
return device;
}
IDevice::Ptr IDeviceFactory::construct() const
{
return m_constructor ? m_constructor() : IDevice::Ptr();
if (!m_constructor)
return {};
IDevice::Ptr device = m_constructor();
QTC_ASSERT(device, return {});
device->setDefaultDisplayName(displayName());
return device;
}
static QList<IDeviceFactory *> g_deviceFactories;
@@ -105,6 +117,16 @@ void IDeviceFactory::setCreator(const std::function<IDevice::Ptr ()> &creator)
m_creator = creator;
}
void IDeviceFactory::setQuickCreationAllowed(bool on)
{
m_quickCreationAllowed = on;
}
bool IDeviceFactory::quickCreationAllowed() const
{
return m_quickCreationAllowed;
}
void IDeviceFactory::setConstructionFunction(const std::function<IDevice::Ptr ()> &constructor)
{
m_constructor = constructor;

View File

@@ -26,6 +26,7 @@ public:
bool canCreate() const;
IDevicePtr construct() const;
IDevicePtr create() const;
bool quickCreationAllowed() const;
virtual bool canRestore(const QVariantMap &) const { return true; }
@@ -41,6 +42,7 @@ protected:
void setCombinedIcon(const Utils::FilePath &smallIcon, const Utils::FilePath &largeIcon);
void setConstructionFunction(const std::function<IDevicePtr ()> &constructor);
void setCreator(const std::function<IDevicePtr()> &creator);
void setQuickCreationAllowed(bool on);
private:
std::function<IDevicePtr()> m_creator;
@@ -48,6 +50,7 @@ private:
QString m_displayName;
QIcon m_icon;
std::function<IDevicePtr()> m_constructor;
bool m_quickCreationAllowed = false;
};
} // namespace ProjectExplorer

View File

@@ -9,9 +9,12 @@
#include "qnxdevicewizard.h"
#include "qnxtr.h"
#include <projectexplorer/devicesupport/sshparameters.h>
#include <remotelinux/remotelinuxsignaloperation.h>
#include <utils/port.h>
#include <utils/portlist.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
@@ -56,6 +59,13 @@ QnxDevice::QnxDevice()
setDisplayType(Tr::tr("QNX"));
setDefaultDisplayName(Tr::tr("QNX Device"));
setOsType(OsTypeOtherUnix);
setupId(IDevice::ManuallyAdded);
setType(Constants::QNX_QNX_OS_TYPE);
setMachineType(IDevice::Hardware);
SshParameters sshParams;
sshParams.timeout = 10;
setSshParameters(sshParams);
setFreePorts(PortList::fromString("10000-10100"));
addDeviceAction({Tr::tr("Deploy Qt libraries..."), [](const IDevice::Ptr &device, QWidget *parent) {
QnxDeployQtLibrariesDialog dialog(device, parent);
@@ -94,6 +104,7 @@ QnxDeviceFactory::QnxDeviceFactory() : IDeviceFactory(Constants::QNX_QNX_OS_TYPE
setDisplayName(Tr::tr("QNX Device"));
setCombinedIcon(":/qnx/images/qnxdevicesmall.png",
":/qnx/images/qnxdevice.png");
setQuickCreationAllowed(true);
setConstructionFunction(&QnxDevice::create);
setCreator(&runDeviceWizard);
}

View File

@@ -11,7 +11,6 @@
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/devicesupport/sshparameters.h>
#include <utils/portlist.h>
#include <utils/fileutils.h>
using namespace ProjectExplorer;
@@ -45,13 +44,6 @@ GenericLinuxDeviceConfigurationWizard::GenericLinuxDeviceConfigurationWizard(QWi
setPage(Internal::FinalPageId, &d->finalPage);
d->finalPage.setCommitPage(true);
d->device = LinuxDevice::create();
d->device->setupId(IDevice::ManuallyAdded, Utils::Id());
d->device->setType(Constants::GenericLinuxOsType);
d->device->setMachineType(IDevice::Hardware);
d->device->setFreePorts(Utils::PortList::fromString(QLatin1String("10000-10100")));
SshParameters sshParams;
sshParams.timeout = 10;
d->device->setSshParameters(sshParams);
d->setupPage.setDevice(d->device);
d->keyDeploymentPage.setDevice(d->device);
}

View File

@@ -27,6 +27,7 @@
#include <utils/environment.h>
#include <utils/hostosinfo.h>
#include <utils/port.h>
#include <utils/portlist.h>
#include <utils/processinfo.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
@@ -887,9 +888,16 @@ LinuxDevice::LinuxDevice()
{
setFileAccess(&d->m_fileAccess);
setDisplayType(Tr::tr("Remote Linux"));
setDefaultDisplayName(Tr::tr("Remote Linux Device"));
setOsType(OsTypeLinux);
setupId(IDevice::ManuallyAdded, Utils::Id());
setType(Constants::GenericLinuxOsType);
setMachineType(IDevice::Hardware);
setFreePorts(PortList::fromString(QLatin1String("10000-10100")));
SshParameters sshParams;
sshParams.timeout = 10;
setSshParameters(sshParams);
addDeviceAction({Tr::tr("Deploy Public Key..."), [](const IDevice::Ptr &device, QWidget *parent) {
if (auto d = PublicKeyDeploymentDialog::createDialog(device, parent)) {
d->exec();
@@ -1489,6 +1497,7 @@ LinuxDeviceFactory::LinuxDeviceFactory()
setDisplayName(Tr::tr("Remote Linux Device"));
setIcon(QIcon());
setConstructionFunction(&LinuxDevice::create);
setQuickCreationAllowed(true);
setCreator([] {
GenericLinuxDeviceConfigurationWizard wizard(Core::ICore::dialogParent());
if (wizard.exec() != QDialog::Accepted)