97 lines
2.7 KiB
C++
97 lines
2.7 KiB
C++
#ifndef DEVICESTATUSWIDGET_H
|
|
#define DEVICESTATUSWIDGET_H
|
|
|
|
#include <QWidget>
|
|
#include <QLabel>
|
|
#include <QVBoxLayout>
|
|
#include <QMap>
|
|
#include <QString>
|
|
#include <QMouseEvent>
|
|
#include "IStatusUpdate.h"
|
|
|
|
// 设备状态枚举
|
|
enum class DeviceStatus {
|
|
Online, // 在线
|
|
Offline, // 离线
|
|
Error // 错误
|
|
};
|
|
|
|
// 设备信息结构体
|
|
struct DeviceInfo {
|
|
QString name; // 设备名称
|
|
QString alias; // 设备别名(用于区分同名设备)
|
|
QString ip; // 设备IP地址
|
|
DeviceStatus status; // 设备状态
|
|
bool isNetworkDevice; // 是否为网络设备
|
|
float temperature; // 设备温度(摄氏度)
|
|
bool hasTemperature; // 是否有温度数据
|
|
|
|
DeviceInfo() : status(DeviceStatus::Offline), isNetworkDevice(false), temperature(0.0f), hasTemperature(false) {}
|
|
DeviceInfo(const QString& n, const QString& a, const QString& i, DeviceStatus s, bool network)
|
|
: name(n), alias(a), ip(i), status(s), isNetworkDevice(network), temperature(0.0f), hasTemperature(false) {}
|
|
};
|
|
|
|
class DeviceStatusWidget : public QWidget {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit DeviceStatusWidget(QWidget* parent = nullptr);
|
|
~DeviceStatusWidget();
|
|
|
|
// 设置设备列表
|
|
void setDevices(const QList<DeviceInfo>& devices);
|
|
|
|
// 更新设备状态
|
|
void updateDeviceStatus(const QString& deviceName, DeviceStatus status);
|
|
|
|
// 更新设备温度
|
|
void updateDeviceTemperature(const QString& deviceName, float temperature);
|
|
|
|
// 获取设备数量
|
|
int deviceCount() const { return m_deviceLabels.size(); }
|
|
|
|
signals:
|
|
// 设备点击信号
|
|
void deviceClicked(const QString& deviceName);
|
|
|
|
// 设备状态改变信号
|
|
void deviceStatusChanged(const QString& deviceName, DeviceStatus status);
|
|
|
|
private slots:
|
|
// 处理设备标签点击事件
|
|
void onDeviceLabelClicked();
|
|
|
|
private:
|
|
// 创建设备标签
|
|
void createDeviceLabels(int count);
|
|
|
|
// 移除设备标签
|
|
void removeDeviceLabels();
|
|
|
|
// 更新设备标签显示
|
|
void updateDeviceLabel(int index);
|
|
|
|
// 获取设备状态对应的图片路径
|
|
QString getStatusImage(DeviceStatus status) const;
|
|
|
|
// 设备信息列表
|
|
QList<DeviceInfo> m_devices;
|
|
|
|
// 设备标签列表
|
|
QList<QWidget*> m_deviceLabels;
|
|
|
|
// 设备状态标签列表
|
|
QList<QLabel*> m_statusLabels;
|
|
|
|
// 设备名称标签列表
|
|
QList<QLabel*> m_nameLabels;
|
|
|
|
// 设备温度标签列表
|
|
QList<QLabel*> m_temperatureLabels;
|
|
|
|
// 主布局
|
|
QVBoxLayout* m_mainLayout;
|
|
|
|
};
|
|
|
|
#endif // DEVICESTATUSWIDGET_H
|