3500/realtimeform.cpp

1330 lines
69 KiB
C++
Raw Normal View History

2023-04-14 19:30:30 +08:00
#include "realtimeform.h"
#include "ui_realtimeform.h"
#include <QDebug>
#include <QMenu>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QFile>
#include <QMessageBox>
#include "MyCustomGraphicsItem.h"
#include "NetMgr.h"
#include <QNetworkRequest>
2023-04-27 19:48:15 +08:00
#include "QGraphicsMovieItem.h"
#include <QLabel>
#include "log.h"
2023-10-19 14:15:31 +08:00
#include <QSettings>
#include <algorithm>
2023-10-19 14:15:31 +08:00
#include "customrectitem.h"
#include "mygraphicrectitem.h"
#include "CustomGraphicsItemGroup.h"
2023-10-19 14:15:31 +08:00
2023-04-14 19:30:30 +08:00
CRealTimeForm::CRealTimeForm(QWidget *parent) :
QWidget(parent),
2024-09-11 16:37:00 +08:00
ui(new Ui::CRealTimeForm) {
2023-04-14 19:30:30 +08:00
ui->setupUi(this);
ui->graphicsView->setContextMenuPolicy(Qt::CustomContextMenu);
2024-09-11 16:37:00 +08:00
QObject::connect(ui->graphicsView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(on_graphView_customContextMenuRequested(const QPoint &)));
2023-04-14 19:30:30 +08:00
ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
m_pGraphicsScene = new QGraphicsScene();
m_pGraphicsScene->setBackgroundBrush(Qt::transparent); // 设置场景背景透明
2024-09-11 16:37:00 +08:00
m_pGraphicsScene->setSceneRect(0, 0, 600, 550);
2023-04-14 19:30:30 +08:00
ui->graphicsView->setScene(m_pGraphicsScene);
ui->graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
ui->graphicsView->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->graphicsView->setRenderHint(QPainter::Antialiasing, true); // 启用视图抗锯齿
ui->graphicsView->setBackgroundBrush(Qt::gray); // 设置视图背景为灰色
ui->graphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
2023-04-14 19:30:30 +08:00
ui->graphicsView_2->setContextMenuPolicy(Qt::CustomContextMenu);
2024-09-11 16:37:00 +08:00
QObject::connect(ui->graphicsView_2, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(on_graphView_customContextMenuRequested(const QPoint &)));
2023-04-14 19:30:30 +08:00
ui->graphicsView_2->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
m_pGraphicsScene_2 = new QGraphicsScene();
2024-09-11 16:37:00 +08:00
m_pGraphicsScene_2->setSceneRect(0, 0, 600, 550);
2023-04-14 19:30:30 +08:00
ui->graphicsView_2->setScene(m_pGraphicsScene_2);
ui->graphicsView_2->setDragMode(QGraphicsView::RubberBandDrag);
ui->tabWidget->setTabPosition(QTabWidget::South);
ui->tabWidget->setTabShape(QTabWidget::Triangular);
//绑定HTTP消息响应
2024-09-11 16:37:00 +08:00
connect(g_NetMgr, SIGNAL(sigNetMgr(QString, const QVariant &)), this, SLOT(slotNetMgr(QString, const QVariant &)));
2023-04-14 19:30:30 +08:00
m_pSocket = new QTcpSocket(this);
2023-04-27 19:48:15 +08:00
m_EditMode = 0;
2023-10-19 14:15:31 +08:00
m_MachineStatus = 1;
//读取ini
2024-09-11 16:37:00 +08:00
#ifdef Q_OS_WIN32
QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini", QSettings::IniFormat);
#endif
#ifdef Q_OS_LINUX
QSettings settingsread(QCoreApplication::applicationDirPath() + "/config/config.ini", QSettings::IniFormat);
#endif
m_RealtimeLog = settingsread.value("Log/realtime").toInt();
2023-04-27 19:48:15 +08:00
LoadGraphicsConfig(0);
2023-04-14 19:30:30 +08:00
InitChannelInfo();
2023-04-27 19:48:15 +08:00
//m_strServerIp = IP;
2023-04-14 19:30:30 +08:00
m_nServerPort = 7305;
m_pSocket = new QTcpSocket(this);
// /*下面是几种常用的信号更多的信号可以查看QAbstractSocket和QIODevice文档*/
// connect(m_pSocket, &QTcpSocket::connected, this, [] () {
// qDebug() << "socket已连接";
// });
// connect(m_pSocket, &QTcpSocket::disconnected, this, [] () {
// qDebug() << "socket已断开连接";
// });
// connect(m_pSocket, &QTcpSocket::stateChanged, this, [] (QAbstractSocket::SocketState socketState) {
// qDebug() << "socket状态改变" << socketState;
// });
// connect(m_pSocket, &QTcpSocket::readyRead, this, [] () {
// qDebug() << "有数据可读";
// });
2024-09-11 16:37:00 +08:00
//connect(m_pSocket, SIGNAL(readyRead()), this, SLOT(slotRecieve()));
connect(m_pSocket, &QTcpSocket::readyRead, this, &CRealTimeForm::slotRecieve);
connect(m_pSocket, &QTcpSocket::disconnected, this, &CRealTimeForm::disConnect);
2024-07-04 15:23:26 +08:00
//#ifdef QT_NO_DEBUG
2023-10-19 14:15:31 +08:00
id1 = startTimer(2000); //参数1 间隔 单位 毫秒
2023-04-14 19:30:30 +08:00
//定时器第二种方式
2024-09-11 16:37:00 +08:00
QTimer *timer = new QTimer(this);
2023-04-14 19:30:30 +08:00
//启动定时器
timer->start(500);
2024-07-04 15:23:26 +08:00
//#endif
2024-09-11 16:37:00 +08:00
// MyGraphicsView *view = new MyGraphicsView(m_pGraphicsScene, this);
// QVBoxLayout *layout = new QVBoxLayout(ui->tab);
// layout->setContentsMargins(0, 0, 0, 0); // 去除边距
// layout->addWidget(view);
// setLayout(layout);
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
CRealTimeForm::~CRealTimeForm() {
2023-04-14 19:30:30 +08:00
delete ui;
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::timerEvent(QTimerEvent *ev) {
if (ev->timerId() == id1) {
2023-04-14 19:30:30 +08:00
QJsonObject allObj;
allObj.insert("cmd", "09");
// 设置IP和端口号连接
2023-04-27 19:48:15 +08:00
m_pSocket->connectToHost(IP, m_nServerPort);
2023-04-14 19:30:30 +08:00
// 设置超时连接时间
m_bConnected = m_pSocket->waitForConnected(1 * 1000);
// QNetworkRequest req;
// QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
// req.setUrl(sUrl);
// g_NetMgr->PostJson(req,allObj);
QJsonDocument doc(allObj);
QString strData = QString(doc.toJson(QJsonDocument::Indented));
int nRet = m_pSocket->write(strData.toStdString().c_str(), strlen(strData.toStdString().c_str()));
2024-09-11 16:37:00 +08:00
if (nRet != 0) {
2023-10-19 14:15:31 +08:00
//qDebug() << "09 通信失败" << endl;
//customLogMessageHandler(QtWarningMsg,"09通信失败");
2023-04-27 19:48:15 +08:00
}
2023-04-14 19:30:30 +08:00
}
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::InitChannelInfo() {
2023-04-14 19:30:30 +08:00
g_channelSetting = g_SqliteDB->GetDataMultiLine("t_ChannelSetting");
2023-10-19 14:15:31 +08:00
g_ChannelBaseInfo.clear();
QVector<channelBaseInfo>().swap(g_ChannelBaseInfo);
2024-09-11 16:37:00 +08:00
for (int i = 0; i < g_channelSetting.size(); i++) {
QMap<QString, QString> mapChannelType;
mapChannelType.insert(g_channelSetting[i].sensorType, g_channelSetting[i].channelName);
g_MapChannel.insert(g_channelSetting[i].channelId, mapChannelType);
2023-04-14 19:30:30 +08:00
channelBaseInfo tempchannelbaseinfo;
tempchannelbaseinfo.bordNo = g_channelSetting[i].sensorModuleNo;
tempchannelbaseinfo.channelID = g_channelSetting[i].channelId;
tempchannelbaseinfo.channelNoInBoard = g_channelSetting[i].sensorNo;
tempchannelbaseinfo.channelName = g_channelSetting[i].channelName;
tempchannelbaseinfo.channelType = g_channelSetting[i].sensorType;
tempchannelbaseinfo.boardType = g_channelSetting[i].boardType;
tempchannelbaseinfo.sensorEngineeringUnit = g_channelSetting[i].sensorEngineeringUnit;
tempchannelbaseinfo.defaultDisplay = g_channelSetting[i].defaultDisplay;
2023-10-19 14:15:31 +08:00
tempchannelbaseinfo.pairChannelId = g_channelSetting[i].pairChannelId;
tempchannelbaseinfo.speedRefChannelId = g_channelSetting[i].speedRefChannelId;
tempchannelbaseinfo.isEnable = g_channelSetting[i].isEnable;
tempchannelbaseinfo.ChUnitDot = g_channelSetting[i].ChUnitDot;
2023-04-14 19:30:30 +08:00
g_ChannelBaseInfo.append(tempchannelbaseinfo);
}
2024-09-11 16:37:00 +08:00
qDebug() << "InitChannelInfo" << g_ChannelBaseInfo.size() << endl;
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::on_graphView_customContextMenuRequested(const QPoint &pos) {
qDebug() << " custom menu!!!!!!!!!" << "##" << pos.x() << " ; " << pos.y();
// if(ui->graphicsView->itemAt(pos) || ui->graphicsView_2->itemAt(pos))
// return;
2023-04-14 19:30:30 +08:00
QMenu menu(this);
2023-04-17 17:40:26 +08:00
pActionVerticalLine = menu.addAction("添加竖线");
pActionHorizontalLine = menu.addAction("添加横线");
pActionRect = menu.addAction("添加通道");
2023-10-19 14:15:31 +08:00
pActionRect2 = menu.addAction("矩形框");
2023-04-17 17:40:26 +08:00
pActionPixmap = menu.addAction("添加图片");
pActionText = menu.addAction("添加文字");
pActionAlignmentX = menu.addAction("水平分布");
pActionAlignmentY = menu.addAction("垂直分布");
2023-04-27 19:48:15 +08:00
pActionEdit = menu.addAction("编辑");
2023-04-17 17:40:26 +08:00
pActionSave = menu.addAction("保存");
2023-04-14 19:30:30 +08:00
pActionVerticalLine->setData(1);
pActionHorizontalLine->setData(2);
pActionRect->setData(3);
pActionPixmap->setData(4);
pActionText->setData(5);
pActionSave->setData(6);
2023-04-27 19:48:15 +08:00
pActionEdit->setData(7);
2023-10-19 14:15:31 +08:00
pActionRect2->setData(8);
pActionAlignmentX->setData(9);
pActionAlignmentY->setData(10);
2023-04-14 19:30:30 +08:00
connect(pActionVerticalLine, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionHorizontalLine, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionRect, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionPixmap, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionText, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionSave, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
2023-04-27 19:48:15 +08:00
connect(pActionEdit, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
2023-10-19 14:15:31 +08:00
connect(pActionRect2, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionAlignmentX, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
connect(pActionAlignmentY, SIGNAL(triggered()), this, SLOT(onTaskBoxContextMenuEvent()));
2023-04-14 19:30:30 +08:00
menu.exec(QCursor::pos());
//menu.exec(ui->graphicsView->mapToGlobal(pos));
// if(pActionLine == menu.exec(ui->graphicsView->mapToGlobal(pos))){
// qDebug() << " Line!!!!!!!!!"<< "##"<< pos.x() << " ; "<< pos.y();
// SetCurDrawType("Line",pos);
// }else if(pActionRect == menu.exec(ui->graphicsView->mapToGlobal(pos))){
// qDebug() << " Rect!!!!!!!!!"<< "##"<< pos.x() << " ; "<< pos.y();
// SetCurDrawType("Rect",pos);
// }
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::onTaskBoxContextMenuEvent() {
2023-04-14 19:30:30 +08:00
QAction *pEven = qobject_cast<QAction *>(this->sender());
int iType = pEven->data().toInt();
2024-09-11 16:37:00 +08:00
switch (iType) {
2023-04-14 19:30:30 +08:00
case 1:
2024-09-11 16:37:00 +08:00
SetCurDrawType("vertical");
break;
2023-04-14 19:30:30 +08:00
case 2:
SetCurDrawType("Horizonta");
2024-09-11 16:37:00 +08:00
break;
2023-04-14 19:30:30 +08:00
case 3:
2024-09-11 16:37:00 +08:00
SetCurDrawType("Channel");
break;
2023-04-14 19:30:30 +08:00
case 4:
2024-09-11 16:37:00 +08:00
SetCurDrawType("Pixmap");
break;
2023-04-14 19:30:30 +08:00
case 5:
SetCurDrawType("Text");
break;
case 6:
2024-09-11 16:37:00 +08:00
SetCurDrawType("Save");
break;
2023-04-27 19:48:15 +08:00
case 7:
SetEdit();
2024-09-11 16:37:00 +08:00
break;
2023-10-19 14:15:31 +08:00
case 8:
SetCurDrawType("Rect");
2024-09-11 16:37:00 +08:00
break;
case 9:
SetAlignmentX();
2024-09-11 16:37:00 +08:00
break;
case 10:
SetAlignmentY();
2024-09-11 16:37:00 +08:00
break;
2023-04-14 19:30:30 +08:00
}
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::SetEdit() {
2023-04-27 19:48:15 +08:00
m_EditMode = 1;
LoadGraphicsConfig(1);
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::SetAlignmentX() {
if (!m_EditMode) {
QMessageBox::information(this, QStringLiteral("提示"), "请先进入编辑模式!");
return;
}
2024-09-11 16:37:00 +08:00
QMap<QGraphicsItem *, float> channleAxisX;
QList<QGraphicsItem *> items;
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
items = m_pGraphicsScene->items();
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
items = m_pGraphicsScene_2->items();
}
foreach (QGraphicsItem *item, items) {
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
int itemType = graphicsItem->type();
if (itemType == 10) {
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
qDebug() << "itemType" << graphicsItem->data(0) << graphicsItem->isSelected() << endl;
2024-09-11 16:37:00 +08:00
if (graphicsItem->isSelected()) {
channleAxisX.insert(graphicsItem, graphicsItem->x());
}
}
}
QList<float> list = channleAxisX.values();
qSort(list);
float minValue = list.first();
qDebug() << "minValue" << minValue << endl;
2024-09-11 16:37:00 +08:00
QMap<QGraphicsItem *, float>::iterator iter = channleAxisX.begin();
for (; iter != channleAxisX.end(); iter++) {
2024-09-11 16:37:00 +08:00
iter.key()->setPos(minValue, iter.key()->y());
}
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::SetAlignmentY() {
if (!m_EditMode) {
QMessageBox::information(this, QStringLiteral("提示"), "请先进入编辑模式!");
return;
}
2024-09-11 16:37:00 +08:00
QMap<QGraphicsItem *, float> channleAxisY;
QList<QGraphicsItem *> items;
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
items = m_pGraphicsScene->items();
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
items = m_pGraphicsScene_2->items();
}
foreach (QGraphicsItem *item, items) {
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
int itemType = graphicsItem->type();
if (itemType == 10) {
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
if (graphicsItem->isSelected()) {
channleAxisY.insert(graphicsItem, graphicsItem->y());
}
}
}
2024-09-11 16:37:00 +08:00
qDebug() << "channleAxisY" << channleAxisY << endl;
QList<float> list = channleAxisY.values();
qSort(list);
float minValue = list.first();
2024-09-11 16:37:00 +08:00
qDebug() << "minValue" << minValue << list.size() << endl;
QMap<QGraphicsItem *, float>::iterator iter = channleAxisY.begin();
for (int j = 0; j < list.size(); j++) {
for (iter = channleAxisY.begin(); iter != channleAxisY.end(); iter++) {
if (iter.value() == list[j]) {
qDebug() << "iter" << iter.key() << endl;
iter.key()->setPos(iter.key()->x(), list[0] + j * 40);
qDebug() << "iter X" << iter.key()->x() << "Y" << list[0] + j * 40 << endl;
}
}
}
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::on_addchannel(channelBaseInfo channelbaseInfo, QString str) {
2023-04-14 19:30:30 +08:00
QPen pen; // 定义一个画笔,设置画笔颜色和宽度
2024-09-11 16:37:00 +08:00
pen.setColor(QColor(0, 0, 0, 0));
2023-04-14 19:30:30 +08:00
pen.setWidth(1);
RoundedGraphicsItemGroup *pItemGroup = new RoundedGraphicsItemGroup();
pItemGroup->setCornerRadius(15); // 设置圆角半径
2024-09-11 16:37:00 +08:00
QGraphicsRectItem *pRect = new QGraphicsRectItem(0, 0, 290, 30);
2023-04-14 19:30:30 +08:00
pRect->setPen(pen);
2023-10-19 14:15:31 +08:00
pRect->setPos(0, 0);
2024-09-11 16:37:00 +08:00
pRect->setData(1, "Rect");
2023-04-14 19:30:30 +08:00
pItemGroup->addToGroup(pRect);
pItemGroup->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2024-09-11 16:37:00 +08:00
QGraphicsTextItem *pTextUnits = NULL;
if (channelbaseInfo.channelType == "TACHOMETER") {
if (str == "偏置电压" || str == "最大正向峰值" || str == "最大负向峰值" || str == "平均值") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem("V");
2024-09-11 16:37:00 +08:00
} else {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem("RPM");
}
2024-09-11 16:37:00 +08:00
} else if (channelbaseInfo.channelType == "ACCELEROMETER") {
if (str == "偏置电压") {
2023-04-14 19:30:30 +08:00
pTextUnits = new QGraphicsTextItem("V");
2024-09-11 16:37:00 +08:00
} else if (str == "最大正向峰值" || str == "最大负向峰值" ||
str == "诊断峰峰值" || str == "平均值") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2024-09-11 16:37:00 +08:00
} else if (str == "速度峰值" || str == "速度有效值") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem("mm/s");
2024-09-11 16:37:00 +08:00
} else {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
} else if (channelbaseInfo.channelType == "PROXIMETER") {
if (str == "平均值") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2024-09-11 16:37:00 +08:00
} else if (str == "最大正向峰值" || str == "最大负向峰值" ||
str == "诊断峰峰值") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2024-09-11 16:37:00 +08:00
} else {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
} else if (channelbaseInfo.channelType == "THRUST") {
if (str == "平均值") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2024-09-11 16:37:00 +08:00
} else if (str == "偏置电压") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem("V");
2024-09-11 16:37:00 +08:00
} else {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
} else if (channelbaseInfo.channelType == "VELOCITY") {
if (str == "偏置电压") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem("V");
2024-09-11 16:37:00 +08:00
} else if (str == "有效值") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2024-09-11 16:37:00 +08:00
} else if (str == "位移峰值" || str == "位移有效值" || str == "诊断峰峰值") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem("um");
2024-09-11 16:37:00 +08:00
} else {
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
} else if (channelbaseInfo.channelType == "SLOW_CURRENT") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2024-09-11 16:37:00 +08:00
} else if (channelbaseInfo.channelType == "FAST_VOLTAGE") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
2024-09-11 16:37:00 +08:00
} else if (channelbaseInfo.channelType == "PULSE_CURRENT") {
pTextUnits = new QGraphicsTextItem(channelbaseInfo.sensorEngineeringUnit);
}
if (str == "峰值因子") {
2023-10-19 14:15:31 +08:00
pTextUnits = new QGraphicsTextItem("");
}
2024-09-11 16:37:00 +08:00
QGraphicsTextItem *pTextChannel = new QGraphicsTextItem(channelbaseInfo.channelName);
QGraphicsTextItem *pTextValue = new QGraphicsTextItem("0.0");
pTextUnits->setData(1, "units");
pTextChannel->setData(2, "channel");
pTextValue->setData(3, "value");
pTextValue->setData(4, str); //特征值
2023-04-14 19:30:30 +08:00
QFont font;
2024-03-14 09:35:39 +08:00
font.setPixelSize(16);
2024-09-11 16:37:00 +08:00
QFont font2("黑体", 18, 50);
2023-04-14 19:30:30 +08:00
font.setFamily(QStringLiteral("黑体"));
pTextUnits->setFont(font);
pTextUnits->setDefaultTextColor(QColor(27, 30, 35));
pTextChannel->setFont(font);
pTextValue->setFont(font2);
2024-09-11 16:37:00 +08:00
pTextValue->setPos(160, -2);
2023-04-14 19:30:30 +08:00
pTextValue->setDefaultTextColor(QColor(31, 81, 136));
pTextChannel->setPos(0, 5);
2023-04-14 19:30:30 +08:00
pTextChannel->setDefaultTextColor(QColor(27, 30, 35));
2024-09-11 16:37:00 +08:00
pTextUnits->setPos(240, 5);
2023-04-14 19:30:30 +08:00
// 设置可移动、可选择
pItemGroup->addToGroup(pTextChannel);
pItemGroup->addToGroup(pTextValue);
pItemGroup->addToGroup(pTextUnits);
2024-09-11 16:37:00 +08:00
pItemGroup->setData(0, channelbaseInfo.channelID);
if (ui->tabWidget->currentIndex() == 0) {
2023-04-14 19:30:30 +08:00
m_pGraphicsScene->addItem(pItemGroup);
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
2023-04-14 19:30:30 +08:00
m_pGraphicsScene_2->addItem(pItemGroup);
}
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::SetCurDrawType(QString strType) {
if (!m_EditMode) {
2023-04-27 19:48:15 +08:00
QMessageBox::information(this, QStringLiteral("提示"), "请先进入编辑模式!");
return;
}
2024-09-11 16:37:00 +08:00
if (strType == "vertical") {
QGraphicsLineItem *pLine = new QGraphicsLineItem(0, 0, 100, 100);
2023-10-19 14:15:31 +08:00
pLine->setPos(0, 0);
2023-04-14 19:30:30 +08:00
pLine->setRotation(45);
pLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2023-10-19 14:15:31 +08:00
pLine->setZValue(100);
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
2023-04-14 19:30:30 +08:00
m_pGraphicsScene->addItem(pLine);
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
2023-04-14 19:30:30 +08:00
m_pGraphicsScene_2->addItem(pLine);
}
2024-09-11 16:37:00 +08:00
} else if (strType == "Horizonta") {
QGraphicsLineItem *pLine = new QGraphicsLineItem(0, 0, 100, 100);
2023-10-19 14:15:31 +08:00
pLine->setPos(0, 0);
2023-04-14 19:30:30 +08:00
pLine->setRotation(-45);
pLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2023-10-19 14:15:31 +08:00
pLine->setZValue(100);
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
2023-04-14 19:30:30 +08:00
m_pGraphicsScene->addItem(pLine);
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
2023-04-14 19:30:30 +08:00
m_pGraphicsScene_2->addItem(pLine);
}
2024-09-11 16:37:00 +08:00
} else if (strType == "Channel") {
2023-04-14 19:30:30 +08:00
CAddChannel *pAddChannel = new CAddChannel();
pAddChannel->setWindowModality(Qt::ApplicationModal);
pAddChannel->show();
2024-09-11 16:37:00 +08:00
connect(pAddChannel, SIGNAL(addChannel_sg(channelBaseInfo, QString)), this, SLOT(on_addchannel(channelBaseInfo, QString)));
} else if (strType == "Pixmap") {
#ifdef Q_OS_WIN32
2023-04-27 19:48:15 +08:00
QString name = QCoreApplication::applicationDirPath() + "\\config\\UnitParameters.json";
2024-09-11 16:37:00 +08:00
#endif
#ifdef Q_OS_LINUX
QString name = QCoreApplication::applicationDirPath() + "/config/UnitParameters.json";
#endif
2023-04-27 19:48:15 +08:00
QFile loadFile(name);
2024-09-11 16:37:00 +08:00
if (!loadFile.open(QIODevice::ReadOnly)) {
qDebug() << "could't open projects json";
return;
2023-04-27 19:48:15 +08:00
}
QString value = loadFile.readAll();
loadFile.close();
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
QMessageBox::about(NULL, "提示", "读取文件错误!");
return;
}
QJsonObject jsonObject = document.object();
if (jsonObject.contains(QStringLiteral("UnitStyle"))) {
QJsonValue jsonValue = jsonObject.value(QStringLiteral("UnitStyle"));
QString strContent = jsonValue["content"].toString();
2024-09-11 16:37:00 +08:00
QGraphicsPixmapItem *pPixmap = NULL;
if (strContent == "混流式机组") {
2023-04-27 19:48:15 +08:00
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/hunliushi.png"));
2024-09-11 16:37:00 +08:00
} else if (strContent == "轴流定桨式机组" || strContent == "轴流转浆式机组") {
2023-04-27 19:48:15 +08:00
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/zhouliushi.png"));
2024-09-11 16:37:00 +08:00
} else if (strContent == "可逆式机组") {
2023-04-27 19:48:15 +08:00
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/kenishi.png"));
2024-09-11 16:37:00 +08:00
} else if (strContent == "灯泡式机组") {
2023-04-27 19:48:15 +08:00
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/dengpaoshi.png"));
}
// 设置可移动、可选择
pPixmap->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
2023-04-27 19:48:15 +08:00
m_pGraphicsScene->addItem(pPixmap);
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
2023-04-27 19:48:15 +08:00
m_pGraphicsScene_2->addItem(pPixmap);
}
2024-09-11 16:37:00 +08:00
pPixmap->setPos(0, 0);
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
} else if (strType == "Text") {
QGraphicsTextItem *pText = new QGraphicsTextItem("请输入...");
2023-04-14 19:30:30 +08:00
// 设置可移动、可选择
pText->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pText->setTextInteractionFlags(Qt::TextEditorInteraction);
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
2023-04-14 19:30:30 +08:00
m_pGraphicsScene->addItem(pText);
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
2023-04-14 19:30:30 +08:00
m_pGraphicsScene_2->addItem(pText);
}
2024-09-11 16:37:00 +08:00
pText->setPos(0, 0);
} else if (strType == "Save") {
2023-04-14 19:30:30 +08:00
SaveGraphicsConfig();
2024-09-11 16:37:00 +08:00
if (m_MachineStatus == 0) {
2023-10-19 14:15:31 +08:00
LoadGraphicsConfig(2);
2024-09-11 16:37:00 +08:00
} else if (m_MachineStatus == 1) {
2023-10-19 14:15:31 +08:00
LoadGraphicsConfig(0);
}
2024-09-11 16:37:00 +08:00
} else if (strType == "Rect") {
2023-10-19 14:15:31 +08:00
CustomRectItem *m_rect = new CustomRectItem();
m_rect->setPos(50, 50);
m_pGraphicsScene->addItem(m_rect);
m_rect->setRect(0, 0, 50, 50);
m_rect->setTransformOriginPoint(25, 25);
m_rect->setRotation(45);
2023-04-14 19:30:30 +08:00
}
ui->graphicsView->update();
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::SaveGraphicsConfig() {
2023-04-27 19:48:15 +08:00
m_EditMode = 0;
2023-04-14 19:30:30 +08:00
QJsonObject jsonObject;
QJsonArray RectjsonArray;
QJsonArray LinejsonArray;
QJsonArray PixmapjsonArray;
QJsonArray TextjsonArray;
QJsonArray GroupjsonArray;
QList<QGraphicsItem *> items;
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
2023-04-14 19:30:30 +08:00
items = m_pGraphicsScene->items();
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
2023-04-14 19:30:30 +08:00
items = m_pGraphicsScene_2->items();
}
foreach (QGraphicsItem *item, items) {
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
2023-04-14 19:30:30 +08:00
int itemType = graphicsItem->type();
2023-04-27 19:48:15 +08:00
//qDebug() << "itemType" << itemType << endl;
2023-04-14 19:30:30 +08:00
switch (itemType) {
// case 3: {//Rect
// QPointF pos = graphicsItem->pos();
// QRectF rect = graphicsItem->boundingRect();
// qDebug() << "Rect" << pos << rect;
// QJsonObject RectjsonObject;
// RectjsonObject.insert("x", pos.x());
// RectjsonObject.insert("y", pos.y());
// RectjsonObject.insert("w", rect.width());
// RectjsonObject.insert("h", rect.height());
// RectjsonArray.append(RectjsonObject);
// } break;
case 4://Ellipse
2024-09-11 16:37:00 +08:00
break;
case 6: { //Line
2023-04-14 19:30:30 +08:00
QPointF pos = graphicsItem->pos();
QRectF rect = graphicsItem->boundingRect();
2023-04-27 19:48:15 +08:00
//qDebug() << "Line" << pos << rect;
2023-04-14 19:30:30 +08:00
QJsonObject LinejsonObject;
LinejsonObject.insert("x", pos.x());
LinejsonObject.insert("y", pos.y());
LinejsonObject.insert("w", rect.width());
LinejsonObject.insert("h", rect.height());
LinejsonObject.insert("rotation", graphicsItem->rotation());
LinejsonArray.append(LinejsonObject);
}
break;
2024-09-11 16:37:00 +08:00
case 7: { //Pixmap
2023-04-14 19:30:30 +08:00
QPointF pos = graphicsItem->pos();
QRectF rect = graphicsItem->boundingRect();
2023-04-27 19:48:15 +08:00
//qDebug() << "Pixmap" << pos << rect;
2023-04-14 19:30:30 +08:00
QJsonObject PixmapjsonObject;
PixmapjsonObject.insert("x", pos.x());
PixmapjsonObject.insert("y", pos.y());
PixmapjsonObject.insert("w", rect.width());
PixmapjsonObject.insert("h", rect.height());
PixmapjsonArray.append(PixmapjsonObject);
}
break;
// case 8:{//Text
// QGraphicsTextItem* pGraphicTextItem = static_cast<QGraphicsTextItem *>(graphicsItem);
// QPointF pos = graphicsItem->pos();
// QRectF rect = graphicsItem->boundingRect();
// qDebug() << "Text" << pos << rect;
// qDebug() << pGraphicTextItem->toPlainText();
// QJsonObject TextjsonObject;
// TextjsonObject.insert("x", pos.x());
// TextjsonObject.insert("y", pos.y());
// TextjsonObject.insert("w", rect.width());
// TextjsonObject.insert("h", rect.height());
// TextjsonObject.insert("word", pGraphicTextItem->toPlainText());
// TextjsonArray.append(TextjsonObject);
// }
// break;
2024-09-11 16:37:00 +08:00
case 10: {
QGraphicsItemGroup *pGraphicGroupItem = static_cast<QGraphicsItemGroup *>(graphicsItem);
2023-04-14 19:30:30 +08:00
QPointF pos = pGraphicGroupItem->pos();
QRectF rect = pGraphicGroupItem->boundingRect();
channelBaseInfo temp;
//qDebug() << "Group" << pos << rect;
QString strChannelID = pGraphicGroupItem->data(0).toString();
2023-04-27 19:48:15 +08:00
//qDebug() << "pGraphicGroupItem data" << strChannelID << endl;
2024-09-11 16:37:00 +08:00
QJsonArray GroupRectjsonArray, GroupTextjsonArray;
2023-04-14 19:30:30 +08:00
QJsonObject itemjsonObject;
QList<QGraphicsItem *> items = pGraphicGroupItem->childItems();
foreach (QGraphicsItem *item, items) {
2024-09-11 16:37:00 +08:00
QString itemData, itemData2 = "";
2023-04-14 19:30:30 +08:00
for (int i = 0; i < 5; i++) {
2024-09-11 16:37:00 +08:00
itemData = item->data(i).toString();
if (itemData == "value") {
itemData2 = item->data(i + 1).toString();
//qDebug() << "item va data" << itemData << itemData2 << i << endl;
break;
} else if (itemData == "channel") {
//qDebug() << "item ch data" << itemData << i << endl;
break;
} else if (itemData == "units") {
//qDebug() << "item un data" << itemData << i << endl;
break;
}
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
2023-04-14 19:30:30 +08:00
int itemType = graphicsItem->type();
2023-04-27 19:48:15 +08:00
//qDebug() << "itemData2" << itemData << endl;
2023-04-14 19:30:30 +08:00
switch (itemType) {
case 3: {//Rect
QPointF pos = graphicsItem->pos();
QRectF rect = graphicsItem->boundingRect();
2023-04-27 19:48:15 +08:00
//qDebug() << "group Rect" << pos << rect;
2023-04-14 19:30:30 +08:00
QJsonObject RectjsonObject;
RectjsonObject.insert("x", pos.x());
RectjsonObject.insert("y", pos.y());
RectjsonObject.insert("w", rect.width());
RectjsonObject.insert("h", rect.height());
GroupRectjsonArray.append(RectjsonObject);
2024-09-11 16:37:00 +08:00
}
break;
case 8: { //Text
QGraphicsTextItem *pGraphicTextItem = static_cast<QGraphicsTextItem *>(graphicsItem);
2023-04-14 19:30:30 +08:00
QPointF pos = graphicsItem->pos();
QRectF rect = graphicsItem->boundingRect();
QJsonObject TextjsonObject;
TextjsonObject.insert("x", pos.x());
TextjsonObject.insert("y", pos.y());
TextjsonObject.insert("w", rect.width());
TextjsonObject.insert("h", rect.height());
TextjsonObject.insert("data", itemData);
QColor color = pGraphicTextItem->defaultTextColor();
QRgb mRgb = qRgba(color.red(), color.green(), color.blue(), color.alpha());
2024-09-11 16:37:00 +08:00
TextjsonObject.insert("color", QString::number(mRgb, 16));
if (itemData2 != "") {
2023-04-14 19:30:30 +08:00
TextjsonObject.insert("static", itemData2);
2024-09-11 16:37:00 +08:00
}
if (itemData == "units") {
2023-04-14 19:30:30 +08:00
temp.channelUnit = pGraphicTextItem->toPlainText();
2024-09-11 16:37:00 +08:00
} else if (itemData == "channel") {
2023-04-14 19:30:30 +08:00
temp.channelName = pGraphicTextItem->toPlainText();
2024-09-11 16:37:00 +08:00
}
2023-04-14 19:30:30 +08:00
TextjsonObject.insert("word", pGraphicTextItem->toPlainText());
GroupTextjsonArray.append(TextjsonObject);
2024-09-11 16:37:00 +08:00
}
break;
2023-04-14 19:30:30 +08:00
}
}
2024-09-11 16:37:00 +08:00
itemjsonObject.insert("Rect", GroupRectjsonArray);
itemjsonObject.insert("Text", GroupTextjsonArray);
itemjsonObject.insert("x", pos.x());
itemjsonObject.insert("y", pos.y());
itemjsonObject.insert("data", strChannelID);
2023-04-14 19:30:30 +08:00
GroupjsonArray.append(itemjsonObject);
temp.channelID = strChannelID;
g_ChannelView.append(temp);
2024-09-11 16:37:00 +08:00
}
2023-10-19 14:15:31 +08:00
break;
2024-09-11 16:37:00 +08:00
default:
break;
}
2023-04-14 19:30:30 +08:00
}
jsonObject.insert("Rect", RectjsonArray);
jsonObject.insert("Line", LinejsonArray);
jsonObject.insert("Pixmap", PixmapjsonArray);
jsonObject.insert("Text", TextjsonArray);
jsonObject.insert("Group", GroupjsonArray);
QString fileName;
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
#ifdef Q_OS_WIN32
2023-04-14 19:30:30 +08:00
fileName = QCoreApplication::applicationDirPath() + "\\config\\Graph1.json";
2024-09-11 16:37:00 +08:00
#endif
#ifdef Q_OS_LINUX
fileName = QCoreApplication::applicationDirPath() + "/config/Graph1.json";
#endif
} else {
#ifdef Q_OS_WIN32
2023-04-14 19:30:30 +08:00
fileName = QCoreApplication::applicationDirPath() + "\\config\\Graph2.json";
2024-09-11 16:37:00 +08:00
#endif
#ifdef Q_OS_LINUX
fileName = QCoreApplication::applicationDirPath() + "/config/Graph2.json";
#endif
2023-04-14 19:30:30 +08:00
}
QJsonDocument jsonDoc;
jsonDoc.setObject(jsonObject);
//QString fileName = QFileDialog::getSaveFileName(this,"另存为 ","xxx.json");
//if(!fileName.isEmpty())
{
qDebug() << "另存为" << fileName;
QFile file(fileName);
//if(!file.exists())
{
file.open(QIODevice::WriteOnly);
file.write(jsonDoc.toJson());
file.close();
}
}
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::slotDoubleClick(QGraphicsSceneMouseEvent *event) {
2023-04-14 19:30:30 +08:00
qDebug() << "slotDoubleClick" << event->pos() << endl;
2024-09-11 16:37:00 +08:00
QGraphicsItem *item = m_pGraphicsScene->itemAt(event->scenePos(), QTransform());
QGraphicsItemGroup *pGraphicGroupItem = static_cast<QGraphicsItemGroup *>(item);
2023-04-14 19:30:30 +08:00
qDebug() << "QGraphicsItem" << pGraphicGroupItem->childItems() << endl;
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::LoadGraphicsConfig(int type) {
//读取图元的数据
m_pGraphicsScene->clear();
m_pGraphicsScene_2->clear();
QPen pen; // 定义一个画笔,设置画笔颜色和宽度
pen.setColor(QColor(0, 0, 0, 0));
pen.setWidth(1);
//QString fileName =QFileDialog::getOpenFileName(this,"打开文件",QDir::currentPath(), "*.json");
for (int ii = 0; ii < ui->tabWidget->count(); ii++) {
QString strFileName = QString("Graph%1.json").arg(ii + 1);
#ifdef Q_OS_WIN32
2023-10-19 14:15:31 +08:00
QString fileName = QCoreApplication::applicationDirPath() + "\\config\\" + strFileName;
2024-09-11 16:37:00 +08:00
#endif
#ifdef Q_OS_LINUX
QString fileName = QCoreApplication::applicationDirPath() + "/config/" + strFileName;
#endif
2023-04-27 19:48:15 +08:00
qDebug() << "打开" << fileName ;
2024-09-11 16:37:00 +08:00
if (!fileName.isEmpty()) {
2023-10-19 14:15:31 +08:00
QFile file(fileName);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QString value = file.readAll();
file.close();
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
QMessageBox::about(NULL, "提示", "读取文件错误!");
return;
}
QJsonObject jsonObject = document.object();
// Line字段
if (jsonObject.contains(QStringLiteral("Line"))) {
QJsonValue arrayValue = jsonObject.value(QStringLiteral("Line"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
for (int i = 0; i < array.size(); i++) {
QJsonValue nameArray = array.at(i);
QJsonObject key = nameArray.toObject();
QGraphicsLineItem *pLine = new QGraphicsLineItem(
2024-09-11 16:37:00 +08:00
0,
0,
key["w"].toDouble(), key["h"].toDouble());
2023-10-19 14:15:31 +08:00
pLine->setPos(key["x"].toDouble(), key["y"].toDouble());
pLine->setRotation(key["rotation"].toInt());
pLine->setZValue(100);
2024-09-11 16:37:00 +08:00
if (type) {
pLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
}
if (ii == 0) {
m_pGraphicsScene->addItem(pLine);
} else if (ii == 1) {
m_pGraphicsScene_2->addItem(pLine);
2023-04-14 19:30:30 +08:00
}
}
2023-10-19 14:15:31 +08:00
}
}
// Rect字段
if (jsonObject.contains(QStringLiteral("Rect"))) {
QJsonValue arrayValue = jsonObject.value(QStringLiteral("Rect"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
for (int i = 0; i < array.size(); i++) {
QJsonValue nameArray = array.at(i);
QJsonObject key = nameArray.toObject();
QGraphicsRectItem *pRect = new QGraphicsRectItem(
2024-09-11 16:37:00 +08:00
0,
0,
key["w"].toDouble(), key["h"].toDouble());
2023-10-19 14:15:31 +08:00
pRect->setPos(key["x"].toDouble(), key["y"].toDouble());
2024-09-11 16:37:00 +08:00
if (type) {
pRect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
}
if (ii == 0) {
m_pGraphicsScene->addItem(pRect);
} else if (ii == 1) {
m_pGraphicsScene_2->addItem(pRect);
2023-04-14 19:30:30 +08:00
}
}
2023-10-19 14:15:31 +08:00
}
}
// Pixmap字段
if (jsonObject.contains(QStringLiteral("Pixmap"))) {
QJsonValue arrayValue = jsonObject.value(QStringLiteral("Pixmap"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
for (int i = 0; i < array.size(); i++) {
QJsonValue nameArray = array.at(i);
QJsonObject key = nameArray.toObject();
2024-09-11 16:37:00 +08:00
#ifdef Q_OS_LINUX
QString name = QCoreApplication::applicationDirPath() + "/config/UnitParameters.json";
#endif
#ifdef Q_OS_WIN32
2023-10-19 14:15:31 +08:00
QString name = QCoreApplication::applicationDirPath() + "\\config\\UnitParameters.json";
2024-09-11 16:37:00 +08:00
#endif
2023-10-19 14:15:31 +08:00
QFile loadFile(name);
2024-09-11 16:37:00 +08:00
if (!loadFile.open(QIODevice::ReadOnly)) {
qDebug() << "could't open projects json";
return;
2023-10-19 14:15:31 +08:00
}
QString value = loadFile.readAll();
loadFile.close();
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
QMessageBox::about(NULL, "提示", "读取文件错误!");
return;
}
QJsonObject jsonObject = document.object();
if (jsonObject.contains(QStringLiteral("UnitStyle"))) {
QJsonValue jsonValue = jsonObject.value(QStringLiteral("UnitStyle"));
QString strContent = jsonValue["content"].toString();
2024-09-11 16:37:00 +08:00
QGraphicsPixmapItem *pPixmap = NULL;
2023-10-19 14:15:31 +08:00
QLabel *gif_anim = new QLabel();
QMovie *movie = NULL;
qDebug() << "strContent" << strContent << endl;
2024-09-11 16:37:00 +08:00
if (strContent == "混流式机组") {
if (type == 1 || type == 2) {
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/hunliushi.png"));
} else {
movie = new QMovie(QCoreApplication::applicationDirPath() + "/image/unit/hunliushi.gif");
}
} else if (strContent == "轴流定桨式机组" || strContent == "轴流转浆式机组") {
if (type == 1 || type == 2) {
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/zhouliushi.png"));
} else {
movie = new QMovie(QCoreApplication::applicationDirPath() + "/image/unit/zhouliushi.gif");
}
2023-10-19 14:15:31 +08:00
//pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/zhouliushi.png"));
2024-09-11 16:37:00 +08:00
} else if (strContent == "可逆式机组") {
if (type == 1 || type == 2) {
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/kenishi.png"));
} else {
movie = new QMovie(QCoreApplication::applicationDirPath() + "/image/unit/kenishi.gif");
}
2023-10-19 14:15:31 +08:00
//pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/kenishi.png"));
2024-09-11 16:37:00 +08:00
} else if (strContent == "灯泡式机组") {
if (type == 1 || type == 2) {
pPixmap = new QGraphicsPixmapItem(QPixmap(QCoreApplication::applicationDirPath() + "/image/unit/dengpaoshi.png"));
} else {
movie = new QMovie(QCoreApplication::applicationDirPath() + "/image/unit/dengpaoshi.gif");
}
2023-10-19 14:15:31 +08:00
}
qDebug() << "type" << type << ii << endl;
2024-09-11 16:37:00 +08:00
if (type) {
pPixmap->setPos(key["x"].toInt(), key["y"].toInt());
// 设置可移动、可选择
if (type == 1) {
2023-10-19 14:15:31 +08:00
pPixmap->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2024-09-11 16:37:00 +08:00
}
if (ii == 0) {
m_pGraphicsScene->addItem(pPixmap);
} else if (ii == 1) {
m_pGraphicsScene_2->addItem(pPixmap);
}
} else {
gif_anim->setMovie(movie);
movie->start();
QGraphicsProxyWidget *proxy = NULL;
if (ii == 0) {
qDebug() << "strContent111" << strContent << endl;
proxy = m_pGraphicsScene->addWidget(gif_anim);
} else if (ii == 1) {
proxy = m_pGraphicsScene_2->addWidget(gif_anim);
}
proxy->setGeometry(QRectF(key["x"].toInt(), key["y"].toInt(), 0, 0));
2023-10-19 14:15:31 +08:00
}
}
// QGraphicsPixmapItem *pPixmap = new QGraphicsPixmapItem(QPixmap(":/image/1.png"));
// pPixmap->setPos(key["x"].toInt(), key["y"].toInt());
// pPixmap->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
// if(ii == 0){
// m_pGraphicsScene->addItem(pPixmap);
// }else if(ii == 1){
// m_pGraphicsScene_2->addItem(pPixmap);
// }
// QLabel *gif_anim = new QLabel();
// QMovie *movie = new QMovie(":/image/1.gif");
// gif_anim->setMovie(movie);
// movie->start();
// QGraphicsProxyWidget *proxy = m_pGraphicsScene->addWidget(gif_anim);
// QGraphicsMovieItem *pPixmap = new QGraphicsMovieItem();
// pPixmap->setPos(key["x"].toInt(), key["y"].toInt());
// QMovie movie(":/image/1.png");
// pPixmap->setMovie(&movie);
// movie.start();
// m_pGraphicsScene->addItem(pPixmap);
}
}
}
// Text字段
if (jsonObject.contains(QStringLiteral("Text"))) {
2024-09-11 16:37:00 +08:00
if (type == 1) {
2023-10-19 14:15:31 +08:00
QGraphicsTextItem *pText = new QGraphicsTextItem("正在编辑中...");
pText->setPos(300, 530);
pText->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2024-09-11 16:37:00 +08:00
QFont font("黑体", 20, 50);
2023-10-19 14:15:31 +08:00
font.setPixelSize(30);
pText->setDefaultTextColor(QColor(255, 0, 0));
pText->setFont(font);
2024-09-11 16:37:00 +08:00
if (ii == 0) {
m_pGraphicsScene->addItem(pText);
} else if (ii == 1) {
m_pGraphicsScene_2->addItem(pText);
2023-04-14 19:30:30 +08:00
}
2023-10-19 14:15:31 +08:00
}
QJsonValue arrayValue = jsonObject.value(QStringLiteral("Text"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
for (int i = 0; i < array.size(); i++) {
QJsonValue nameArray = array.at(i);
QJsonObject key = nameArray.toObject();
QGraphicsTextItem *pText = new QGraphicsTextItem(key["word"].toString());
pText->setPos(key["x"].toInt(), key["y"].toInt());
pText->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pText->setTextInteractionFlags(Qt::TextEditorInteraction);
QFont font;
font.setPixelSize(25);
pText->setFont(font);
2024-09-11 16:37:00 +08:00
if (ii == 0) {
m_pGraphicsScene->addItem(pText);
} else if (ii == 1) {
m_pGraphicsScene_2->addItem(pText);
2023-10-19 14:15:31 +08:00
}
}
}
}
// Group字段
if (jsonObject.contains(QStringLiteral("Group"))) {
QJsonValue arrayValue = jsonObject.value(QStringLiteral("Group"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
for (int i = 0; i < array.size(); i++) {
2024-09-11 16:37:00 +08:00
channelBaseInfo temp;
RoundedGraphicsItemGroup *pItemGroup = new RoundedGraphicsItemGroup();
pItemGroup->setCornerRadius(15); // 设置圆角半径
2024-09-11 16:37:00 +08:00
if (type == 1) {
pItemGroup->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pItemGroup->setFlag(QGraphicsItem::ItemIsSelectable, true);
2024-09-11 16:37:00 +08:00
}
//connect(pItemGroup, SIGNAL(doubleclick(QGraphicsSceneMouseEvent *)), this, SLOT(slotDoubleClick(QGraphicsSceneMouseEvent *)));
2024-09-11 16:37:00 +08:00
//qDebug() << array.at(i)["x"].toDouble() << array.at(i)["y"].toDouble() << endl;
QJsonObject jsonObject = array.at(i).toObject();
if (jsonObject.contains(QStringLiteral("Rect"))) {
QJsonValue arrayValue = jsonObject.value(QStringLiteral("Rect"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
for (int i = 0; i < array.size(); i++) {
QJsonValue nameArray = array.at(i);
QJsonObject key = nameArray.toObject();
QGraphicsRectItem *pRect = new QGraphicsRectItem(
0,
0,
290, 30);
pRect->setPos(key["x"].toDouble(), key["y"].toDouble());
if (type == 1) {
pRect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
}
//pRect->setBrush(QBrush(QColor(255, 255, 255)));
2024-09-11 16:37:00 +08:00
pRect->setPen(pen);
pItemGroup->addToGroup(pRect);
}
}
}
if (jsonObject.contains(QStringLiteral("Text"))) {
QJsonValue arrayValue = jsonObject.value(QStringLiteral("Text"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
for (int i = 0; i < array.size(); i++) {
QJsonValue nameArray = array.at(i);
QJsonObject key = nameArray.toObject();
QGraphicsTextItem *pText = new QGraphicsTextItem(key["word"].toString());
pText->setPos(key["x"].toDouble(), key["y"].toDouble());
if (type) {
pText->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
pText->setTextInteractionFlags(Qt::TextEditorInteraction);
}
QFont font;
QFont font2("黑体", 18, 50);
font.setPixelSize(16);
font.setFamily(QStringLiteral("黑体"));
pText->setFont(font);
if (key["data"].toString() == "units") {
pText->setData(1, "units");
pText->setDefaultTextColor(QColor(27, 30, 35));
temp.channelUnit = key["word"].toString();
} else if (key["data"].toString() == "channel") {
pText->setData(2, "channel");
pText->setDefaultTextColor(QColor(27, 30, 35));
temp.channelName = key["word"].toString();
} else if (key["data"].toString() == "value") {
pText->setData(3, "value");
pText->setData(4, key["static"].toString());
pText->setDefaultTextColor(QColor(31, 81, 136));
pText->setFont(font2);
}
pItemGroup->addToGroup(pText);
}
}
}
pItemGroup->setPos(array.at(i)["x"].toDouble(), array.at(i)["y"].toDouble());
pItemGroup->setData(0, array.at(i)["data"].toString());
if (ii == 0) {
m_pGraphicsScene->addItem(pItemGroup);
} else if (ii == 1) {
m_pGraphicsScene_2->addItem(pItemGroup);
}
temp.channelID = array.at(i)["data"].toString();
g_ChannelView.append(temp);
2023-10-19 14:15:31 +08:00
}
}
}
}
2024-09-11 16:37:00 +08:00
}
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::keyPressEvent(QKeyEvent *event) {
//QGraphicsItem::keyPressEvent(event);
qDebug() << "键盘按下";
if (event->key() == Qt::Key_Delete) {
qDebug() << "press Key_Delete";
if (ui->tabWidget->currentIndex() == 0) {
2023-04-14 19:30:30 +08:00
QList<QGraphicsItem *> items = m_pGraphicsScene->items();
foreach (QGraphicsItem *item, items) {
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
if (graphicsItem->isSelected()) {
qDebug() << "delete Item";
m_pGraphicsScene->removeItem(graphicsItem);
2023-04-14 19:30:30 +08:00
}
}
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
QList<QGraphicsItem *> items = m_pGraphicsScene_2->items();
foreach (QGraphicsItem *item, items) {
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
if (graphicsItem->isSelected()) {
2023-04-14 19:30:30 +08:00
qDebug() << "delete Item";
m_pGraphicsScene_2->removeItem(graphicsItem);
2024-09-11 16:37:00 +08:00
}
}
}
return;
}
2023-04-14 19:30:30 +08:00
//
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::UpdateCharacteristic(QVector<_Charateristic> &m_vecCharateristic) {
2023-04-27 19:48:15 +08:00
QString RPM = "0";
2024-09-11 16:37:00 +08:00
if (m_vecCharateristic.size() > 0) {
2023-04-14 19:30:30 +08:00
for (int i = 0; i < m_vecCharateristic.size(); i++) {
QList<QGraphicsItem *> items;
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
2023-04-14 19:30:30 +08:00
items = m_pGraphicsScene->items();
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
2023-04-14 19:30:30 +08:00
items = m_pGraphicsScene_2->items();
}
foreach (QGraphicsItem *item, items) {
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
2023-04-14 19:30:30 +08:00
int itemType = graphicsItem->type();
switch (itemType) {
2024-09-11 16:37:00 +08:00
case 10: {
QGraphicsItemGroup *pGraphicGroupItem = static_cast<QGraphicsItemGroup *>(graphicsItem);
2023-04-14 19:30:30 +08:00
channelBaseInfo temp;
QString strChannelID = pGraphicGroupItem->data(0).toString();
2024-09-11 16:37:00 +08:00
if (strChannelID != m_vecCharateristic[i].ChannelID) {
2023-04-14 19:30:30 +08:00
continue;
2024-09-11 16:37:00 +08:00
}
2023-04-14 19:30:30 +08:00
QJsonObject itemjsonObject;
QList<QGraphicsItem *> items = pGraphicGroupItem->childItems();
2024-09-11 16:37:00 +08:00
QString itemData, itemData2 = "";
foreach (QGraphicsItem *item, items) {
for (int i = 0; i < 5; i++) {
itemData = item->data(i).toString();
if (itemData == "value") {
itemData2 = item->data(i + 1).toString();
//qDebug() << "item va data" << itemData << itemData2 << i << endl;
break;
} else if (itemData == "channel") {
break;
} else if (itemData == "units") {
break;
}
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
2023-04-14 19:30:30 +08:00
int itemType = graphicsItem->type();
switch (itemType) {
2024-09-11 16:37:00 +08:00
case 8: { //Text
QGraphicsTextItem *pGraphicTextItem = static_cast<QGraphicsTextItem *>(graphicsItem);
if (itemData == "value") {
2023-04-14 19:30:30 +08:00
//qDebug() << strChannelID << "itemData" <<itemData << "itemData2" << itemData2 << m_vecCharateristic[i].speedRPM<<endl;
QString str = "";
2024-09-11 16:37:00 +08:00
if (itemData2 == "转速") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].speedRPM, 'f', m_vecCharateristic[i].ChUnitDot));
2023-04-14 19:30:30 +08:00
RPM = str;
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "最大正向峰值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].MaxValues, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "最大负向峰值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].MinValues, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "监测保护峰峰值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].MonitorPk2Pk, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "诊断峰峰值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].DiagnosisPk2Pk, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "速度有效值" || itemData2 == "位移有效值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].IntegratRMS, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "速度峰值" || itemData2 == "位移峰值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].IntegratPk2Pk2, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "加速度峰值因子") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].CrestFactor, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "推导峰值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].DerivedPeak, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "偏置电压") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].DCValues, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "有效值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].RMSValues, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "峰值因子") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].CrestFactor, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "峰值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].DiagnosisPeak, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else if (itemData2 == "平均值") {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].DCValues, 'f', m_vecCharateristic[i].ChUnitDot));
2024-09-11 16:37:00 +08:00
} else {
2023-10-19 14:15:31 +08:00
str = QString("%1").arg(QString::number(m_vecCharateristic[i].DCValues, 'f', m_vecCharateristic[i].ChUnitDot));
}
2024-03-14 09:35:39 +08:00
int flag = -1;
2024-09-11 16:37:00 +08:00
if ((g_mapTriggerEvent[strChannelID].DangerOver == 1 || g_mapTriggerEvent[strChannelID].DangerUnder == 1) \
&& itemData2 == g_mapTriggerEvent[strChannelID].Characteristic) {
if ((str.toFloat() < g_mapTriggerEvent[strChannelID].DangerUnderSetpoint.toFloat() && g_mapTriggerEvent[strChannelID].DangerUnder == 1) ||
(str.toFloat() > g_mapTriggerEvent[strChannelID].DangerOverSetpoint.toFloat() && g_mapTriggerEvent[strChannelID].DangerOver == 1)) {
2024-03-14 09:35:39 +08:00
pGraphicTextItem->setDefaultTextColor(QColor(255, 0, 0));
flag = 1;
2024-09-11 16:37:00 +08:00
} else {
2024-03-14 09:35:39 +08:00
pGraphicTextItem->setDefaultTextColor(QColor(31, 81, 136));
}
}
2024-09-11 16:37:00 +08:00
if ((g_mapTriggerEvent[strChannelID].AlertOver == 1 || g_mapTriggerEvent[strChannelID].AlertUnder == 1) \
&& itemData2 == g_mapTriggerEvent[strChannelID].Characteristic && flag == -1) {
2024-03-14 09:35:39 +08:00
QString strLog = "警报" + str + "," + g_mapTriggerEvent[strChannelID].AlertUnderSetpoint + "," + g_mapTriggerEvent[strChannelID].AlertOverSetpoint;
2024-09-11 16:37:00 +08:00
if ((str.toFloat() < g_mapTriggerEvent[strChannelID].AlertUnderSetpoint.toFloat() && g_mapTriggerEvent[strChannelID].AlertUnder == 1 \
&& g_mapTriggerEvent[strChannelID].DangerUnder == 1 && str.toFloat() > g_mapTriggerEvent[strChannelID].DangerUnderSetpoint.toFloat()) || \
2024-03-14 09:35:39 +08:00
(str.toFloat() > g_mapTriggerEvent[strChannelID].AlertOverSetpoint.toFloat() && g_mapTriggerEvent[strChannelID].AlertOver == 1 \
2024-09-11 16:37:00 +08:00
&& g_mapTriggerEvent[strChannelID].DangerOver == 0) || \
2024-03-14 09:35:39 +08:00
(str.toFloat() > g_mapTriggerEvent[strChannelID].AlertOverSetpoint.toFloat() && g_mapTriggerEvent[strChannelID].AlertOver == 1 \
2024-09-11 16:37:00 +08:00
&& g_mapTriggerEvent[strChannelID].DangerOver == 1 && str.toFloat() < g_mapTriggerEvent[strChannelID].DangerOverSetpoint.toFloat())) {
2024-03-14 09:35:39 +08:00
pGraphicTextItem->setDefaultTextColor(QColor(255, 165, 0));
2024-09-11 16:37:00 +08:00
} else {
2024-03-14 09:35:39 +08:00
pGraphicTextItem->setDefaultTextColor(QColor(31, 81, 136));
}
2023-04-14 19:30:30 +08:00
}
sigRPM(RPM);
pGraphicTextItem->setPlainText(str);
}
2024-09-11 16:37:00 +08:00
}
break;
2023-04-14 19:30:30 +08:00
}
}
2024-09-11 16:37:00 +08:00
}
break;
2023-04-14 19:30:30 +08:00
}
}
}
2024-09-11 16:37:00 +08:00
if (ui->tabWidget->currentIndex() == 0) {
2023-04-14 19:30:30 +08:00
ui->graphicsView->update();
2024-09-11 16:37:00 +08:00
} else if (ui->tabWidget->currentIndex() == 1) {
2023-04-14 19:30:30 +08:00
ui->graphicsView_2->update();
}
}
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::ParseCharacteristic(QJsonArray &arrayValue) {
2023-04-14 19:30:30 +08:00
m_vecCharateristic.clear();
g_Charateristic.clear();
QVector<Charateristic_t>().swap(m_vecCharateristic);
QVector<Charateristic_t>().swap(g_Charateristic);
_Charateristic tempCharateristic;
for (int i = 0; i < arrayValue.size(); i++) {
2024-03-14 09:35:39 +08:00
int enable = arrayValue.at(i)["isEnable"].toDouble();
2024-09-11 16:37:00 +08:00
if (enable == 1) {
2024-03-14 09:35:39 +08:00
tempCharateristic.Amp1x = arrayValue.at(i)["1xAmp"].toDouble();
tempCharateristic.Phase1x = arrayValue.at(i)["1xPhase"].toDouble();
tempCharateristic.ChannelID = arrayValue.at(i)["ChannelId"].toString();
tempCharateristic.ChannelName = arrayValue.at(i)["ChannelName"].toString();
tempCharateristic.CrestFactor = arrayValue.at(i)["CrestFactor"].toDouble();
tempCharateristic.DCValues = arrayValue.at(i)["DCValues"].toDouble();
tempCharateristic.DerivedPeak = arrayValue.at(i)["DerivedPeak"].toDouble();
tempCharateristic.DiagnosisPeak = arrayValue.at(i)["DiagnosisPeak"].toDouble();
tempCharateristic.DiagnosisPk2Pk = arrayValue.at(i)["DiagnosisPk2Pk"].toDouble();
tempCharateristic.DirectPK = arrayValue.at(i)["DirectPK"].toDouble();
tempCharateristic.FullScalePosition = arrayValue.at(i)["FullScalePosition"].toDouble();
tempCharateristic.Gap = arrayValue.at(i)["Gap"].toDouble();
tempCharateristic.IntegratPk2Pk2 = arrayValue.at(i)["IntegratPk2Pk/2"].toDouble();
tempCharateristic.IntegratRMS = arrayValue.at(i)["IntegratRMS"].toDouble();
tempCharateristic.MaxValues = arrayValue.at(i)["MaxValues"].toDouble();
tempCharateristic.MinValues = arrayValue.at(i)["MinValues"].toDouble();
tempCharateristic.MonitorPk2Pk = arrayValue.at(i)["MonitorPk2Pk"].toDouble();
tempCharateristic.Position = arrayValue.at(i)["Position"].toDouble();
tempCharateristic.RmsPkPk2Pk = arrayValue.at(i)["RmsPkPk2Pk"].toDouble();
tempCharateristic.SensorEngineeringUnit = arrayValue.at(i)["SensorEngineeringUnit"].toString();
tempCharateristic.SensorStatus = arrayValue.at(i)["SensorStatus"].toDouble();
tempCharateristic.ZeroScalePosition = arrayValue.at(i)["ZeroScalePosition"].toDouble();
tempCharateristic.xFullScalePosition = arrayValue.at(i)["xFullScalePosition"].toDouble();
tempCharateristic.xProcessVariableName = arrayValue.at(i)["xProcessVariableName"].toString();
tempCharateristic.xZeroScalePosition = arrayValue.at(i)["xZeroScalePosition"].toDouble();
tempCharateristic.RMSValues = arrayValue.at(i)["RMSValues"].toDouble();
tempCharateristic.speedRPM = arrayValue.at(i)["SpeedProfileSpeed"].toDouble();
tempCharateristic.ChUnitDot = arrayValue.at(i)["ChUnitDot"].toInt();
tempCharateristic.channelType = arrayValue.at(i)["ChannelType"].toString();
2024-07-04 15:23:26 +08:00
tempCharateristic.ChUnitDot = arrayValue.at(i)["ChUnitDot"].toInt();
tempCharateristic.channelType = arrayValue.at(i)["ChannelType"].toString();
tempCharateristic.InvertAlarm = arrayValue.at(i)["InvertAlarm"].toDouble();
tempCharateristic.InvertDanger = arrayValue.at(i)["InvertDanger"].toDouble();
2024-03-14 09:35:39 +08:00
m_vecCharateristic.push_back(tempCharateristic);
g_Charateristic.push_back(tempCharateristic);
}
2023-04-14 19:30:30 +08:00
}
UpdateCharacteristic(m_vecCharateristic);
}
// 接受服务返回的数据
2024-09-11 16:37:00 +08:00
void CRealTimeForm::slotRecieve() {
2023-04-14 19:30:30 +08:00
QByteArray arrayReady = m_pSocket->readAll();
m_arrayReady += arrayReady;
2023-04-27 19:48:15 +08:00
// customLogMessageHandler(QtDebugMsg,m_arrayReady);
// qDebug() << "arrayReady" << arrayReady << endl;
// QJsonDocument doc = QJsonDocument::fromJson(arrayReady);
// QJsonObject objec = doc.object();
// if(objec.contains("cmd"))
// {
// QJsonValue arrays_value = objec.take("cmd");
// qDebug()<<"cmd ="<<arrays_value.toString();
// if(arrays_value.toString() == "09"){
// QJsonArray arrayValue = objec["content"].toArray();
// QJsonArray arrayValueDIs = objec["DIO_Board_DIs"].toArray();
// QJsonArray arrayValueDOs = objec["DIO_Board_DOs"].toArray();
// ParseCharacteristic(arrayValue);
// QString strTrgStatus = objec["currentTriggerStatus"].toString();
// QString strWCStatus = objec["currentWorkCondition"].toString();
// QString str = strTrgStatus + "," + strWCStatus;
// sigWCStatus(str);
// sigDOStatus(arrayValueDIs,arrayValueDOs);
// }
// }
2023-04-14 19:30:30 +08:00
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::disConnect() {
2023-04-14 19:30:30 +08:00
QJsonDocument doc = QJsonDocument::fromJson(m_arrayReady);
QJsonObject objec = doc.object();
2024-09-11 16:37:00 +08:00
if (m_RealtimeLog == 1) {
customLogMessageHandler(QtDebugMsg, QString(QJsonDocument(objec).toJson()));
}
if (objec.contains("cmd")) {
2023-04-14 19:30:30 +08:00
QJsonValue arrays_value = objec.take("cmd");
2023-10-19 14:15:31 +08:00
//qDebug()<<"cmd ="<<arrays_value.toString();
2024-09-11 16:37:00 +08:00
if (arrays_value.toString() == "09") {
2023-10-19 14:15:31 +08:00
//qDebug()<<"cmd ="<<arrays_value.toString();
2023-04-14 19:30:30 +08:00
QJsonArray arrayValue = objec["content"].toArray();
QJsonArray arrayValueDIs = objec["DIO_Board_DIs"].toArray();
QJsonArray arrayValueDOs = objec["DIO_Board_DOs"].toArray();
ParseCharacteristic(arrayValue);
QString strTrgStatus = objec["currentTriggerStatus"].toString();
QString strWCStatus = objec["currentWorkCondition"].toString();
2023-10-19 14:15:31 +08:00
QString strinvalid_ch = objec["invalid_ch_num"].toString();
QString str = strTrgStatus + "," + strWCStatus + "," + strinvalid_ch;
2023-04-14 19:30:30 +08:00
sigWCStatus(str);
2024-09-11 16:37:00 +08:00
sigDOStatus(arrayValueDIs, arrayValueDOs);
if (strWCStatus.contains("停机")) {
if (m_MachineStatus == 1) {
2023-10-19 14:15:31 +08:00
LoadGraphicsConfig(2);
}
m_MachineStatus = 0;
2024-09-11 16:37:00 +08:00
} else {
if (m_MachineStatus == 0) {
2023-10-19 14:15:31 +08:00
LoadGraphicsConfig(0);
}
m_MachineStatus = 1;
}
2023-04-14 19:30:30 +08:00
}
}
m_arrayReady = "";
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::slotNetMgr(QString sAddr, const QVariant &msg) {
2023-04-14 19:30:30 +08:00
QJsonObject objec = msg.value<QJsonObject>();
2024-09-11 16:37:00 +08:00
if (objec.contains("cmd")) {
2023-04-14 19:30:30 +08:00
QJsonValue arrays_value = objec.take("cmd");
//qDebug()<<"cmd ="<<arrays_value.toString();
2024-09-11 16:37:00 +08:00
if (arrays_value.toString() == "09") {
2023-04-14 19:30:30 +08:00
QJsonArray arrayValue = objec["content"].toArray();
QJsonArray arrayValueDIs = objec["DIO_Board_DIs"].toArray();
QJsonArray arrayValueDOs = objec["DIO_Board_DOs"].toArray();
ParseCharacteristic(arrayValue);
QString strTrgStatus = objec["currentTriggerStatus"].toString();
QString strWCStatus = objec["currentWorkCondition"].toString();
QString str = strTrgStatus + "," + strWCStatus;
sigWCStatus(str);
2024-09-11 16:37:00 +08:00
sigDOStatus(arrayValueDIs, arrayValueDOs);
2023-04-14 19:30:30 +08:00
}
}
}
2024-09-11 16:37:00 +08:00
void CRealTimeForm::mouseDoubleClickEvent(QMouseEvent *e) {
QGraphicsItem *currentItem = m_pGraphicsScene->focusItem();
QGraphicsSceneEvent *mouseEvent = (QGraphicsSceneEvent *)e;
2023-04-14 19:30:30 +08:00
qDebug() << "event->type():" << mouseEvent->type();
2024-09-11 16:37:00 +08:00
if (e->type() == QEvent::MouseButtonDblClick) {
2023-04-14 19:30:30 +08:00
qDebug() << "Double Click"; // 注意这里一定要返回true表示你要过滤该事件原本的实现
QList<QGraphicsItem *> items = m_pGraphicsScene->items();
foreach (QGraphicsItem *item, items) {
qDebug() << "Double items";
2024-09-11 16:37:00 +08:00
QGraphicsItem *graphicsItem = static_cast<QGraphicsItem *>(item);
if (graphicsItem->isSelected()) {
qDebug() << "Double Click Item";
2023-04-14 19:30:30 +08:00
}
}
}
}