feat:完成alrmEventDataModel中实时数据加载展示逻辑
This commit is contained in:
parent
d765f819be
commit
4d6f10f762
|
|
@ -7,6 +7,33 @@
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
#include <QStyledItemDelegate>
|
#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
|
class AlarmEventDataModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -34,7 +61,7 @@ public:
|
||||||
struct PaginationInfo
|
struct PaginationInfo
|
||||||
{
|
{
|
||||||
int totalEntries;
|
int totalEntries;
|
||||||
int entriesPerpage;
|
int entriesPerPage;
|
||||||
int totalPages;
|
int totalPages;
|
||||||
int currentPage;
|
int currentPage;
|
||||||
};
|
};
|
||||||
|
|
@ -67,46 +94,30 @@ public:
|
||||||
const QVector<SectionData> headerData() const {return m_headerData;}
|
const QVector<SectionData> headerData() const {return m_headerData;}
|
||||||
void setMaxRealTimeEvents(int value) {m_maxRealTimeEvents = value;}
|
void setMaxRealTimeEvents(int value) {m_maxRealTimeEvents = value;}
|
||||||
const int getMaxRealTimeEvents() const {return m_maxRealTimeEvents;}
|
const int getMaxRealTimeEvents() const {return m_maxRealTimeEvents;}
|
||||||
|
void setFilter(const AlarmEventDataFilter& filter);
|
||||||
|
void applyFilter();
|
||||||
|
void refresh();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onRealTimeEventReceived(const EventData& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void iniHeaderData();
|
void iniHeaderData();
|
||||||
void updateCurPageData(); //更新当前页的数据
|
void updateCurPageData(); //更新当前页的数据
|
||||||
void updateTotalCount(); //更新总记录数
|
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;
|
QVector<SectionData> m_headerData;
|
||||||
PaginationInfo m_paginationInfo;
|
PaginationInfo m_paginationInfo;
|
||||||
|
|
||||||
|
AlarmDataMode m_dataMode;
|
||||||
|
AlarmEventDataFilter m_currentFilter;
|
||||||
int m_maxRealTimeEvents;
|
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
|
class AlarmEventDataDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ class alarmEventRealTimeDock;
|
||||||
}
|
}
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class AlarmEventDataView;
|
||||||
class QPropertyAnimation;
|
class QPropertyAnimation;
|
||||||
class AlarmEventRealTimeDock : public QWidget
|
class AlarmEventRealTimeDock : public QWidget
|
||||||
{
|
{
|
||||||
|
|
@ -31,6 +32,7 @@ private:
|
||||||
void collapse();
|
void collapse();
|
||||||
|
|
||||||
Ui::alarmEventRealTimeDock* ui;
|
Ui::alarmEventRealTimeDock* ui;
|
||||||
|
AlarmEventDataView* m_tableView;
|
||||||
QPropertyAnimation* m_animation;
|
QPropertyAnimation* m_animation;
|
||||||
bool m_isInAnimation;
|
bool m_isInAnimation;
|
||||||
QString m_curState;
|
QString m_curState;
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,64 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QPainter>
|
#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::AlarmEventDataModel(QObject* parent)
|
AlarmEventDataModel::AlarmEventDataModel(QObject* parent)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractTableModel(parent)
|
||||||
|
,m_maxRealTimeEvents(5)
|
||||||
{
|
{
|
||||||
|
m_dataMode = Historical;
|
||||||
|
m_paginationInfo.entriesPerPage = 100;
|
||||||
|
m_paginationInfo.currentPage = 1;
|
||||||
|
m_paginationInfo.totalEntries = 0;
|
||||||
iniHeaderData();
|
iniHeaderData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +85,7 @@ QVariant AlarmEventDataModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
int row = index.row();
|
int row = index.row();
|
||||||
int col = index.column();
|
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);
|
const EventData& event = m_displayEvents.at(row);
|
||||||
//EventData event = m_displayEvents[row];
|
//EventData event = m_displayEvents[row];
|
||||||
|
|
||||||
|
|
@ -132,6 +186,17 @@ void AlarmEventDataModel::iniHeaderData()
|
||||||
m_headerData.emplace_back(SectionData("操作", 300, Operation));
|
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()
|
void AlarmEventDataModel::updateCurPageData()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
@ -144,55 +209,63 @@ void AlarmEventDataModel::updateCurPageData()
|
||||||
void AlarmEventDataModel::updateTotalCount()
|
void AlarmEventDataModel::updateTotalCount()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
int AlarmEventDataModel::findEventDataIndexById(const QString& eventId)
|
||||||
///////------AlarmEventDataFilter-----
|
|
||||||
AlarmEventDataFilter::AlarmEventDataFilter()
|
|
||||||
{
|
{
|
||||||
m_type = -1;
|
for(int i = 0; i < m_displayEvents.size(); i++)
|
||||||
m_status = -1;
|
{
|
||||||
|
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(index < 0 || index >= m_displayEvents.size())
|
||||||
if(m_startTime.isValid() && eventTime < m_startTime)
|
return;
|
||||||
return false;
|
|
||||||
if(m_endTime.isValid() && eventTime > m_endTime)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(!m_station.isEmpty() && event.stationName != m_station)
|
m_displayEvents[index] = updatedEvent;
|
||||||
return false;
|
//更新视图
|
||||||
|
QModelIndex modelIndex = createIndex(index, 0);
|
||||||
if(!m_bay.isEmpty() && event.bayName != m_bay)
|
emit dataChanged(modelIndex, modelIndex);
|
||||||
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()
|
void AlarmEventDataModel::onRealTimeEventReceived(const EventData& event)
|
||||||
{
|
{
|
||||||
m_startTime = QDateTime();
|
if(m_dataMode != RealTime)
|
||||||
m_endTime = QDateTime();
|
return;
|
||||||
m_station.clear();
|
|
||||||
m_bay.clear();
|
int index = findEventDataIndexById(event.id);
|
||||||
m_type = -1;
|
if(index >= 0)
|
||||||
m_severity.clear();
|
{
|
||||||
m_description.clear();
|
updateEventData(index, event);
|
||||||
m_status = -1;
|
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::AlarmEventDataDelegate(QTableView* view, QObject* parent)
|
AlarmEventDataDelegate::AlarmEventDataDelegate(QTableView* view, QObject* parent)
|
||||||
: QStyledItemDelegate(parent)
|
: QStyledItemDelegate(parent)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "alarmEventRealTimeDock.h"
|
#include "alarmEventRealTimeDock.h"
|
||||||
#include "./ui_alarmEventRealTimeDock.h"
|
#include "./ui_alarmEventRealTimeDock.h"
|
||||||
|
#include "alarmEventDataView.h"
|
||||||
|
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
@ -15,6 +16,9 @@ AlarmEventRealTimeDock::AlarmEventRealTimeDock(QWidget* parent)
|
||||||
m_isInAnimation = false;
|
m_isInAnimation = false;
|
||||||
m_curState = "collapse";
|
m_curState = "collapse";
|
||||||
|
|
||||||
|
m_tableView = new AlarmEventDataView(this);
|
||||||
|
ui->tableLayout->addWidget(m_tableView);
|
||||||
|
|
||||||
m_animation = new QPropertyAnimation(this, "geometry");
|
m_animation = new QPropertyAnimation(this, "geometry");
|
||||||
m_animation->setDuration(120);
|
m_animation->setDuration(120);
|
||||||
connect(m_animation, &QPropertyAnimation::finished, this, [this]{m_isInAnimation = false;});
|
connect(m_animation, &QPropertyAnimation::finished, this, [this]{m_isInAnimation = false;});
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1539</width>
|
<width>1563</width>
|
||||||
<height>992</height>
|
<height>904</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
|
@ -177,7 +177,7 @@ font: 700 18pt "微软雅黑";
|
||||||
</string>
|
</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>历史事件</string>
|
<string>全部事件</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -526,7 +526,7 @@ icon: url(:/images/icon_configuration.png);
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="lineEdit_timePeriod_3">
|
<widget class="QLineEdit" name="lineEdit_content">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>0</width>
|
<width>0</width>
|
||||||
|
|
|
||||||
|
|
@ -563,111 +563,24 @@ QTableView::item:selected
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableWidget" name="tableWidget">
|
<widget class="QWidget" name="talbeWidget" native="true">
|
||||||
<property name="textElideMode">
|
<layout class="QVBoxLayout" name="tableLayout">
|
||||||
<enum>Qt::TextElideMode::ElideNone</enum>
|
<property name="spacing">
|
||||||
</property>
|
<number>0</number>
|
||||||
<property name="showGrid">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<attribute name="verticalHeaderVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
<row>
|
|
||||||
<property name="text">
|
|
||||||
<string>新建行</string>
|
|
||||||
</property>
|
</property>
|
||||||
</row>
|
<property name="leftMargin">
|
||||||
<row>
|
<number>0</number>
|
||||||
<property name="text">
|
|
||||||
<string>新建行</string>
|
|
||||||
</property>
|
</property>
|
||||||
</row>
|
<property name="topMargin">
|
||||||
<row>
|
<number>0</number>
|
||||||
<property name="text">
|
|
||||||
<string>新建行</string>
|
|
||||||
</property>
|
</property>
|
||||||
</row>
|
<property name="rightMargin">
|
||||||
<row>
|
<number>0</number>
|
||||||
<property name="text">
|
|
||||||
<string>新建行</string>
|
|
||||||
</property>
|
</property>
|
||||||
</row>
|
<property name="bottomMargin">
|
||||||
<row>
|
<number>0</number>
|
||||||
<property name="text">
|
|
||||||
<string>新建行</string>
|
|
||||||
</property>
|
</property>
|
||||||
</row>
|
</layout>
|
||||||
<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>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue