diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2024-01-18 15:23:23 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2024-01-19 10:07:47 +0000 |
commit | b34a8130bb19605c61b985f58014f4dfa576ddbe (patch) | |
tree | d9d52fa77ae9224b98cdd62cf7ce13cc3aecc139 | |
parent | 37d3c4ed7854833ae87254a4e2b46f277d07772c (diff) |
ProjectExplorer: Show device status when displaying lists of devices
Fixes: QTCREATORBUG-20941
Change-Id: Ibc24785ae2afc174d13c22231f2c8e7e6923d64c
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
4 files changed, 27 insertions, 22 deletions
diff --git a/src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp b/src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp index 7e8a74d0a3..ef43726ef8 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp @@ -143,17 +143,18 @@ QVariant DeviceManagerModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() >= rowCount()) return {}; - if (role != Qt::DisplayRole && role != Qt::UserRole) - return {}; const IDevice::ConstPtr dev = device(index.row()); - if (role == Qt::UserRole) + switch (role) { + case Qt::DecorationRole: + return dev->deviceStateIcon(); + case Qt::UserRole: return dev->id().toSetting(); - QString name; - if (d->deviceManager->defaultDevice(dev->type()) == dev) - name = Tr::tr("%1 (default for %2)").arg(dev->displayName(), dev->displayType()); - else - name = dev->displayName(); - return name; + case Qt::DisplayRole: + if (d->deviceManager->defaultDevice(dev->type()) == dev) + return Tr::tr("%1 (default for %2)").arg(dev->displayName(), dev->displayType()); + return dev->displayName(); + } + return {}; } bool DeviceManagerModel::matchesTypeFilter(const IDevice::ConstPtr &dev) const diff --git a/src/plugins/projectexplorer/devicesupport/devicesettingspage.cpp b/src/plugins/projectexplorer/devicesupport/devicesettingspage.cpp index 81e0eec15a..cb3bac4297 100644 --- a/src/plugins/projectexplorer/devicesupport/devicesettingspage.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicesettingspage.cpp @@ -249,20 +249,10 @@ void DeviceSettingsWidget::displayCurrent() m_autoDetectionLabel->setText(current->isAutoDetected() ? Tr::tr("Yes (id is \"%1\")").arg(current->id().toString()) : Tr::tr("No")); m_deviceStateIconLabel->show(); - switch (current->deviceState()) { - case IDevice::DeviceReadyToUse: - m_deviceStateIconLabel->setPixmap(Icons::DEVICE_READY_INDICATOR.pixmap()); - break; - case IDevice::DeviceConnected: - m_deviceStateIconLabel->setPixmap(Icons::DEVICE_CONNECTED_INDICATOR.pixmap()); - break; - case IDevice::DeviceDisconnected: - m_deviceStateIconLabel->setPixmap(Icons::DEVICE_DISCONNECTED_INDICATOR.pixmap()); - break; - case IDevice::DeviceStateUnknown: + if (const QPixmap &icon = current->deviceStateIcon(); !icon.isNull()) + m_deviceStateIconLabel->setPixmap(icon); + else m_deviceStateIconLabel->hide(); - break; - } m_deviceStateTextLabel->setText(current->deviceStateToString()); m_removeConfigButton->setEnabled(!current->isAutoDetected() diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index acc4259c27..9a79347da1 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -9,6 +9,7 @@ #include "../kit.h" #include "../kitaspects.h" +#include "../projectexplorericons.h" #include "../projectexplorertr.h" #include "../target.h" @@ -590,6 +591,17 @@ QString IDevice::deviceStateToString() const } } +QPixmap IDevice::deviceStateIcon() const +{ + switch (d->deviceState) { + case IDevice::DeviceReadyToUse: return Icons::DEVICE_READY_INDICATOR.pixmap(); + case IDevice::DeviceConnected: return Icons::DEVICE_CONNECTED_INDICATOR.pixmap(); + case IDevice::DeviceDisconnected: return Icons::DEVICE_DISCONNECTED_INDICATOR.pixmap(); + case IDevice::DeviceStateUnknown: break; + } + return {}; +} + SshParameters IDevice::sshParameters() const { return *d->sshParameters.readLocked(); diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h index 4642697c76..1edd702444 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.h +++ b/src/plugins/projectexplorer/devicesupport/idevice.h @@ -26,6 +26,7 @@ #include <memory> QT_BEGIN_NAMESPACE +class QPixmap; class QWidget; QT_END_NAMESPACE @@ -158,6 +159,7 @@ public: DeviceState deviceState() const; void setDeviceState(const DeviceState state); QString deviceStateToString() const; + QPixmap deviceStateIcon() const; static Utils::Id typeFromMap(const Utils::Store &map); static Utils::Id idFromMap(const Utils::Store &map); |