feat:完整实时告警数据模拟与加载
This commit is contained in:
parent
4d6f10f762
commit
baa048c2d4
|
|
@ -34,6 +34,7 @@ private:
|
|||
int m_status;
|
||||
};
|
||||
|
||||
class QTimer;
|
||||
class AlarmEventDataModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -92,6 +93,7 @@ public:
|
|||
|
||||
//自定义功能函数
|
||||
const QVector<SectionData> headerData() const {return m_headerData;}
|
||||
void setMode(AlarmDataMode mode) {m_dataMode = mode;}
|
||||
void setMaxRealTimeEvents(int value) {m_maxRealTimeEvents = value;}
|
||||
const int getMaxRealTimeEvents() const {return m_maxRealTimeEvents;}
|
||||
void setFilter(const AlarmEventDataFilter& filter);
|
||||
|
|
@ -99,6 +101,7 @@ public:
|
|||
void refresh();
|
||||
|
||||
private:
|
||||
void onTimeoutSimulateData();
|
||||
void onRealTimeEventReceived(const EventData& event);
|
||||
|
||||
private:
|
||||
|
|
@ -113,6 +116,8 @@ private:
|
|||
QVector<SectionData> m_headerData;
|
||||
PaginationInfo m_paginationInfo;
|
||||
|
||||
QTimer* m_simulatedDataTimer;
|
||||
|
||||
AlarmDataMode m_dataMode;
|
||||
AlarmEventDataFilter m_currentFilter;
|
||||
int m_maxRealTimeEvents;
|
||||
|
|
@ -141,6 +146,8 @@ public:
|
|||
AlarmEventDataView(QWidget* parent = nullptr);
|
||||
~AlarmEventDataView();
|
||||
|
||||
void setModelMode(AlarmDataMode);
|
||||
|
||||
private:
|
||||
QTableView* m_tableView;
|
||||
AlarmEventDataModel* m_tableModel;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <QHeaderView>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
///////------AlarmEventDataFilter-----
|
||||
AlarmEventDataFilter::AlarmEventDataFilter()
|
||||
|
|
@ -62,6 +64,11 @@ AlarmEventDataModel::AlarmEventDataModel(QObject* parent)
|
|||
m_paginationInfo.currentPage = 1;
|
||||
m_paginationInfo.totalEntries = 0;
|
||||
iniHeaderData();
|
||||
|
||||
//实时数据测试
|
||||
m_simulatedDataTimer = new QTimer(this);
|
||||
connect(m_simulatedDataTimer, &QTimer::timeout, this, &AlarmEventDataModel::onTimeoutSimulateData);
|
||||
m_simulatedDataTimer->start(2000);
|
||||
}
|
||||
|
||||
AlarmEventDataModel::~AlarmEventDataModel()
|
||||
|
|
@ -80,7 +87,7 @@ QModelIndex AlarmEventDataModel::index(int row, int column, const QModelIndex& p
|
|||
|
||||
QVariant AlarmEventDataModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if(index.isValid())
|
||||
if(!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
|
|
@ -118,9 +125,15 @@ QVariant AlarmEventDataModel::data(const QModelIndex& index, int role) const
|
|||
else
|
||||
return QString("已确认");
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
case Qt::ForegroundRole:
|
||||
{
|
||||
switch(col)
|
||||
{
|
||||
case Severity:
|
||||
{
|
||||
if(event.severity == "事故")
|
||||
return QColor(255, 85, 0);
|
||||
|
|
@ -130,12 +143,20 @@ QVariant AlarmEventDataModel::data(const QModelIndex& index, int role) const
|
|||
return QColor(0, 170, 255);
|
||||
else if(event.severity == "告知")
|
||||
return QColor(0, 170, 0);
|
||||
|
||||
else
|
||||
return QColor(250, 250, 250);
|
||||
}
|
||||
case Status:
|
||||
{
|
||||
if(event.status < 3)
|
||||
return QColor(0, 170, 255);
|
||||
else
|
||||
return QColor(0, 170, 0);
|
||||
}
|
||||
default:
|
||||
return QColor(250, 250, 250);
|
||||
}
|
||||
}
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter; //居中展示
|
||||
default:
|
||||
|
|
@ -175,12 +196,12 @@ Qt::ItemFlags AlarmEventDataModel::flags(const QModelIndex& index) const
|
|||
void AlarmEventDataModel::iniHeaderData()
|
||||
{
|
||||
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, ReceiveTime));
|
||||
m_headerData.emplace_back(SectionData("SOE时间", 200, 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, Type));
|
||||
m_headerData.emplace_back(SectionData("等级", 150, Severity));
|
||||
m_headerData.emplace_back(SectionData("确认状态", 150, Status));
|
||||
m_headerData.emplace_back(SectionData("操作", 300, Operation));
|
||||
|
|
@ -231,6 +252,35 @@ void AlarmEventDataModel::updateEventData(int index, const EventData& updatedEve
|
|||
emit dataChanged(modelIndex, modelIndex);
|
||||
}
|
||||
|
||||
void AlarmEventDataModel::onTimeoutSimulateData()
|
||||
{
|
||||
//模拟实时告警数据
|
||||
static int id = 0, min = 0, max = 3;
|
||||
int randomInt = min + QRandomGenerator::global()->bounded(min, max + 1);
|
||||
QString strID = QString::number(++id);
|
||||
//qDebug() << id << " " << strID;
|
||||
EventData event;
|
||||
event.id = strID;
|
||||
event.name = QString("实时告警") + strID;
|
||||
event.timestamp = QDateTime::currentMSecsSinceEpoch();
|
||||
event.stationName = QString("厂站") + QString::number(randomInt);
|
||||
event.bayName = QString("间隔") + QString::number(randomInt);
|
||||
event.description = "";
|
||||
event.type = 5;
|
||||
QString severity = QString("预警");
|
||||
if(randomInt == 0)
|
||||
severity = QString("告知");
|
||||
else if(randomInt == 1)
|
||||
severity = QString("预警");
|
||||
else if(randomInt == 2)
|
||||
severity = QString("异常");
|
||||
else if(randomInt == 3)
|
||||
severity = QString("事故");
|
||||
event.severity = severity;
|
||||
event.status = 0;
|
||||
onRealTimeEventReceived(event);
|
||||
}
|
||||
|
||||
void AlarmEventDataModel::onRealTimeEventReceived(const EventData& event)
|
||||
{
|
||||
if(m_dataMode != RealTime)
|
||||
|
|
@ -281,7 +331,7 @@ void AlarmEventDataDelegate::paint(QPainter* painter, const QStyleOptionViewItem
|
|||
QStyleOptionViewItem opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
if((index.row() + 1) % 2 == 0)
|
||||
painter->fillRect(opt.rect, QColor(11, 26, 33, 200));
|
||||
painter->fillRect(opt.rect, QColor(11, 26, 33, 100));
|
||||
else
|
||||
painter->fillRect(opt.rect, QColor(11, 26, 33, 0));
|
||||
|
||||
|
|
@ -336,3 +386,9 @@ AlarmEventDataView::AlarmEventDataView(QWidget* parent)
|
|||
|
||||
AlarmEventDataView::~AlarmEventDataView()
|
||||
{}
|
||||
|
||||
void AlarmEventDataView::setModelMode(AlarmDataMode mode)
|
||||
{
|
||||
if(m_tableModel)
|
||||
m_tableModel->setMode(mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ AlarmEventRealTimeDock::AlarmEventRealTimeDock(QWidget* parent)
|
|||
m_curState = "collapse";
|
||||
|
||||
m_tableView = new AlarmEventDataView(this);
|
||||
m_tableView->setModelMode(RealTime);
|
||||
ui->tableLayout->addWidget(m_tableView);
|
||||
|
||||
m_animation = new QPropertyAnimation(this, "geometry");
|
||||
|
|
|
|||
|
|
@ -542,7 +542,6 @@ QTableView
|
|||
}
|
||||
QTableView::item
|
||||
{
|
||||
color: rgb(250, 250, 250);
|
||||
background-color:transparent;
|
||||
}
|
||||
QTableView::item:hover
|
||||
|
|
|
|||
Loading…
Reference in New Issue