feat:添加表头宽度的自定义功能
This commit is contained in:
parent
1419e2efc6
commit
b6cb80fe2b
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef ALARMEVENTDATAVIEW_H
|
||||
#define ALARMEVENTDATAVIEW_H
|
||||
|
||||
#include "alarmEventGlobal.h"
|
||||
#include <QWidget>
|
||||
#include <QTableView>
|
||||
#include <QAbstractTableModel>
|
||||
|
|
@ -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<QVariant> 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<SectionData> headerData() const {return m_headerData;}
|
||||
|
||||
private:
|
||||
void iniHeaderData();
|
||||
void updateCurPageData(); //更新当前页的数据
|
||||
void updateTotalCount(); //更新总记录数
|
||||
|
||||
QVector<RowData> m_curPageData;
|
||||
QVector<EventData> m_displayEvents;
|
||||
QVector<SectionData> m_headerData;
|
||||
PaginationInfo m_paginationInfo;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -32,20 +32,56 @@ 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; //居中展示
|
||||
default:
|
||||
|
|
@ -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<AlarmEventDataModel::SectionData> 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);
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ background-color: rgb(67,160,249);
|
|||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>事件查看</string>
|
||||
<string>历史事件</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
|
|
@ -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);
|
|||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>报警(0条)</string>
|
||||
<string>实时告警</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
Loading…
Reference in New Issue