feat:添加事件主窗口及其相关文件
This commit is contained in:
parent
956483cc94
commit
cb52a6bd29
|
|
@ -2,8 +2,73 @@
|
|||
#define ALARMEVENTDATAVIEW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTableView>
|
||||
#include <QAbstractTableModel>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class AlarmEventDataModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct RowData
|
||||
{
|
||||
QVector<QVariant> values;
|
||||
};
|
||||
|
||||
struct PaginationInfo
|
||||
{
|
||||
int totalEntries;
|
||||
int entriesPerpage;
|
||||
int totalPages;
|
||||
int currentPage;
|
||||
};
|
||||
|
||||
struct SectionData
|
||||
{
|
||||
int width = -1;
|
||||
QString text;
|
||||
|
||||
SectionData(QString t, int w)
|
||||
:text(t),
|
||||
width(w){}
|
||||
};
|
||||
|
||||
explicit AlarmEventDataModel(QObject* parent = nullptr);
|
||||
~AlarmEventDataModel();
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
void iniHeaderData();
|
||||
void updateCurPageData(); //更新当前页的数据
|
||||
void updateTotalCount(); //更新总记录数
|
||||
|
||||
QVector<RowData> m_curPageData;
|
||||
QVector<SectionData> m_headerData;
|
||||
PaginationInfo m_paginationInfo;
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
QTableView* m_tableView;
|
||||
};
|
||||
|
||||
class QTableView;
|
||||
class QVBoxLayout;
|
||||
class AlarmEventDataView : public QWidget
|
||||
{
|
||||
|
|
@ -15,6 +80,8 @@ public:
|
|||
|
||||
private:
|
||||
QTableView* m_tableView;
|
||||
AlarmEventDataModel* m_tableModel;
|
||||
AlarmEventDataDelegate* m_delegate;
|
||||
QVBoxLayout* m_vLayout;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <QString>
|
||||
#include <QDateTime>
|
||||
|
||||
enum MainDialogType
|
||||
enum MainDialogMode
|
||||
{
|
||||
RealTime = 0,
|
||||
Historical
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ class AlarmEventMainDialog : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AlarmEventMainDialog(MainDialogType type, QWidget *parent = nullptr);
|
||||
AlarmEventMainDialog(QWidget *parent = nullptr);
|
||||
~AlarmEventMainDialog();
|
||||
|
||||
void setMode(MainDialogMode mode);
|
||||
|
||||
signals:
|
||||
void sgl_hide();
|
||||
|
||||
|
|
@ -26,6 +28,8 @@ public slots:
|
|||
|
||||
private:
|
||||
Ui::alarmEventMainDialog* ui;
|
||||
MainDialogMode m_mode;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class DateTimeWidget;
|
|||
class TimeLineWidget;
|
||||
class DataPanel;
|
||||
class dpConfigurationDialog;
|
||||
class AlarmEventMainDialog;
|
||||
|
||||
namespace dashboardFrame {
|
||||
enum frameType
|
||||
|
|
@ -74,6 +75,8 @@ public slots:
|
|||
void onBtnClicked_addDataPanel();
|
||||
void onBtnClicked_dashboardList();
|
||||
void onBtnClicked_dashboardTab();
|
||||
void onBtnClicked_showRealtimeEvents();
|
||||
void onBtnClicked_showHistoricalEvents();
|
||||
|
||||
void onMenuAction_dashboardList();
|
||||
|
||||
|
|
@ -110,6 +113,7 @@ private:
|
|||
TimeLineWidget* m_pTimeLineWidget;
|
||||
|
||||
dpConfigurationDialog* m_pPanelConfigurationDialog;
|
||||
AlarmEventMainDialog* m_pAlarmEventMainDialog;
|
||||
|
||||
QTimer* m_pTimer_RealTime;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,138 @@
|
|||
#include "alarmEventDataView.h"
|
||||
#include <QTableView>
|
||||
#include <QHeaderView>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPainter>
|
||||
|
||||
///////------AlarmEventDataModel-----
|
||||
AlarmEventDataModel::AlarmEventDataModel(QObject* parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
iniHeaderData();
|
||||
}
|
||||
|
||||
AlarmEventDataModel::~AlarmEventDataModel()
|
||||
{}
|
||||
|
||||
QModelIndex AlarmEventDataModel::index(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
if(!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
if(column > m_headerData.count())
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(row, column);
|
||||
}
|
||||
|
||||
QVariant AlarmEventDataModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if(index.isValid())
|
||||
return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
int globalRow = (m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerpage + row;
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
{
|
||||
if(index.column() == 0) //第一列显示序号
|
||||
return QString::number(globalRow + 1);
|
||||
else
|
||||
{
|
||||
int dataCol = col - 1;
|
||||
const RowData& rowData = m_curPageData[row];
|
||||
return rowData.values.value(dataCol);
|
||||
}
|
||||
}
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter; //居中展示
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant AlarmEventDataModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if(orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return m_headerData.at(section).text;
|
||||
|
||||
return QAbstractItemModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
int AlarmEventDataModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return m_curPageData.count();
|
||||
}
|
||||
|
||||
int AlarmEventDataModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return m_headerData.isEmpty() ? 0 : m_headerData.count();
|
||||
}
|
||||
|
||||
Qt::ItemFlags AlarmEventDataModel::flags(const QModelIndex& index) const
|
||||
{
|
||||
if(!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
|
||||
flags |= Qt::ItemIsEditable; //不可编辑
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
///////------AlarmEventDataDelegate-----
|
||||
AlarmEventDataDelegate::AlarmEventDataDelegate(QTableView* view, QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
,m_tableView(view)
|
||||
{}
|
||||
|
||||
AlarmEventDataDelegate::~AlarmEventDataDelegate()
|
||||
{}
|
||||
|
||||
void AlarmEventDataDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
//根据行号设置交替颜色
|
||||
QStyleOptionViewItem opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
if((index.row() + 1) % 2 == 0)
|
||||
painter->fillRect(opt.rect, QColor(11, 26, 33, 200));
|
||||
else
|
||||
painter->fillRect(opt.rect, QColor(11, 26, 33, 0));
|
||||
|
||||
//绘制单元格边框(只绘制右边框,每行的最后一个单元格不绘制)
|
||||
if(m_tableView)
|
||||
{
|
||||
painter->save();
|
||||
QPen pen(QColor(60,60,60), 1);
|
||||
painter->setPen(pen);
|
||||
if(index.column() != m_tableView->model()->columnCount() - 1)
|
||||
painter->drawLine(opt.rect.topRight(), opt.rect.bottomRight());
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
//绘制默认内容
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
|
||||
|
||||
///////------AlarmEventDataView-----
|
||||
AlarmEventDataView::AlarmEventDataView(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
|
|
@ -12,6 +142,12 @@ AlarmEventDataView::AlarmEventDataView(QWidget* parent)
|
|||
m_tableView->setShowGrid(false);
|
||||
//m_tableView->setStyleSheet("QHeaderView{background-color: rgb(40, 40, 40);} QHeaderView::section{background-color:transparent;}");
|
||||
|
||||
m_tableModel = new AlarmEventDataModel(this);
|
||||
m_tableView->setModel(m_tableModel);
|
||||
|
||||
m_delegate = new AlarmEventDataDelegate(m_tableView, this);
|
||||
m_tableView->setItemDelegate(m_delegate);
|
||||
|
||||
m_vLayout = new QVBoxLayout(this);
|
||||
m_vLayout->setSpacing(0);
|
||||
m_vLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
#include "alarmEventMainDialog.h"
|
||||
#include "ui_alarmEventMainDialog.h"
|
||||
|
||||
AlarmEventMainDialog::AlarmEventMainDialog(MainDialogType type, QWidget *parent)
|
||||
AlarmEventMainDialog::AlarmEventMainDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::alarmEventMainDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowFlags(Qt::FramelessWindowHint);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
if(type == RealTime)
|
||||
ui->dataFilteringPanel->setVisible(false);
|
||||
else
|
||||
ui->dataFilteringPanel->setVisible(true);
|
||||
connect(ui->btnClose, &QPushButton::clicked, this, &AlarmEventMainDialog::onBtnClicked_close);
|
||||
}
|
||||
|
||||
AlarmEventMainDialog::~AlarmEventMainDialog()
|
||||
|
|
@ -18,6 +17,22 @@ AlarmEventMainDialog::~AlarmEventMainDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void AlarmEventMainDialog::setMode(MainDialogMode mode)
|
||||
{
|
||||
if(mode == RealTime)
|
||||
{
|
||||
ui->label_WindowlTitle->setText("实时报警");
|
||||
ui->dataFilteringPanel->setVisible(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->label_WindowlTitle->setText("历史事件");
|
||||
ui->dataFilteringPanel->setVisible(true);
|
||||
}
|
||||
|
||||
m_mode = mode;
|
||||
}
|
||||
|
||||
void AlarmEventMainDialog::onBtnClicked_close()
|
||||
{
|
||||
//reject();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "dataPanel/dpConfigurationDialog.h"
|
||||
#include "dateTimeWidget.h"
|
||||
#include "util/TimeLine/timeLineWidget.h"
|
||||
#include "alarmEventMainDialog.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
|
|
@ -33,6 +34,7 @@ DashboardFrame::DashboardFrame(const QString& strName, dashboardFrame::frameType
|
|||
, m_curOperationDashboard(nullptr)
|
||||
, m_pPanelSelectionDialog(nullptr)
|
||||
, m_pPanelConfigurationDialog(nullptr)
|
||||
, m_pAlarmEventMainDialog(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setAcceptDrops(true);
|
||||
|
|
@ -78,11 +80,17 @@ DashboardFrame::DashboardFrame(const QString& strName, dashboardFrame::frameType
|
|||
connect(ui->btnAddPanel, SIGNAL(clicked()), this, SLOT(onBtnClicked_addDataPanel()));
|
||||
//connect(ui->btnDashboradList1, SIGNAL(clicked()), this, SLOT(onBtnClicked_dashboardList()));
|
||||
connect(ui->btnDashboradList2, SIGNAL(clicked()), this, SLOT(onBtnClicked_dashboardList()));
|
||||
connect(ui->btnAlarm, SIGNAL(clicked()), this, SLOT(onBtnClicked_showRealtimeEvents()));
|
||||
connect(ui->btnAllEvent, SIGNAL(clicked()), this, SLOT(onBtnClicked_showHistoricalEvents()));
|
||||
|
||||
m_pTimer_RealTime = new QTimer(this);
|
||||
m_pTimer_RealTime->setTimerType(Qt::PreciseTimer); //设置成高精度类型,默认为Qt::CoarseTimer(粗糙定时器)
|
||||
connect(m_pTimer_RealTime, SIGNAL(timeout()), this, SLOT(onTimeout_realTime()));
|
||||
m_pTimer_RealTime->start(1000);
|
||||
|
||||
//暂时放弃这两个按钮的逻辑
|
||||
ui->btnShowDashboards->setVisible(false);
|
||||
ui->btnShowNotifications->setVisible(false);
|
||||
}
|
||||
|
||||
DashboardFrame::~DashboardFrame()
|
||||
|
|
@ -489,7 +497,8 @@ void DashboardFrame::onBtnClicked_addDashboard()
|
|||
m_pDashboardNamingDialog = new DashboardNamingDialog(this);
|
||||
m_pDashboardNamingDialog->installEventFilter(this);
|
||||
connect(m_pDashboardNamingDialog, SIGNAL(sgl_hide()), this, SLOT(onSignal_subDialogClose()));
|
||||
connect(m_pDashboardNamingDialog, SIGNAL(dashboardName(const QString&, const QString&)), this, SLOT(onSignal_dashboardNaming(const QString&, const QString&)));
|
||||
connect(m_pDashboardNamingDialog, &DashboardNamingDialog::dashboardName, this, &DashboardFrame::onSignal_dashboardNaming);
|
||||
//connect(m_pDashboardNamingDialog, SIGNAL(dashboardName(const QString&, const QString&)), this, SLOT(onSignal_dashboardNaming(const QString&, const QString&)));
|
||||
}
|
||||
|
||||
showTransparentMask();
|
||||
|
|
@ -567,6 +576,44 @@ void DashboardFrame::onBtnClicked_dashboardTab()
|
|||
setCurrentDashboard(strName);
|
||||
}
|
||||
|
||||
void DashboardFrame::onBtnClicked_showRealtimeEvents()
|
||||
{
|
||||
if(m_pAlarmEventMainDialog == nullptr)
|
||||
{
|
||||
m_pAlarmEventMainDialog = new AlarmEventMainDialog(this);
|
||||
connect(m_pAlarmEventMainDialog, SIGNAL(sgl_hide()), this, SLOT(onSignal_subDialogClose()));
|
||||
}
|
||||
|
||||
m_pAlarmEventMainDialog->setMode(RealTime);
|
||||
int nWidth = this->width() * 0.8;
|
||||
int nHeight = this->height() * 0.8;
|
||||
int nX = this->geometry().x() + (this->width() - nWidth) * 0.5;
|
||||
int nY = this->geometry().y() + (this->height() - nHeight) * 0.5;
|
||||
showTransparentMask();
|
||||
m_pAlarmEventMainDialog->setGeometry(nX, nY, nWidth, nHeight);
|
||||
m_pAlarmEventMainDialog->show();
|
||||
m_pAlarmEventMainDialog->raise();
|
||||
}
|
||||
|
||||
void DashboardFrame::onBtnClicked_showHistoricalEvents()
|
||||
{
|
||||
if(m_pAlarmEventMainDialog == nullptr)
|
||||
{
|
||||
m_pAlarmEventMainDialog = new AlarmEventMainDialog(this);
|
||||
connect(m_pAlarmEventMainDialog, SIGNAL(sgl_hide()), this, SLOT(onSignal_subDialogClose()));
|
||||
}
|
||||
|
||||
m_pAlarmEventMainDialog->setMode(Historical);
|
||||
int nWidth = this->width() * 0.8;
|
||||
int nHeight = this->height() * 0.8;
|
||||
int nX = this->geometry().x() + (this->width() - nWidth) * 0.5;
|
||||
int nY = this->geometry().y() + (this->height() - nHeight) * 0.5;
|
||||
showTransparentMask();
|
||||
m_pAlarmEventMainDialog->setGeometry(nX, nY, nWidth, nHeight);
|
||||
m_pAlarmEventMainDialog->show();
|
||||
m_pAlarmEventMainDialog->raise();
|
||||
}
|
||||
|
||||
void DashboardFrame::onMenuAction_dashboardList()
|
||||
{
|
||||
QAction* action = qobject_cast<QAction*>(sender());
|
||||
|
|
@ -639,7 +686,7 @@ void DashboardFrame::onSignal_renameDashboard()
|
|||
{
|
||||
m_pDashboardNamingDialog = new DashboardNamingDialog(this);
|
||||
connect(m_pDashboardNamingDialog, SIGNAL(dlgHide()), this, SLOT(onSignal_subDialogClose()));
|
||||
connect(m_pDashboardNamingDialog, SIGNAL(dashboardName(const QString&, const QString&)), this, SLOT(onSignal_dashboardNaming(const QString&, const QString&)));
|
||||
connect(m_pDashboardNamingDialog, &DashboardNamingDialog::dashboardName, this, &DashboardFrame::onSignal_dashboardNaming);
|
||||
}
|
||||
|
||||
showTransparentMask();
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue