添加OpenCv
This commit is contained in:
@@ -1,14 +1,77 @@
|
||||
#include "P08_AlarmPage.h"
|
||||
#include "ui_P08_AlarmPage.h"
|
||||
|
||||
#include <DataCenter/MySQL.h>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <GlobalDefinitions/Variable.h>
|
||||
MySQL P08_sql;
|
||||
P08_AlarmPage::P08_AlarmPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::P08_AlarmPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
WinInit();
|
||||
}
|
||||
|
||||
P08_AlarmPage::~P08_AlarmPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
uint16_t OldAlarmCode = 0;
|
||||
void P08_AlarmPage::WinInit()
|
||||
{
|
||||
OldAlarmCode = 0;
|
||||
//所用定时器初始化
|
||||
QTimer* UIRefresh_Timer = new QTimer(this);
|
||||
connect(UIRefresh_Timer, &QTimer::timeout, this, &P08_AlarmPage::UIRefreshTimeOut);
|
||||
UIRefresh_Timer->setInterval(100); // 设置定时器间隔为 1000 毫秒(1 秒)
|
||||
UIRefresh_Timer->start();
|
||||
}
|
||||
static QColor parseCssRgb(const QString &css)
|
||||
{
|
||||
// 正则把 "rgb(255, 0, 0)" 里的数字抠出来
|
||||
QRegularExpression re("rgb\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)");
|
||||
QRegularExpressionMatch m = re.match(css);
|
||||
if (m.hasMatch())
|
||||
return QColor(m.captured(1).toInt(),
|
||||
m.captured(2).toInt(),
|
||||
m.captured(3).toInt());
|
||||
return Qt::black; // 解析失败就回退到黑色
|
||||
}
|
||||
|
||||
void P08_AlarmPage::UIRefreshTimeOut()
|
||||
{
|
||||
|
||||
uint16_t NewAlarmCode = gOPC_NodeValue["ns=6;s=::AsGlobalPV:AlarmCode.New"] .toUInt();
|
||||
if (NewAlarmCode == OldAlarmCode)
|
||||
return;
|
||||
ui->ListWidget_AlarmList->clear();
|
||||
|
||||
auto rows = P08_sql.selectLatest("AlarmHistory", 100);
|
||||
for (const auto &row : rows) {
|
||||
// 0 时间 1 报警内容 2 排查方法 3 报警代码
|
||||
QDateTime t = row[0].toDateTime();
|
||||
QString text1 = row[1].toString();
|
||||
QString text2 = row[2].toString();
|
||||
QString CodeText = row[3].toString();
|
||||
/* 把 16 位 code 拆成高 8 位设备码 + 低 8 位索引码 */
|
||||
bool ok;
|
||||
uint16_t code = CodeText.toUShort(&ok, 16); // 16 表示按 16 进制解析
|
||||
uint8_t devCode = code / 256; // 高 8 位
|
||||
uint8_t idxCode = code % 256; // 低 8 位
|
||||
|
||||
/* 显示格式: [时间] 设备码-索引码 内容 排查方法 */
|
||||
QString AlarmTexts = QString("[%1] %2 %3")
|
||||
.arg(t.toString("MM-dd hh:mm:ss"))
|
||||
.arg(CodeText,text1);
|
||||
QString colorStr = AlarmText[devCode][idxCode].TextColor;
|
||||
QListWidgetItem *item = new QListWidgetItem(AlarmTexts);
|
||||
item->setForeground(parseCssRgb(colorStr));
|
||||
ui->ListWidget_AlarmList->addItem(item);
|
||||
|
||||
}
|
||||
|
||||
OldAlarmCode = NewAlarmCode;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user