2025-08-31 21:08:28 +08:00
|
|
|
|
#ifndef TEARINGDATATABLEWIDGET_H
|
|
|
|
|
|
#define TEARINGDATATABLEWIDGET_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
#include <QTableWidget>
|
2025-09-24 22:36:13 +08:00
|
|
|
|
#include <QTableWidgetItem>
|
2025-08-31 21:08:28 +08:00
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
#include <QString>
|
2025-10-08 21:45:37 +08:00
|
|
|
|
#include <QSet>
|
2025-08-31 21:08:28 +08:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include "IStatusUpdate.h"
|
2025-10-08 21:45:37 +08:00
|
|
|
|
#include "VrDateUtils.h"
|
2025-08-31 21:08:28 +08:00
|
|
|
|
|
2025-09-24 22:36:13 +08:00
|
|
|
|
// 自定义TableWidgetItem类,支持按数字值排序
|
|
|
|
|
|
class NumericTableWidgetItem : public QTableWidgetItem
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
2025-09-29 00:56:53 +08:00
|
|
|
|
NumericTableWidgetItem();
|
2025-09-24 22:36:13 +08:00
|
|
|
|
NumericTableWidgetItem(const QString &text);
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<(const QTableWidgetItem &other) const override;
|
2025-09-29 00:56:53 +08:00
|
|
|
|
|
|
|
|
|
|
// 实现clone方法,确保在复制时能正确创建对象
|
|
|
|
|
|
QTableWidgetItem* clone() const override;
|
2025-09-24 22:36:13 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
double toDouble() const;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-29 00:56:53 +08:00
|
|
|
|
Q_DECLARE_METATYPE(NumericTableWidgetItem)
|
|
|
|
|
|
|
2025-08-31 21:08:28 +08:00
|
|
|
|
class TearingDataTableWidget : public QWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
explicit TearingDataTableWidget(QWidget *parent = nullptr);
|
|
|
|
|
|
~TearingDataTableWidget();
|
|
|
|
|
|
|
2025-10-08 21:45:37 +08:00
|
|
|
|
|
2025-09-29 00:56:53 +08:00
|
|
|
|
// 添加多条数据(自动选择优化方法)
|
2025-10-08 21:45:37 +08:00
|
|
|
|
void addData(const QString devName, const TearingData &dataList);
|
|
|
|
|
|
|
|
|
|
|
|
// 添加多条数据(自动选择优化方法)
|
|
|
|
|
|
void addData(const QString devName, const std::vector<TearingData> &dataList);
|
|
|
|
|
|
|
2025-09-29 00:56:53 +08:00
|
|
|
|
// 批量添加数据,优化大量数据处理性能
|
2025-10-08 21:45:37 +08:00
|
|
|
|
void addDataBatch(const QString devName, const std::vector<TearingData> &dataList);
|
2025-09-29 00:56:53 +08:00
|
|
|
|
|
|
|
|
|
|
// 清除所有数据
|
2025-08-31 21:08:28 +08:00
|
|
|
|
void clearData();
|
2025-09-29 00:56:53 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置表格最大行数限制,防止内存占用过大
|
|
|
|
|
|
void setMaximumRows(int maxRows);
|
2025-10-08 21:45:37 +08:00
|
|
|
|
|
|
|
|
|
|
// 从集合中移除指定行的设备ID组合
|
|
|
|
|
|
void removeRowFromSet(int row);
|
2025-08-31 21:08:28 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
void setupUI();
|
|
|
|
|
|
void setupTable();
|
2025-10-08 21:45:37 +08:00
|
|
|
|
|
|
|
|
|
|
void _AddDataToTable(const QString devName, const TearingData &data, int row);
|
|
|
|
|
|
|
2025-09-24 22:36:13 +08:00
|
|
|
|
QString getTearStatusText(const QString &status);
|
|
|
|
|
|
QString getTearTypeText(const QString &type);
|
2025-10-08 21:45:37 +08:00
|
|
|
|
int findExistingRowById(const QString &devName, const QString &id);
|
2025-09-29 00:56:53 +08:00
|
|
|
|
|
|
|
|
|
|
// 内存管理相关方法
|
|
|
|
|
|
void limitRowsIfNeeded();
|
2025-09-24 22:36:13 +08:00
|
|
|
|
|
|
|
|
|
|
// 排序相关的私有方法
|
|
|
|
|
|
void connectHeaderSignals();
|
2025-08-31 21:08:28 +08:00
|
|
|
|
|
2025-10-08 21:45:37 +08:00
|
|
|
|
// 与服务端颜色协调的颜色数组
|
|
|
|
|
|
QColor m_tearColors[10];
|
|
|
|
|
|
|
2025-08-31 21:08:28 +08:00
|
|
|
|
QTableWidget *m_tableWidget;
|
2025-09-29 00:56:53 +08:00
|
|
|
|
int m_maxRows = -1; // 最大行数限制,-1表示无限制
|
2025-10-08 21:45:37 +08:00
|
|
|
|
|
|
|
|
|
|
// 使用QSet存储设备名称和ID的组合,格式为"设备名:ID"
|
|
|
|
|
|
QSet<QString> m_devIdSet;
|
2025-08-31 21:08:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // TEARINGDATATABLEWIDGET_H
|