ProjectExplorer: inline devicesettingswidget.ui

Change-Id: I806fc291e0096c2dadb5489be32cde8f87b1e41b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Alessandro Portale
2022-08-29 13:19:08 +02:00
parent d76ba33381
commit a531a8c64e
5 changed files with 125 additions and 289 deletions

View File

@@ -57,7 +57,7 @@ add_qtc_plugin(ProjectExplorer
devicesupport/deviceprocessesdialog.cpp devicesupport/deviceprocessesdialog.h
devicesupport/deviceprocesslist.cpp devicesupport/deviceprocesslist.h
devicesupport/devicesettingspage.cpp devicesupport/devicesettingspage.h
devicesupport/devicesettingswidget.cpp devicesupport/devicesettingswidget.h devicesupport/devicesettingswidget.ui
devicesupport/devicesettingswidget.cpp devicesupport/devicesettingswidget.h
devicesupport/devicetestdialog.cpp devicesupport/devicetestdialog.h
devicesupport/deviceusedportsgatherer.cpp devicesupport/deviceusedportsgatherer.h
devicesupport/filetransfer.cpp devicesupport/filetransfer.h

View File

@@ -2,7 +2,6 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "devicesettingswidget.h"
#include "ui_devicesettingswidget.h"
#include "devicefactoryselectiondialog.h"
#include "devicemanager.h"
@@ -17,12 +16,19 @@
#include <coreplugin/icore.h>
#include <utils/qtcassert.h>
#include <utils/algorithm.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <QPixmap>
#include <QComboBox>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
#include <QTextStream>
#include <QVBoxLayout>
#include <QValidator>
#include <algorithm>
@@ -64,8 +70,7 @@ private:
};
DeviceSettingsWidget::DeviceSettingsWidget()
: m_ui(new Ui::DeviceSettingsWidget),
m_deviceManager(DeviceManager::cloneInstance()),
: m_deviceManager(DeviceManager::cloneInstance()),
m_deviceManagerModel(new DeviceManagerModel(m_deviceManager, this)),
m_nameValidator(new NameValidator(m_deviceManager, this)),
m_configWidget(nullptr)
@@ -79,36 +84,85 @@ DeviceSettingsWidget::~DeviceSettingsWidget()
{
DeviceManager::removeClonedInstance();
delete m_configWidget;
delete m_ui;
}
void DeviceSettingsWidget::initGui()
{
m_ui->setupUi(this);
m_ui->configurationComboBox->setModel(m_deviceManagerModel);
m_ui->nameLineEdit->setValidator(m_nameValidator);
m_configurationLabel = new QLabel(tr("&Device:"));
m_configurationComboBox = new QComboBox;
m_configurationComboBox->setModel(m_deviceManagerModel);
m_generalGroupBox = new QGroupBox(tr("General"));
m_nameLineEdit = new QLineEdit;
m_nameLineEdit->setValidator(m_nameValidator);
m_osTypeValueLabel = new QLabel;
m_autoDetectionLabel = new QLabel;
m_deviceStateIconLabel = new QLabel;
m_deviceStateTextLabel = new QLabel;
m_osSpecificGroupBox = new QGroupBox(tr("Type Specific"));
m_osSpecificGroupBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
m_addConfigButton = new QPushButton(tr("&Add..."));
m_removeConfigButton = new QPushButton(tr("&Remove"));
m_defaultDeviceButton = new QPushButton(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);
m_buttonsLayout->setContentsMargins({});
auto scrollAreaWidget = new QWidget;
auto scrollArea = new QScrollArea;
scrollArea->setWidgetResizable(true);
scrollArea->setWidget(scrollAreaWidget);
using namespace Utils::Layouting;
Column {
m_generalGroupBox,
m_osSpecificGroupBox,
}.attachTo(scrollAreaWidget);
Form {
tr("&Name:"), m_nameLineEdit, br,
tr("Type:"), m_osTypeValueLabel, br,
tr("Auto-detected:"), m_autoDetectionLabel, br,
tr("Current state:"), Row { m_deviceStateIconLabel, m_deviceStateTextLabel, st, }, br,
}.attachTo(m_generalGroupBox);
Row {
Column {
Form { m_configurationLabel, m_configurationComboBox, br, },
scrollArea,
},
Column {
m_addConfigButton,
m_removeConfigButton,
m_defaultDeviceButton,
line,
customButtonsContainer,
st,
},
}.attachTo(this);
bool hasDeviceFactories = Utils::anyOf(IDeviceFactory::allDeviceFactories(),
&IDeviceFactory::canCreate);
m_ui->addConfigButton->setEnabled(hasDeviceFactories);
m_addConfigButton->setEnabled(hasDeviceFactories);
int lastIndex = ICore::settings()
->value(QLatin1String(LastDeviceIndexKey), 0).toInt();
if (lastIndex == -1)
lastIndex = 0;
if (lastIndex < m_ui->configurationComboBox->count())
m_ui->configurationComboBox->setCurrentIndex(lastIndex);
connect(m_ui->configurationComboBox, &QComboBox::currentIndexChanged,
if (lastIndex < m_configurationComboBox->count())
m_configurationComboBox->setCurrentIndex(lastIndex);
connect(m_configurationComboBox, &QComboBox::currentIndexChanged,
this, &DeviceSettingsWidget::currentDeviceChanged);
currentDeviceChanged(currentIndex());
connect(m_ui->defaultDeviceButton, &QAbstractButton::clicked,
connect(m_defaultDeviceButton, &QAbstractButton::clicked,
this, &DeviceSettingsWidget::setDefaultDevice);
connect(m_ui->removeConfigButton, &QAbstractButton::clicked,
connect(m_removeConfigButton, &QAbstractButton::clicked,
this, &DeviceSettingsWidget::removeDevice);
connect(m_ui->nameLineEdit, &QLineEdit::editingFinished,
connect(m_nameLineEdit, &QLineEdit::editingFinished,
this, &DeviceSettingsWidget::deviceNameEditingFinished);
connect(m_ui->addConfigButton, &QAbstractButton::clicked,
connect(m_addConfigButton, &QAbstractButton::clicked,
this, &DeviceSettingsWidget::addDevice);
}
@@ -129,8 +183,8 @@ void DeviceSettingsWidget::addDevice()
return;
m_deviceManager->addDevice(device);
m_ui->removeConfigButton->setEnabled(true);
m_ui->configurationComboBox->setCurrentIndex(m_deviceManagerModel->indexOf(device));
m_removeConfigButton->setEnabled(true);
m_configurationComboBox->setCurrentIndex(m_deviceManagerModel->indexOf(device));
saveSettings();
if (device->hasDeviceTester())
testDevice();
@@ -146,46 +200,46 @@ void DeviceSettingsWidget::removeDevice()
void DeviceSettingsWidget::displayCurrent()
{
const IDevice::ConstPtr &current = currentDevice();
m_ui->defaultDeviceButton->setEnabled(
m_defaultDeviceButton->setEnabled(
m_deviceManager->defaultDevice(current->type()) != current);
m_ui->osTypeValueLabel->setText(current->displayType());
m_ui->autoDetectionValueLabel->setText(current->isAutoDetected()
m_osTypeValueLabel->setText(current->displayType());
m_autoDetectionLabel->setText(current->isAutoDetected()
? tr("Yes (id is \"%1\")").arg(current->id().toString()) : tr("No"));
m_nameValidator->setDisplayName(current->displayName());
m_ui->deviceStateValueIconLabel->show();
m_deviceStateIconLabel->show();
switch (current->deviceState()) {
case IDevice::DeviceReadyToUse:
m_ui->deviceStateValueIconLabel->setPixmap(Icons::DEVICE_READY_INDICATOR.pixmap());
m_deviceStateIconLabel->setPixmap(Icons::DEVICE_READY_INDICATOR.pixmap());
break;
case IDevice::DeviceConnected:
m_ui->deviceStateValueIconLabel->setPixmap(Icons::DEVICE_CONNECTED_INDICATOR.pixmap());
m_deviceStateIconLabel->setPixmap(Icons::DEVICE_CONNECTED_INDICATOR.pixmap());
break;
case IDevice::DeviceDisconnected:
m_ui->deviceStateValueIconLabel->setPixmap(Icons::DEVICE_DISCONNECTED_INDICATOR.pixmap());
m_deviceStateIconLabel->setPixmap(Icons::DEVICE_DISCONNECTED_INDICATOR.pixmap());
break;
case IDevice::DeviceStateUnknown:
m_ui->deviceStateValueIconLabel->hide();
m_deviceStateIconLabel->hide();
break;
}
m_ui->deviceStateValueTextLabel->setText(current->deviceStateToString());
m_deviceStateTextLabel->setText(current->deviceStateToString());
m_ui->removeConfigButton->setEnabled(!current->isAutoDetected()
m_removeConfigButton->setEnabled(!current->isAutoDetected()
|| current->deviceState() == IDevice::DeviceDisconnected);
fillInValues();
}
void DeviceSettingsWidget::setDeviceInfoWidgetsEnabled(bool enable)
{
m_ui->configurationLabel->setEnabled(enable);
m_ui->configurationComboBox->setEnabled(enable);
m_ui->generalGroupBox->setEnabled(enable);
m_ui->osSpecificGroupBox->setEnabled(enable);
m_configurationLabel->setEnabled(enable);
m_configurationComboBox->setEnabled(enable);
m_generalGroupBox->setEnabled(enable);
m_osSpecificGroupBox->setEnabled(enable);
}
void DeviceSettingsWidget::fillInValues()
{
const IDevice::ConstPtr &current = currentDevice();
m_ui->nameLineEdit->setText(current->displayName());
m_nameLineEdit->setText(current->displayName());
}
void DeviceSettingsWidget::updateDeviceFromUi()
@@ -203,7 +257,7 @@ void DeviceSettingsWidget::saveSettings()
int DeviceSettingsWidget::currentIndex() const
{
return m_ui->configurationComboBox->currentIndex();
return m_configurationComboBox->currentIndex();
}
IDevice::ConstPtr DeviceSettingsWidget::currentDevice() const
@@ -214,10 +268,10 @@ IDevice::ConstPtr DeviceSettingsWidget::currentDevice() const
void DeviceSettingsWidget::deviceNameEditingFinished()
{
if (m_ui->configurationComboBox->count() == 0)
if (m_configurationComboBox->count() == 0)
return;
const QString &newName = m_ui->nameLineEdit->text();
const QString &newName = m_nameLineEdit->text();
m_deviceManager->mutableDevice(currentDevice()->id())->setDisplayName(newName);
m_nameValidator->setDisplayName(newName);
m_deviceManagerModel->updateDevice(currentDevice()->id());
@@ -226,7 +280,7 @@ void DeviceSettingsWidget::deviceNameEditingFinished()
void DeviceSettingsWidget::setDefaultDevice()
{
m_deviceManager->setDefaultDevice(currentDevice()->id());
m_ui->defaultDeviceButton->setEnabled(false);
m_defaultDeviceButton->setEnabled(false);
}
void DeviceSettingsWidget::testDevice()
@@ -255,19 +309,19 @@ void DeviceSettingsWidget::currentDeviceChanged(int index)
const IDevice::ConstPtr device = m_deviceManagerModel->device(index);
if (device.isNull()) {
setDeviceInfoWidgetsEnabled(false);
m_ui->removeConfigButton->setEnabled(false);
m_removeConfigButton->setEnabled(false);
clearDetails();
m_ui->defaultDeviceButton->setEnabled(false);
m_defaultDeviceButton->setEnabled(false);
return;
}
setDeviceInfoWidgetsEnabled(true);
m_ui->removeConfigButton->setEnabled(true);
m_removeConfigButton->setEnabled(true);
if (device->hasDeviceTester()) {
QPushButton * const button = new QPushButton(tr("Test"));
m_additionalActionButtons << button;
connect(button, &QAbstractButton::clicked, this, &DeviceSettingsWidget::testDevice);
m_ui->buttonsLayout->insertWidget(m_ui->buttonsLayout->count() - 1, button);
m_buttonsLayout->insertWidget(m_buttonsLayout->count() - 1, button);
}
if (device->canCreateProcessModel()) {
@@ -275,7 +329,7 @@ void DeviceSettingsWidget::currentDeviceChanged(int index)
m_additionalActionButtons << button;
connect(button, &QAbstractButton::clicked,
this, &DeviceSettingsWidget::handleProcessListRequested);
m_ui->buttonsLayout->insertWidget(m_ui->buttonsLayout->count() - 1, button);
m_buttonsLayout->insertWidget(m_buttonsLayout->count() - 1, button);
}
for (const IDevice::DeviceAction &deviceAction : device->deviceActions()) {
@@ -291,22 +345,22 @@ void DeviceSettingsWidget::currentDeviceChanged(int index)
currentDeviceChanged(currentIndex());
});
m_ui->buttonsLayout->insertWidget(m_ui->buttonsLayout->count() - 1, button);
m_buttonsLayout->insertWidget(m_buttonsLayout->count() - 1, button);
}
if (!m_ui->osSpecificGroupBox->layout())
new QVBoxLayout(m_ui->osSpecificGroupBox);
if (!m_osSpecificGroupBox->layout())
new QVBoxLayout(m_osSpecificGroupBox);
m_configWidget = m_deviceManager->mutableDevice(device->id())->createWidget();
if (m_configWidget)
m_ui->osSpecificGroupBox->layout()->addWidget(m_configWidget);
m_osSpecificGroupBox->layout()->addWidget(m_configWidget);
displayCurrent();
}
void DeviceSettingsWidget::clearDetails()
{
m_ui->nameLineEdit->clear();
m_ui->osTypeValueLabel->clear();
m_ui->autoDetectionValueLabel->clear();
m_nameLineEdit->clear();
m_osTypeValueLabel->clear();
m_autoDetectionLabel->clear();
}
void DeviceSettingsWidget::handleProcessListRequested()

View File

@@ -12,7 +12,12 @@
#include <coreplugin/dialogs/ioptionspage.h>
QT_BEGIN_NAMESPACE
class QComboBox;
class QGroupBox;
class QLabel;
class QLineEdit;
class QPushButton;
class QVBoxLayout;
QT_END_NAMESPACE
namespace ProjectExplorer {
@@ -61,6 +66,20 @@ private:
NameValidator * const m_nameValidator;
QList<QPushButton *> m_additionalActionButtons;
IDeviceWidget *m_configWidget;
QLabel *m_configurationLabel;
QComboBox *m_configurationComboBox;
QGroupBox *m_generalGroupBox;
QLineEdit *m_nameLineEdit;
QLabel *m_osTypeValueLabel;
QLabel *m_autoDetectionLabel;
QLabel *m_deviceStateIconLabel;
QLabel *m_deviceStateTextLabel;
QGroupBox *m_osSpecificGroupBox;
QPushButton *m_addConfigButton;
QPushButton *m_removeConfigButton;
QPushButton *m_defaultDeviceButton;
QVBoxLayout *m_buttonsLayout;
};
} // namespace Internal

View File

@@ -1,237 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProjectExplorer::Internal::DeviceSettingsWidget</class>
<widget class="QWidget" name="ProjectExplorer::Internal::DeviceSettingsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>728</width>
<height>429</height>
</rect>
</property>
<property name="windowTitle">
<string>Linux Device Configurations</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="configurationLabel">
<property name="text">
<string>&amp;Device:</string>
</property>
<property name="buddy">
<cstring>configurationComboBox</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="configurationComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>564</width>
<height>360</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="generalGroupBox">
<property name="title">
<string>General</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="deviceNameLabel">
<property name="text">
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>nameLineEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="oSTypeLabel">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="osTypeValueLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="autoDetectionKeyLabel">
<property name="text">
<string>Auto-detected:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="autoDetectionValueLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="deviceStateKeyLabel">
<property name="text">
<string>Current state:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="deviceStateValueIconLabel"/>
</item>
<item>
<widget class="QLabel" name="deviceStateValueTextLabel"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="osSpecificGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Type Specific</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="buttonsLayout">
<item>
<widget class="QPushButton" name="addConfigButton">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="text">
<string>&amp;Add...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeConfigButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="text">
<string>&amp;Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="defaultDeviceButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="text">
<string>Set As Default</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -217,7 +217,7 @@ Project {
"deviceprocessesdialog.cpp", "deviceprocessesdialog.h",
"deviceprocesslist.cpp", "deviceprocesslist.h",
"devicesettingspage.cpp", "devicesettingspage.h",
"devicesettingswidget.cpp", "devicesettingswidget.h", "devicesettingswidget.ui",
"devicesettingswidget.cpp", "devicesettingswidget.h",
"devicetestdialog.cpp", "devicetestdialog.h",
"deviceusedportsgatherer.cpp", "deviceusedportsgatherer.h",
"filetransfer.cpp", "filetransfer.h",