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>
This commit is contained in:
Christian Kandeler
2024-01-18 15:23:23 +01:00
parent 37d3c4ed78
commit b34a8130bb
4 changed files with 27 additions and 22 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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();

View File

@@ -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);