feat:完成alrmEventDataModel中实时数据加载展示逻辑
This commit is contained in:
parent
d765f819be
commit
4d6f10f762
|
|
@ -7,6 +7,33 @@
|
|||
#include <QAbstractTableModel>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class AlarmEventDataFilter
|
||||
{
|
||||
public:
|
||||
AlarmEventDataFilter();
|
||||
|
||||
void setTimeRange(const QDateTime& start, const QDateTime& end) {m_startTime = start; m_endTime = end;}
|
||||
void setStationFilter(const QString& station) {m_station = station;}
|
||||
void setBayFilter(const QString& bay) {m_bay = bay;}
|
||||
void setTypeFilter(int type) {m_type = type;}
|
||||
void setSeverityFilter(const QString& severity) {m_severity = severity;}
|
||||
void setDescriptionFilter(const QString& description) {m_description = description;}
|
||||
void setConfirmStatusFilter(int status) {m_status = status;}
|
||||
|
||||
bool matches(const EventData& event);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
QDateTime m_startTime;
|
||||
QDateTime m_endTime;
|
||||
QString m_station;
|
||||
QString m_bay;
|
||||
int m_type;
|
||||
QString m_severity;
|
||||
QString m_description;
|
||||
int m_status;
|
||||
};
|
||||
|
||||
class AlarmEventDataModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -34,7 +61,7 @@ public:
|
|||
struct PaginationInfo
|
||||
{
|
||||
int totalEntries;
|
||||
int entriesPerpage;
|
||||
int entriesPerPage;
|
||||
int totalPages;
|
||||
int currentPage;
|
||||
};
|
||||
|
|
@ -67,46 +94,30 @@ public:
|
|||
const QVector<SectionData> headerData() const {return m_headerData;}
|
||||
void setMaxRealTimeEvents(int value) {m_maxRealTimeEvents = value;}
|
||||
const int getMaxRealTimeEvents() const {return m_maxRealTimeEvents;}
|
||||
void setFilter(const AlarmEventDataFilter& filter);
|
||||
void applyFilter();
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
void onRealTimeEventReceived(const EventData& event);
|
||||
|
||||
private:
|
||||
void iniHeaderData();
|
||||
void updateCurPageData(); //更新当前页的数据
|
||||
void updateTotalCount(); //更新总记录数
|
||||
int findEventDataIndexById(const QString& eventId);
|
||||
void updateEventData(int index, const EventData& updatedEvent);
|
||||
|
||||
QVector<EventData> m_displayEvents;
|
||||
QVector<EventData> m_displayEvents; //当前(页)展示的事件
|
||||
QVector<EventData> m_allEvents; //所有事件
|
||||
QVector<SectionData> m_headerData;
|
||||
PaginationInfo m_paginationInfo;
|
||||
|
||||
AlarmDataMode m_dataMode;
|
||||
AlarmEventDataFilter m_currentFilter;
|
||||
int m_maxRealTimeEvents;
|
||||
};
|
||||
|
||||
class AlarmEventDataFilter
|
||||
{
|
||||
public:
|
||||
AlarmEventDataFilter();
|
||||
|
||||
void setTimeRange(const QDateTime& start, const QDateTime& end) {m_startTime = start; m_endTime = end;}
|
||||
void setStationFilter(const QString& station) {m_station = station;}
|
||||
void setBayFilter(const QString& bay) {m_bay = bay;}
|
||||
void setTypeFilter(int type) {m_type = type;}
|
||||
void setSeverityFilter(const QString& severity) {m_severity = severity;}
|
||||
void setDescriptionFilter(const QString& description) {m_description = description;}
|
||||
void setConfirmStatusFilter(int status) {m_status = status;}
|
||||
|
||||
bool matches(const EventData& event);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
QDateTime m_startTime;
|
||||
QDateTime m_endTime;
|
||||
QString m_station;
|
||||
QString m_bay;
|
||||
int m_type;
|
||||
QString m_severity;
|
||||
QString m_description;
|
||||
int m_status;
|
||||
};
|
||||
|
||||
class AlarmEventDataDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class alarmEventRealTimeDock;
|
|||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class AlarmEventDataView;
|
||||
class QPropertyAnimation;
|
||||
class AlarmEventRealTimeDock : public QWidget
|
||||
{
|
||||
|
|
@ -31,6 +32,7 @@ private:
|
|||
void collapse();
|
||||
|
||||
Ui::alarmEventRealTimeDock* ui;
|
||||
AlarmEventDataView* m_tableView;
|
||||
QPropertyAnimation* m_animation;
|
||||
bool m_isInAnimation;
|
||||
QString m_curState;
|
||||
|
|
|
|||
|
|
@ -3,10 +3,64 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QPainter>
|
||||
|
||||
///////------AlarmEventDataFilter-----
|
||||
AlarmEventDataFilter::AlarmEventDataFilter()
|
||||
{
|
||||
m_type = -1;
|
||||
m_status = -1;
|
||||
}
|
||||
|
||||
bool AlarmEventDataFilter::matches(const EventData& event)
|
||||
{
|
||||
QDateTime eventTime = QDateTime::fromMSecsSinceEpoch(event.timestamp);
|
||||
if(m_startTime.isValid() && eventTime < m_startTime)
|
||||
return false;
|
||||
if(m_endTime.isValid() && eventTime > m_endTime)
|
||||
return false;
|
||||
|
||||
if(!m_station.isEmpty() && event.stationName != m_station)
|
||||
return false;
|
||||
|
||||
if(!m_bay.isEmpty() && event.bayName != m_bay)
|
||||
return false;
|
||||
|
||||
if(event.type != m_type)
|
||||
return false;
|
||||
|
||||
if(!m_severity.isEmpty() && event.severity != m_severity)
|
||||
return false;
|
||||
|
||||
if(!m_description.isEmpty() && event.description != m_description)
|
||||
return false;
|
||||
|
||||
if(event.status != m_status)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AlarmEventDataFilter::clear()
|
||||
{
|
||||
m_startTime = QDateTime();
|
||||
m_endTime = QDateTime();
|
||||
m_station.clear();
|
||||
m_bay.clear();
|
||||
m_type = -1;
|
||||
m_severity.clear();
|
||||
m_description.clear();
|
||||
m_status = -1;
|
||||
}
|
||||
|
||||
|
||||
///////------AlarmEventDataModel-----
|
||||
AlarmEventDataModel::AlarmEventDataModel(QObject* parent)
|
||||
: QAbstractTableModel(parent)
|
||||
,m_maxRealTimeEvents(5)
|
||||
{
|
||||
m_dataMode = Historical;
|
||||
m_paginationInfo.entriesPerPage = 100;
|
||||
m_paginationInfo.currentPage = 1;
|
||||
m_paginationInfo.totalEntries = 0;
|
||||
iniHeaderData();
|
||||
}
|
||||
|
||||
|
|
@ -31,7 +85,7 @@ 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;
|
||||
int globalRow = (m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage + row;
|
||||
const EventData& event = m_displayEvents.at(row);
|
||||
//EventData event = m_displayEvents[row];
|
||||
|
||||
|
|
@ -132,6 +186,17 @@ void AlarmEventDataModel::iniHeaderData()
|
|||
m_headerData.emplace_back(SectionData("操作", 300, Operation));
|
||||
}
|
||||
|
||||
void AlarmEventDataModel::setFilter(const AlarmEventDataFilter& filter)
|
||||
{
|
||||
m_currentFilter = filter;
|
||||
}
|
||||
|
||||
void AlarmEventDataModel::applyFilter()
|
||||
{}
|
||||
|
||||
void AlarmEventDataModel::refresh()
|
||||
{}
|
||||
|
||||
void AlarmEventDataModel::updateCurPageData()
|
||||
{
|
||||
beginResetModel();
|
||||
|
|
@ -144,55 +209,63 @@ void AlarmEventDataModel::updateCurPageData()
|
|||
void AlarmEventDataModel::updateTotalCount()
|
||||
{}
|
||||
|
||||
|
||||
///////------AlarmEventDataFilter-----
|
||||
AlarmEventDataFilter::AlarmEventDataFilter()
|
||||
int AlarmEventDataModel::findEventDataIndexById(const QString& eventId)
|
||||
{
|
||||
m_type = -1;
|
||||
m_status = -1;
|
||||
for(int i = 0; i < m_displayEvents.size(); i++)
|
||||
{
|
||||
if(m_displayEvents.at(i).id == eventId)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool AlarmEventDataFilter::matches(const EventData& event)
|
||||
void AlarmEventDataModel::updateEventData(int index, const EventData& updatedEvent)
|
||||
{
|
||||
QDateTime eventTime = QDateTime::fromMSecsSinceEpoch(event.timestamp);
|
||||
if(m_startTime.isValid() && eventTime < m_startTime)
|
||||
return false;
|
||||
if(m_endTime.isValid() && eventTime > m_endTime)
|
||||
return false;
|
||||
if(index < 0 || index >= m_displayEvents.size())
|
||||
return;
|
||||
|
||||
if(!m_station.isEmpty() && event.stationName != m_station)
|
||||
return false;
|
||||
|
||||
if(!m_bay.isEmpty() && event.bayName != m_bay)
|
||||
return false;
|
||||
|
||||
if(event.type != m_type)
|
||||
return false;
|
||||
|
||||
if(!m_severity.isEmpty() && event.severity != m_severity)
|
||||
return false;
|
||||
|
||||
if(!m_description.isEmpty() && event.description != m_description)
|
||||
return false;
|
||||
|
||||
if(event.status != m_status)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
m_displayEvents[index] = updatedEvent;
|
||||
//更新视图
|
||||
QModelIndex modelIndex = createIndex(index, 0);
|
||||
emit dataChanged(modelIndex, modelIndex);
|
||||
}
|
||||
|
||||
void AlarmEventDataFilter::clear()
|
||||
void AlarmEventDataModel::onRealTimeEventReceived(const EventData& event)
|
||||
{
|
||||
m_startTime = QDateTime();
|
||||
m_endTime = QDateTime();
|
||||
m_station.clear();
|
||||
m_bay.clear();
|
||||
m_type = -1;
|
||||
m_severity.clear();
|
||||
m_description.clear();
|
||||
m_status = -1;
|
||||
if(m_dataMode != RealTime)
|
||||
return;
|
||||
|
||||
int index = findEventDataIndexById(event.id);
|
||||
if(index >= 0)
|
||||
{
|
||||
updateEventData(index, event);
|
||||
return;
|
||||
}
|
||||
|
||||
beginResetModel();
|
||||
|
||||
//插入数据之前,先判断当前是否达到最大显示条目,达到的话删除最靠前(时间)的条目
|
||||
if(m_displayEvents.size() >= m_maxRealTimeEvents)
|
||||
m_displayEvents.removeLast();
|
||||
|
||||
//按照时间顺序排序(从小到大)
|
||||
int insertPosition = 0;
|
||||
for(; insertPosition < m_displayEvents.size(); ++insertPosition)
|
||||
{
|
||||
if(event.timestamp > m_displayEvents.at(insertPosition).timestamp)
|
||||
break;
|
||||
}
|
||||
|
||||
if(insertPosition < m_displayEvents.size())
|
||||
m_displayEvents.insert(insertPosition, event);
|
||||
else
|
||||
m_displayEvents.append(event);
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
///////------AlarmEventDataDelegate-----
|
||||
AlarmEventDataDelegate::AlarmEventDataDelegate(QTableView* view, QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "alarmEventRealTimeDock.h"
|
||||
#include "./ui_alarmEventRealTimeDock.h"
|
||||
#include "alarmEventDataView.h"
|
||||
|
||||
#include <QPropertyAnimation>
|
||||
#include <QTimer>
|
||||
|
|
@ -15,6 +16,9 @@ AlarmEventRealTimeDock::AlarmEventRealTimeDock(QWidget* parent)
|
|||
m_isInAnimation = false;
|
||||
m_curState = "collapse";
|
||||
|
||||
m_tableView = new AlarmEventDataView(this);
|
||||
ui->tableLayout->addWidget(m_tableView);
|
||||
|
||||
m_animation = new QPropertyAnimation(this, "geometry");
|
||||
m_animation->setDuration(120);
|
||||
connect(m_animation, &QPropertyAnimation::finished, this, [this]{m_isInAnimation = false;});
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1539</width>
|
||||
<height>992</height>
|
||||
<width>1563</width>
|
||||
<height>904</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
@ -177,7 +177,7 @@ font: 700 18pt "微软雅黑";
|
|||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>历史事件</string>
|
||||
<string>全部事件</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -526,7 +526,7 @@ icon: url(:/images/icon_configuration.png);
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_timePeriod_3">
|
||||
<widget class="QLineEdit" name="lineEdit_content">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
|
|
|
|||
|
|
@ -563,111 +563,24 @@ QTableView::item:selected
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="textElideMode">
|
||||
<enum>Qt::TextElideMode::ElideNone</enum>
|
||||
</property>
|
||||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>新建行</string>
|
||||
<widget class="QWidget" name="talbeWidget" native="true">
|
||||
<layout class="QVBoxLayout" name="tableLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>新建行</string>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>新建行</string>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>新建行</string>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>新建行</string>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</row>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>序号</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>时间</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>厂站</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>详情</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>类型</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>级别</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>操作</string>
|
||||
</property>
|
||||
</column>
|
||||
<item row="0" column="0">
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<property name="text">
|
||||
<string>2025-09-17 16:51:01</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<property name="text">
|
||||
<string>灵州换流站</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<property name="text">
|
||||
<string>3</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<property name="text">
|
||||
<string>4</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
</property>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
|||
Loading…
Reference in New Issue