From b6cb80fe2b96806f61b98db8dcf27dcf7dde33ac Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Fri, 10 Oct 2025 10:06:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E8=A1=A8=E5=A4=B4?= =?UTF-8?q?=E5=AE=BD=E5=BA=A6=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/alarmEventDataView.h | 27 ++++++++++-- include/alarmEventGlobal.h | 17 +++++--- source/alarmEventDataView.cpp | 82 +++++++++++++++++++++++++++-------- ui/dashboardFrame.ui | 6 +-- 4 files changed, 101 insertions(+), 31 deletions(-) diff --git a/include/alarmEventDataView.h b/include/alarmEventDataView.h index 116ac82..a25387a 100644 --- a/include/alarmEventDataView.h +++ b/include/alarmEventDataView.h @@ -1,6 +1,7 @@ #ifndef ALARMEVENTDATAVIEW_H #define ALARMEVENTDATAVIEW_H +#include "alarmEventGlobal.h" #include #include #include @@ -11,6 +12,20 @@ class AlarmEventDataModel : public QAbstractTableModel Q_OBJECT public: + enum Column + { + Index, + ReceiveTime, + SOETime, + Station, + Bay, + Description, + Type, + Severity, + Status, + Operation, + }; + struct RowData { QVector values; @@ -27,11 +42,13 @@ public: struct SectionData { int width = -1; + Column column; QString text; - SectionData(QString t, int w) - :text(t), - width(w){} + SectionData(QString t, int w, Column c) + :text(t) + ,column(c) + ,width(w){} }; explicit AlarmEventDataModel(QObject* parent = nullptr); @@ -45,12 +62,14 @@ public: int columnCount(const QModelIndex& parent = QModelIndex()) const override; Qt::ItemFlags flags(const QModelIndex& index) const override; + const QVector headerData() const {return m_headerData;} + private: void iniHeaderData(); void updateCurPageData(); //更新当前页的数据 void updateTotalCount(); //更新总记录数 - QVector m_curPageData; + QVector m_displayEvents; QVector m_headerData; PaginationInfo m_paginationInfo; }; diff --git a/include/alarmEventGlobal.h b/include/alarmEventGlobal.h index 22bc35e..86b01f8 100644 --- a/include/alarmEventGlobal.h +++ b/include/alarmEventGlobal.h @@ -13,12 +13,19 @@ enum MainDialogMode struct EventData { QString id; - QString stationName; - QString bayName; + QString name; + int type; + int priority; + int status; + qint64 timestamp; + QString stationName; //场站名称 + QString bayName; //间隔名称 + QString severity;//严重性(等级) + QString from; //'station'、'platform'、'msa' + QString category; //存放订阅数据的标识,它和 timestamp 一起构成订阅从的requst QString description; - bool confirmed; - QDateTime recivingTime; - QDateTime SOETime; + QVariantMap condition; //事件发生时的简单场景描述,如{'up_limitaion': 40, 'low_limitation': 10, value: 45} + QVariantMap alarmInfo; //{"driver_name":"ssu_driver_name","device_no":"ssu000","alarm_code":1,"alarm_time":2516666461000,"alarm_status":0} }; #endif diff --git a/source/alarmEventDataView.cpp b/source/alarmEventDataView.cpp index 58b1201..0166167 100644 --- a/source/alarmEventDataView.cpp +++ b/source/alarmEventDataView.cpp @@ -32,19 +32,55 @@ QVariant AlarmEventDataModel::data(const QModelIndex& index, int role) const int row = index.row(); int col = index.column(); int globalRow = (m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerpage + row; + const EventData& event = m_displayEvents.at(row); + //EventData event = m_displayEvents[row]; switch (role) { case Qt::DisplayRole: { - if(index.column() == 0) //第一列显示序号 - return QString::number(globalRow + 1); - else + switch(col) { - int dataCol = col - 1; - const RowData& rowData = m_curPageData[row]; - return rowData.values.value(dataCol); + case Index: + return QString::number(globalRow + 1); + case ReceiveTime: + return QDateTime::fromMSecsSinceEpoch(event.timestamp).toString("yyyy-MM-dd hh:mm:ss"); + case SOETime: + return QDateTime::fromMSecsSinceEpoch(event.timestamp).toString("yyyy-MM-dd hh:mm:ss"); + case Station: + return event.stationName; + case Bay: + return event.bayName; + case Description: + return event.description; + case Type: + return event.type; + case Severity: + return event.severity; + case Status: + { + if(event.status < 3) + return QString("未确认"); + else + return QString("已确认"); } + } + } + case Qt::ForegroundRole: + { + if(event.severity == "事故") + return QColor(255, 85, 0); + else if(event.severity == "异常") + return QColor(255, 170, 0); + else if(event.severity == "预警") + return QColor(0, 170, 255); + else if(event.severity == "告知") + return QColor(0, 170, 0); + + if(event.status < 3) + return QColor(0, 170, 255); + else + return QColor(0, 170, 0); } case Qt::TextAlignmentRole: return Qt::AlignCenter; //居中展示 @@ -63,7 +99,7 @@ QVariant AlarmEventDataModel::headerData(int section, Qt::Orientation orientatio int AlarmEventDataModel::rowCount(const QModelIndex& parent) const { - return m_curPageData.count(); + return m_displayEvents.count(); } int AlarmEventDataModel::columnCount(const QModelIndex& parent) const @@ -84,22 +120,21 @@ Qt::ItemFlags AlarmEventDataModel::flags(const QModelIndex& index) const void AlarmEventDataModel::iniHeaderData() { - m_headerData.emplace_back(SectionData("序号", 90)); - m_headerData.emplace_back(SectionData("接收时间", 270)); - m_headerData.emplace_back(SectionData("SOE时间", 270)); - m_headerData.emplace_back(SectionData("厂站", 200)); - m_headerData.emplace_back(SectionData("间隔", 200)); - m_headerData.emplace_back(SectionData("信息", -1)); - m_headerData.emplace_back(SectionData("类型", 200)); - m_headerData.emplace_back(SectionData("等级", 150)); - m_headerData.emplace_back(SectionData("确认状态", 150)); - m_headerData.emplace_back(SectionData("操作", 300)); + m_headerData.emplace_back(SectionData("序号", 90, Index)); + m_headerData.emplace_back(SectionData("接收时间", 270, ReceiveTime)); + m_headerData.emplace_back(SectionData("SOE时间", 270, SOETime)); + m_headerData.emplace_back(SectionData("厂站", 200, Station)); + m_headerData.emplace_back(SectionData("间隔", 200, Bay)); + m_headerData.emplace_back(SectionData("信息", -1, Description)); + m_headerData.emplace_back(SectionData("类型", 200, Type)); + m_headerData.emplace_back(SectionData("等级", 150, Severity)); + m_headerData.emplace_back(SectionData("确认状态", 150, Status)); + m_headerData.emplace_back(SectionData("操作", 300, Operation)); } - void AlarmEventDataModel::updateCurPageData() { - m_curPageData.clear(); + m_displayEvents.clear(); } @@ -153,6 +188,15 @@ AlarmEventDataView::AlarmEventDataView(QWidget* parent) m_tableModel = new AlarmEventDataModel(this); m_tableView->setModel(m_tableModel); + //设置表头 + const QVector headerData = m_tableModel->headerData(); + for(int i = 0; i < headerData.size(); i++) + { + if(headerData.at(i).width == -1) + m_tableView->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch); + else + m_tableView->setColumnWidth(i, headerData.at(i).width); + } m_delegate = new AlarmEventDataDelegate(m_tableView, this); m_tableView->setItemDelegate(m_delegate); diff --git a/ui/dashboardFrame.ui b/ui/dashboardFrame.ui index 62691fd..bf1741d 100644 --- a/ui/dashboardFrame.ui +++ b/ui/dashboardFrame.ui @@ -157,7 +157,7 @@ background-color: rgb(67,160,249); - 事件查看 + 历史事件 false @@ -227,7 +227,7 @@ background-color: rgb(39, 102, 59); font: 700 12pt "微软雅黑"; color:rgb(250,250,250); text-align:right; -padding-right:30px; +padding-right:35px; background-color: rgb(200, 68, 56); icon-size:20px; icon: url(:/images/icon_alarm.png); @@ -243,7 +243,7 @@ background-color: rgb(128, 43, 36); - 报警(0条) + 实时告警