2025-09-18 15:50:18 +08:00
|
|
|
#ifndef ALARMEVENTDATAVIEW_H
|
|
|
|
|
#define ALARMEVENTDATAVIEW_H
|
|
|
|
|
|
2025-10-10 10:06:54 +08:00
|
|
|
#include "alarmEventGlobal.h"
|
2025-09-18 15:50:18 +08:00
|
|
|
#include <QWidget>
|
2025-09-19 17:45:52 +08:00
|
|
|
#include <QTableView>
|
|
|
|
|
#include <QAbstractTableModel>
|
|
|
|
|
#include <QStyledItemDelegate>
|
|
|
|
|
|
2025-10-17 18:15:06 +08:00
|
|
|
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();
|
2025-10-27 11:43:13 +08:00
|
|
|
QVector<EventData> apply(const QVector<EventData>& events);
|
2025-10-17 18:15:06 +08:00
|
|
|
|
|
|
|
|
private:
|
2025-10-27 11:43:13 +08:00
|
|
|
bool isEmpty();
|
|
|
|
|
|
2025-10-17 18:15:06 +08:00
|
|
|
QDateTime m_startTime;
|
|
|
|
|
QDateTime m_endTime;
|
|
|
|
|
QString m_station;
|
|
|
|
|
QString m_bay;
|
|
|
|
|
int m_type;
|
|
|
|
|
QString m_severity;
|
|
|
|
|
QString m_description;
|
|
|
|
|
int m_status;
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-21 11:13:08 +08:00
|
|
|
class QTimer;
|
2025-09-19 17:45:52 +08:00
|
|
|
class AlarmEventDataModel : public QAbstractTableModel
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2025-10-10 10:06:54 +08:00
|
|
|
enum Column
|
|
|
|
|
{
|
|
|
|
|
Index,
|
|
|
|
|
ReceiveTime,
|
|
|
|
|
SOETime,
|
|
|
|
|
Station,
|
|
|
|
|
Bay,
|
|
|
|
|
Description,
|
|
|
|
|
Type,
|
|
|
|
|
Severity,
|
|
|
|
|
Status,
|
|
|
|
|
Operation,
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-19 17:45:52 +08:00
|
|
|
struct RowData
|
|
|
|
|
{
|
|
|
|
|
QVector<QVariant> values;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PaginationInfo
|
|
|
|
|
{
|
|
|
|
|
int totalEntries;
|
2025-10-17 18:15:06 +08:00
|
|
|
int entriesPerPage;
|
2025-09-19 17:45:52 +08:00
|
|
|
int totalPages;
|
|
|
|
|
int currentPage;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SectionData
|
|
|
|
|
{
|
|
|
|
|
int width = -1;
|
2025-10-10 10:06:54 +08:00
|
|
|
Column column;
|
2025-09-19 17:45:52 +08:00
|
|
|
QString text;
|
|
|
|
|
|
2025-10-10 10:06:54 +08:00
|
|
|
SectionData(QString t, int w, Column c)
|
|
|
|
|
:text(t)
|
|
|
|
|
,column(c)
|
|
|
|
|
,width(w){}
|
2025-09-19 17:45:52 +08:00
|
|
|
};
|
|
|
|
|
|
2025-10-28 16:39:23 +08:00
|
|
|
explicit AlarmEventDataModel(AlarmDataMode mode, QObject* parent = nullptr);
|
2025-09-19 17:45:52 +08:00
|
|
|
~AlarmEventDataModel();
|
|
|
|
|
|
2025-10-13 17:31:50 +08:00
|
|
|
//QAbstractTableModel接口实现
|
2025-09-19 17:45:52 +08:00
|
|
|
QModelIndex index(int row, int column, const QModelIndex& parent) const override;
|
|
|
|
|
QVariant data(const QModelIndex& index, int role) const override;
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
|
|
|
|
//bool setData(const QModelIndex& index, const QVariant &value, int role = Qt::EditRole) override;
|
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
|
|
|
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
|
|
|
|
|
2025-10-13 17:31:50 +08:00
|
|
|
//自定义功能函数
|
2025-10-10 10:06:54 +08:00
|
|
|
const QVector<SectionData> headerData() const {return m_headerData;}
|
2025-10-28 16:39:23 +08:00
|
|
|
//void setMode(AlarmDataMode mode);
|
|
|
|
|
void setMaxRealTimeEvents(int value);
|
2025-10-13 17:31:50 +08:00
|
|
|
const int getMaxRealTimeEvents() const {return m_maxRealTimeEvents;}
|
2025-10-17 18:15:06 +08:00
|
|
|
void setFilter(const AlarmEventDataFilter& filter);
|
|
|
|
|
void refresh();
|
|
|
|
|
|
2025-10-28 16:39:23 +08:00
|
|
|
bool setCurrentPage(int);
|
|
|
|
|
void previousPage();
|
|
|
|
|
void nextPage();
|
|
|
|
|
void firstPage();
|
|
|
|
|
void lastPage();
|
2025-10-27 17:43:39 +08:00
|
|
|
|
|
|
|
|
private slots:
|
2025-10-21 11:13:08 +08:00
|
|
|
void onTimeoutSimulateData();
|
2025-10-17 18:15:06 +08:00
|
|
|
void onRealTimeEventReceived(const EventData& event);
|
2025-10-10 10:06:54 +08:00
|
|
|
|
2025-09-19 17:45:52 +08:00
|
|
|
private:
|
|
|
|
|
void iniHeaderData();
|
2025-10-27 17:43:39 +08:00
|
|
|
void applyFilter();
|
2025-10-24 17:28:14 +08:00
|
|
|
void updatePaginationInfo();
|
2025-10-17 18:15:06 +08:00
|
|
|
int findEventDataIndexById(const QString& eventId);
|
|
|
|
|
void updateEventData(int index, const EventData& updatedEvent);
|
2025-10-24 17:28:14 +08:00
|
|
|
void updateCurPageData();
|
2025-09-19 17:45:52 +08:00
|
|
|
|
2025-10-17 18:15:06 +08:00
|
|
|
QVector<EventData> m_allEvents; //所有事件
|
2025-10-24 17:28:14 +08:00
|
|
|
QVector<EventData> m_filteredEvents; //过滤后的事件
|
|
|
|
|
QVector<EventData> m_displayEvents; //当前(页)展示的事件
|
2025-09-19 17:45:52 +08:00
|
|
|
QVector<SectionData> m_headerData;
|
|
|
|
|
PaginationInfo m_paginationInfo;
|
2025-10-13 17:31:50 +08:00
|
|
|
|
2025-10-21 11:13:08 +08:00
|
|
|
QTimer* m_simulatedDataTimer;
|
|
|
|
|
|
2025-10-17 18:15:06 +08:00
|
|
|
AlarmDataMode m_dataMode;
|
|
|
|
|
AlarmEventDataFilter m_currentFilter;
|
2025-10-13 17:31:50 +08:00
|
|
|
int m_maxRealTimeEvents;
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-19 17:45:52 +08:00
|
|
|
class AlarmEventDataDelegate : public QStyledItemDelegate
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit AlarmEventDataDelegate(QTableView* view, QObject* parent = nullptr);
|
|
|
|
|
~AlarmEventDataDelegate();
|
|
|
|
|
|
|
|
|
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
2025-10-23 16:54:59 +08:00
|
|
|
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
|
2025-09-19 17:45:52 +08:00
|
|
|
|
2025-10-23 20:21:32 +08:00
|
|
|
signals:
|
|
|
|
|
void confirmBtnClicked(const QModelIndex& index);
|
|
|
|
|
void replayBtnClicked(const QModelIndex& index);
|
|
|
|
|
|
2025-09-19 17:45:52 +08:00
|
|
|
private:
|
2025-10-23 16:54:59 +08:00
|
|
|
struct ControlButton
|
|
|
|
|
{
|
|
|
|
|
QRect rect;
|
|
|
|
|
QColor normalBgColor;
|
|
|
|
|
QColor hoverBgColor;
|
|
|
|
|
QColor pressedBgColor;
|
|
|
|
|
QColor borderColor;
|
|
|
|
|
QColor textColor;
|
|
|
|
|
QFont textFont;
|
|
|
|
|
int borderWidth;
|
|
|
|
|
int borderRaius;
|
|
|
|
|
QString text;
|
2025-10-23 19:05:48 +08:00
|
|
|
//int mouseState = 0; //0Normal,1Hover,2Pressed
|
2025-10-23 16:54:59 +08:00
|
|
|
};
|
|
|
|
|
|
2025-09-19 17:45:52 +08:00
|
|
|
QTableView* m_tableView;
|
2025-10-23 19:05:48 +08:00
|
|
|
QPoint m_mousePositon;
|
|
|
|
|
bool m_buttonColumnIsPress;
|
2025-10-23 16:54:59 +08:00
|
|
|
ControlButton m_btnConfirm;
|
|
|
|
|
ControlButton m_btnReplay;
|
2025-09-19 17:45:52 +08:00
|
|
|
};
|
2025-09-18 15:50:18 +08:00
|
|
|
|
|
|
|
|
class QVBoxLayout;
|
|
|
|
|
class AlarmEventDataView : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2025-10-28 16:39:23 +08:00
|
|
|
AlarmEventDataView(AlarmDataMode mode, QWidget* parent = nullptr);
|
2025-09-18 15:50:18 +08:00
|
|
|
~AlarmEventDataView();
|
|
|
|
|
|
2025-10-28 16:39:23 +08:00
|
|
|
//void setModelMode(AlarmDataMode, int maxRealTimeEvents = 5);
|
2025-10-21 11:13:08 +08:00
|
|
|
|
2025-10-23 20:21:32 +08:00
|
|
|
public slots:
|
|
|
|
|
void onBtnClicked_Confirm(const QModelIndex& index);
|
|
|
|
|
void onBtnClicked_Replay(const QModelIndex& index);
|
|
|
|
|
|
2025-09-18 15:50:18 +08:00
|
|
|
private:
|
|
|
|
|
QTableView* m_tableView;
|
2025-09-19 17:45:52 +08:00
|
|
|
AlarmEventDataModel* m_tableModel;
|
|
|
|
|
AlarmEventDataDelegate* m_delegate;
|
2025-09-18 15:50:18 +08:00
|
|
|
QVBoxLayout* m_vLayout;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|