169 lines
4.9 KiB
C++
169 lines
4.9 KiB
C++
#include "alarmEventDataView.h"
|
|
#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));
|
|
}
|
|
|
|
|
|
void AlarmEventDataModel::updateCurPageData()
|
|
{
|
|
m_curPageData.clear();
|
|
|
|
}
|
|
|
|
void AlarmEventDataModel::updateTotalCount()
|
|
{}
|
|
|
|
///////------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)
|
|
{
|
|
m_tableView = new QTableView(this);
|
|
m_tableView->verticalHeader()->setVisible(false);
|
|
m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
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);
|
|
m_vLayout->addWidget(m_tableView);
|
|
this->setLayout(m_vLayout);
|
|
}
|
|
|
|
AlarmEventDataView::~AlarmEventDataView()
|
|
{}
|