3500/WaveDisplay.cpp

679 lines
23 KiB
C++
Raw Normal View History

2023-04-14 19:30:30 +08:00
#include "WaveDisplay.h"
#include "ui_WaveDisplay.h"
#include "NetMgr.h"
#include <QNetworkRequest>
#include <QListView>
2023-10-19 14:15:31 +08:00
#include "log.h"
2023-04-14 19:30:30 +08:00
CWaveDisPlay::CWaveDisPlay(QWidget *parent) :
QWidget(parent),
ui(new Ui::CWaveDisPlay)
{
ui->setupUi(this);
m_ChannelID = "";
m_PackgNum = 1;
bFlag = false;
2023-04-17 17:40:26 +08:00
m_Times = 0;
2023-04-27 19:48:15 +08:00
m_Count = 0;
OneSecond = true;
2023-04-14 19:30:30 +08:00
ui->widget->setProperty("flag", "Title");
ui->widget_4->setProperty("flag", "normal");
2023-10-19 14:15:31 +08:00
ui->widget_wave->plotLayout()->insertRow(0);
2024-07-04 15:23:26 +08:00
QString strTitle = QString("主频频率 %1 Hz主频幅值 %2相位角 %3").arg(0).arg(0).arg(0);
2023-10-19 14:15:31 +08:00
customLogMessageHandler(QtDebugMsg,strTitle);
m_title = new QCPTextElement(ui->widget_wave, strTitle);
ui->widget_wave->plotLayout()->addElement(0, 0, m_title);
2023-04-14 19:30:30 +08:00
InitWindows();
2024-09-11 16:37:00 +08:00
2023-04-14 19:30:30 +08:00
}
CWaveDisPlay::~CWaveDisPlay()
{
delete ui;
}
void CWaveDisPlay::InitWindows()
{
m_pNetMgr = new NetMgr(this);
ui->Btn_Timewave->setStyleSheet(" QPushButton{ border-image:url(:/image/Btn/timewave.png) 5; }\
QPushButton:hover{ border-image:url(:/image/Btn/timewave-p.png) 5; }\
QPushButton:pressed{border-image:url(:/image/Btn/timewave-p.png) 5; }\
QPushButton:checked{border-image:url(:/image/Btn/timewave-p.png) 5; } " );
ui->Btn_Timewave->setChecked(true);
2023-04-17 17:40:26 +08:00
ui->pushButton_1S->setStyleSheet(" QPushButton{ border-image:url(:/image/Btn/normal_Btn.png); color:#1f5188 }\
QPushButton:hover{ border-image:url(:/image/Btn/normal_Btn_p.png); color:#ffffff }\
QPushButton:pressed{border-image:url(:/image/Btn/normal_Btn_p.png); color:#ffffff }\
QPushButton:checked{border-image:url(:/image/Btn/normal_Btn_p.png); color:#ffffff } " );
ui->pushButton_1S->setChecked(true);
2023-04-14 19:30:30 +08:00
//绑定HTTP消息响应
connect(m_pNetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
on_comboBox_channel_2_currentTextChanged("");
tracer = new QCPItemTracer(ui->widget_wave);
tracer->setStyle(QCPItemTracer::tsCrosshair);
tracer->setPen(QPen(Qt::red));
tracer->setBrush(Qt::red);
tracer->setSize(6);
tracer->setVisible(false);
tracer->setInterpolating(false);
QFont font;
font.setPixelSize(20);
tracerLabel = new QCPItemText(ui->widget_wave);
tracerLabel->setLayer("overlay");
tracerLabel->setPen(QPen(Qt::white));
tracerLabel->setBrush(QColor(64, 156, 225));
tracerLabel->setPadding(QMargins(2,2,2,2));//边界宽度
tracerLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignLeft);//文字布局:顶、左对齐
tracerLabel->position->setType(QCPItemPosition::ptAxisRectRatio);//位置类型(当前轴范围的比例为单位/实际坐标为单位)
tracerLabel->position->setCoords(0, 0);
tracerLabel->setFont(font);
tracerLabel->setText("");
2023-10-19 14:15:31 +08:00
ui->comboBox_channel_2->clear();
ui->comboBox_channel_2->addItem("请选择通道...");
for (int i = 0; i < g_ChannelBaseInfo.size(); i++) {
ui->comboBox_channel_2->addItem(g_ChannelBaseInfo[i].channelName);
}
ui->comboBox_channel_2->setView(new QListView());
ui->comboBox_channel_2->setCurrentText("请选择通道...");
2023-04-14 19:30:30 +08:00
Cursor();
}
void CWaveDisPlay::on_Btn_Hand_clicked()
{
ui->widget_wave->setSelectionRectMode(QCP::SelectionRectMode::srmNone);
if(ui->Btn_Hand->isChecked()){
//交互设置
ui->widget_wave->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iMultiSelect);
2023-04-27 19:48:15 +08:00
ui->Btn_Zoom->setChecked(false);
2023-04-14 19:30:30 +08:00
}else if(!ui->Btn_Hand->isChecked()){
ui->widget_wave->setInteractions(QCP::iNone);
}
}
void CWaveDisPlay::on_Btn_Zoom_clicked()
{
2023-04-27 19:48:15 +08:00
if(ui->Btn_Zoom->isChecked()){
ui->Btn_Hand->setChecked(false);
ui->widget_wave->setSelectionRectMode(QCP::SelectionRectMode::srmZoom);
ui->widget_wave->selectionRect()->setPen(QPen(Qt::black,1,Qt::DashLine));//虚线
ui->widget_wave->selectionRect()->setBrush(QBrush(QColor(255, 222, 173,50)));//NavajoWhite
}
else if(!ui->Btn_Zoom->isChecked()){
ui->widget_wave->setSelectionRectMode(QCP::SelectionRectMode::srmNone);
}
2023-04-14 19:30:30 +08:00
}
void CWaveDisPlay::on_Btn_Scales_clicked()
{
ui->widget_wave->setSelectionRectMode(QCP::SelectionRectMode::srmNone);
ui->widget_wave->rescaleAxes(true);
ui->widget_wave->replot();
}
void CWaveDisPlay::on_comboBox_channel_currentTextChanged(const QString &arg1)
{
}
void CWaveDisPlay::ParseDataTimeWave(QJsonObject & objContent)
{
int packageMax = objContent["packageMax"].toInt();
int package = objContent["package"].toInt();
if(packageMax > 1 && m_PackgNum < packageMax /*&& package + 1 <= packageMax*/ && !bFlag ){
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "30");
cmdBody.insert("package",m_PackgNum);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
m_PackgNum += 1;
}
QString data = objContent["Data"].toString();
2023-04-27 19:48:15 +08:00
2023-04-14 19:30:30 +08:00
if(package + 1 == packageMax){
2023-04-27 19:48:15 +08:00
m_WaveData = m_WaveData + data;
qDebug() << "package" <<package << "packageMax" <<packageMax << endl;
m_PackgNum = 1;
bFlag = true;
m_ListWaveData = m_WaveData.split(",");
ui->widget_wave->xAxis->setLabel("Time(s)");
ui->widget_wave->yAxis->setLabel(m_ChannelUnit);
QString str = QString("wave size = %1").arg(m_ListWaveData.size());
customLogMessageHandler(QtDebugMsg,str);
double gap = 0.0;
if(OneSecond){
ui->widget_wave->xAxis->setRange(0, 1);
gap = (double)1/(double)m_ListWaveData.size();
}else{
ui->widget_wave->xAxis->setRange(0, 4);
gap = (double)4/(double)m_ListWaveData.size();
}
2023-10-19 14:15:31 +08:00
double f = 0.0;
QVector<double> x,y;
QCPGraph* graph = ui->widget_wave->addGraph(ui->widget_wave->xAxis, ui->widget_wave->yAxis);
for(int i = 0; i < m_ListWaveData.size();i++){
x.push_back(f);
y.push_back(m_ListWaveData[i].toDouble());
f += gap;
}
2023-10-19 14:15:31 +08:00
QVector<double>::iterator max = std::max_element(std::begin(y), std::end(y));
if(m_ChannelType == "PULSE_CURRENT"){
QVector<double>::iterator min = std::min_element(std::begin(y), std::end(y));
double min_y = *min;
if(min_y < 1){
double sum = std::accumulate(std::begin(y), std::end(y), 0.0);
double size = y.size();
double mean = sum/size;
for(int i = 0; i < size;i++){
y[i] = y[i] - mean;
}
}
max = std::max_element(std::begin(y), std::end(y));
2023-04-14 19:30:30 +08:00
}
double biggest = *max;
qDebug() << "x" << x.size() << "y" << y.size() << endl;
graph->setData(x,y);
ui->widget_wave->yAxis->setRange(-1,biggest+2);
on_Btn_Scales_clicked();
ui->widget_wave->replot();
2023-04-14 19:30:30 +08:00
2023-10-19 14:15:31 +08:00
if(ui->pushButton_1S->isChecked() && (m_ChannelType == "TACHOMETER" || (m_speedRefChannelId != "" && m_speedRefChannelId != "- -"))){
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "92");//获取键相
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
}
2023-04-27 19:48:15 +08:00
}else{
m_WaveData = m_WaveData + data + ",";
2023-04-14 19:30:30 +08:00
}
}
void CWaveDisPlay::ParseDataFsWave(QJsonObject & objContent)
{
int packageMax = objContent["packageMax"].toInt();
int package = objContent["package"].toInt();
if(packageMax > 1 && m_PackgNum < packageMax && package + 1 <= packageMax && !bFlag ){
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "32");
cmdBody.insert("package",m_PackgNum);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
m_PackgNum += 1;
}
QString data = objContent["Data"].toString();
2023-10-19 14:15:31 +08:00
qDebug() << data << endl;
2023-04-14 19:30:30 +08:00
m_WaveData = m_WaveData + data + ",";
if(m_PackgNum == packageMax){
m_PackgNum = 1;
bFlag = true;
m_ListWaveData = m_WaveData.split(",");
//qDebug() << m_ListWaveData << endl;
ui->widget_wave->xAxis->setRange(0, 1);
ui->widget_wave->xAxis->setLabel("Fs(Hz)");
2024-07-04 15:23:26 +08:00
ui->widget_wave->yAxis->setLabel(m_ChannelUnit);
2023-04-14 19:30:30 +08:00
QVector<double> x,y;
2024-09-11 16:37:00 +08:00
//QCPGraph* graph = ui->widget_wave->addGraph(ui->widget_wave->xAxis, ui->widget_wave->yAxis);
QCPBars *bars = new QCPBars(ui->widget_wave->xAxis, ui->widget_wave->yAxis);
bars->setAntialiased(false);
bars->setPen(QPen(QColor(31, 81, 136).lighter(130))); // 设置柱状图的边框颜色
bars->setBrush(QColor(31, 81, 136)); // 设置柱状图的画刷颜色
bars->setWidth(0.02);
2023-10-19 14:15:31 +08:00
float gap = 0;
2023-04-14 19:30:30 +08:00
for(int i = 0; i < m_ListWaveData.size();i++){
2023-10-19 14:15:31 +08:00
x.push_back(gap);
y.push_back(qAbs(m_ListWaveData[i].toDouble()));
2023-10-19 14:15:31 +08:00
if(g_strFre == "1")
gap += 1;
else if(g_strFre == "0.25")
gap += 0.25;
2023-04-14 19:30:30 +08:00
}
2023-10-19 14:15:31 +08:00
y[0] = 0;
//qDebug() << "x" <<x.size() << "y" << y.size() << endl;
2024-09-11 16:37:00 +08:00
//graph->setData(x,y);
bars->setData(x, y);
2023-04-14 19:30:30 +08:00
ui->widget_wave->xAxis->setRange(0, y.size());
on_Btn_Scales_clicked();
ui->widget_wave->replot();
}
}
2023-04-27 19:48:15 +08:00
void CWaveDisPlay::ParseDataKeyPhase(QJsonObject& objContent)
{
2023-10-19 14:15:31 +08:00
m_ListKeyPhaseData.clear();
ui->widget_wave->plotLayout()->remove(m_title);
m_title = NULL;
2023-04-27 19:48:15 +08:00
QString data = objContent["Data"].toString();
2023-10-19 14:15:31 +08:00
double PhaseAngle = objContent["PhaseAngle"].toDouble();
double amp1x = objContent["1xamp"].toDouble();
double freq1x = objContent["1xfreq"].toDouble();
2023-04-27 19:48:15 +08:00
m_ListKeyPhaseData = data.split(",");
qDebug() << "m_ListKeyPhaseData" << m_ListKeyPhaseData << endl;
2024-07-04 15:23:26 +08:00
QString strAmp1x = QString::number(amp1x, 'f', 2); // 保留两位小数
QString strPhaseAngle = QString::number(PhaseAngle, 'f', 1);
QString strTitle = QString("主频频率 %1 Hz主频幅值 %2相位角 %3").arg(freq1x).arg(strAmp1x).arg(strPhaseAngle);
2023-10-19 14:15:31 +08:00
customLogMessageHandler(QtDebugMsg,strTitle);
m_title = new QCPTextElement(ui->widget_wave, strTitle);
ui->widget_wave->plotLayout()->addElement(0, 0, m_title);
QVector<double> x,y,x2,y2;
double f = 0;
double gap = (double)1/(double)m_ListWaveData.size();
for(int i = 0; i < m_ListWaveData.size();i++){
for(int j = 0; j < m_ListKeyPhaseData.size();j++){
if(m_ListKeyPhaseData[j].toInt() == i){
x2.push_back(f);
y2.push_back(m_ListWaveData[i].toDouble());
}
}
f += gap;
}
QCPGraph* dwPoints = new QCPGraph(ui->widget_wave->xAxis, ui->widget_wave->yAxis);
dwPoints->setAdaptiveSampling(false);
dwPoints->setLineStyle(QCPGraph::lsNone);
dwPoints->setScatterStyle(QCPScatterStyle::ssDot);
dwPoints->setPen(QPen(QBrush(Qt::red), 5));
dwPoints->addData(x2, y2);
ui->widget_wave->replot();
2023-04-27 19:48:15 +08:00
}
2023-10-19 14:15:31 +08:00
2023-04-14 19:30:30 +08:00
void CWaveDisPlay::slotNetMgr(QString sAddr, const QVariant &msg)
{
2023-10-19 14:15:31 +08:00
2023-04-14 19:30:30 +08:00
QJsonObject objec = msg.value<QJsonObject>();
2023-10-19 14:15:31 +08:00
2023-04-27 19:48:15 +08:00
if(!objec["success"].toBool()){
QString strMessage = objec["message"].toString();
if(strMessage.isEmpty())
QMessageBox::information(this, QStringLiteral("提示"), "连接失败!");
else
QMessageBox::information(this, QStringLiteral("提示"), strMessage);
return;
}
2023-04-14 19:30:30 +08:00
if(objec.contains("cmd"))
{
QJsonValue arrays_value = objec.take("cmd");
qDebug()<<"cmd ="<<arrays_value.toString();
2023-10-19 14:15:31 +08:00
if(arrays_value.toString() == "30" || arrays_value.toString() == "89"){
2023-04-14 19:30:30 +08:00
QJsonObject objValue = objec["content"].toObject();
ParseDataTimeWave(objValue);
2023-04-27 19:48:15 +08:00
}else if(arrays_value.toString() == "32"){
2023-04-14 19:30:30 +08:00
QJsonObject objValue = objec["content"].toObject();
ParseDataFsWave(objValue);
2023-04-27 19:48:15 +08:00
}else if(arrays_value.toString() == "92"){
QJsonObject objValue = objec["content"].toObject();
ParseDataKeyPhase(objValue);
2023-04-14 19:30:30 +08:00
}
}
}
void CWaveDisPlay::InitGraph()
{
m_PackgNum = 1;
bFlag = false;
ui->widget_wave->clearGraphs();
ui->widget_wave->clearPlottables();
ui->widget_wave->replot();
m_WaveData = "";
m_ListWaveData.clear();
}
void CWaveDisPlay::on_Btn_Timewave_clicked()
{
ui->Btn_Fswave->setChecked(false);
if(!ui->Btn_Timewave->isChecked()){
InitGraph();
return;
}
InitGraph();
2023-10-19 14:15:31 +08:00
2023-04-14 19:30:30 +08:00
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "30");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
2023-04-27 19:48:15 +08:00
2023-10-19 14:15:31 +08:00
2023-04-14 19:30:30 +08:00
}
void CWaveDisPlay::on_Btn_Fswave_clicked()
{
2023-04-27 19:48:15 +08:00
if(ui->pushButton_4S->isChecked()){
QMessageBox::information(this, QStringLiteral("提示"), "请切换到1S波形");
ui->Btn_Fswave->setChecked(false);
return;
}
2023-04-14 19:30:30 +08:00
ui->Btn_Timewave->setChecked(false);
if(!ui->Btn_Fswave->isChecked()){
InitGraph();
return;
}
InitGraph();
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "32");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
}
void CWaveDisPlay::mouseMoveEvent(QMouseEvent *event)
{
tracer->setVisible(true);
tracerLabel->setVisible(true);
2024-09-11 16:37:00 +08:00
if(ui->Btn_Timewave->isChecked()){
//将像素点转换成qcustomplot中的坐标值并通过setGraphKey将锚点值设为真实数据值。tracer->setGraphKey(xAxis->pixelToCoord(event->pos().x()));
int graphCount = ui->widget_wave->graphCount();
if(graphCount < 1)
return;
//获得鼠标位置处对应的横坐标数据x
double x = ui->widget_wave->xAxis->pixelToCoord(event->pos().x());
//遍历曲线
//for (int i = 0; i < graphCount && tracer->visible(); ++i)
{
//显示锚点
QCPGraph *mGraph = ui->widget_wave->graph(0);
tracer->setGraph(mGraph);//将锚点设置到被选中的曲线上
tracer->setGraphKey(x); //将游标横坐标设置成刚获得的横坐标数据x
tracer->updatePosition(); //使得刚设置游标的横纵坐标位置生效
double xValue = tracer->position->key();
double yValue = tracer->position->value();
tracerLabel->setVisible(true);
tracerLabel->setText(QString("X: %1 Y: %2").arg( QString::number(xValue)).arg(QString::number(yValue)));
//显示tip框
QCPDataContainer<QCPGraphData>::const_iterator coorPoint = ui->widget_wave->graph(0)->data().data()->findBegin(xValue, true);//true代表向左搜索
}
}else if(ui->Btn_Fswave->isChecked()){
// 获取鼠标位置并转换为坐标
double x = ui->widget_wave->xAxis->pixelToCoord(event->pos().x());
// 找到最近的条形图数据点
double minDistance = std::numeric_limits<double>::max();
double nearestBarKey = 0;
double nearestBarValue = 0;
for (int i = 0; i < ui->widget_wave->plottableCount();i++)
{
if (QCPBars *bars = qobject_cast<QCPBars *>(ui->widget_wave->plottable(i)))
{
for (int i = 0; i < bars->data()->size(); ++i)
{
double barKey = bars->data()->at(i)->key;
double distance = std::abs(barKey - x);
if (distance < minDistance)
{
minDistance = distance;
nearestBarKey = barKey;
nearestBarValue = bars->data()->at(i)->value;
}
}
}
}
tracerLabel->setText(QString("X: %1 Y: %2").arg( QString::number(nearestBarKey)).arg(QString::number(nearestBarValue)));
// 设置游标位置
tracer->position->setCoords(nearestBarKey, nearestBarValue);
2023-04-14 19:30:30 +08:00
}
//重绘
ui->widget_wave->replot();
}
void CWaveDisPlay::Cursor()
{
tracer->setVisible(false);
tracerLabel->setVisible(false);
connect(ui->widget_wave, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoveEvent(QMouseEvent*)));
ui->widget_wave->replot();
}
void CWaveDisPlay::on_pushButton_refresh_clicked()
{
on_comboBox_channel_2_currentTextChanged("");
}
void CWaveDisPlay::on_comboBox_channel_2_currentTextChanged(const QString &arg1)
{
2023-10-19 14:15:31 +08:00
if(ui->comboBox_channel_2->count() < 1)
return;
2023-04-14 19:30:30 +08:00
m_PackgNum = 1;
bFlag = false;
ui->widget_wave->clearGraphs();
ui->widget_wave->clearPlottables();
ui->widget_wave->replot();
m_WaveData = "";
m_ListWaveData.clear();
QString strChannelName = ui->comboBox_channel_2->currentText();
if(strChannelName == "请选择通道..."){
return;
}
int i = 0;
for (i = 0; i < g_ChannelBaseInfo.size(); i++) {
if(strChannelName == g_ChannelBaseInfo[i].channelName){
break;
}
}
m_ChannelID = g_ChannelBaseInfo[i].channelID;
2023-04-27 19:48:15 +08:00
m_ChannelType = g_ChannelBaseInfo[i].channelType;
2023-10-19 14:15:31 +08:00
m_speedRefChannelId = g_ChannelBaseInfo[i].speedRefChannelId;
2024-07-04 15:23:26 +08:00
m_ChannelUnit = g_ChannelBaseInfo[i].sensorEngineeringUnit;
2023-04-14 19:30:30 +08:00
if(ui->Btn_Timewave->isChecked())
{
2023-04-27 19:48:15 +08:00
m_Times = 0;
if(ui->pushButton_4S->isChecked()){
OneSecond = false;
2023-10-19 14:15:31 +08:00
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "89");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
2024-03-14 09:35:39 +08:00
2023-04-27 19:48:15 +08:00
}else if(ui->pushButton_1S->isChecked()){
OneSecond = true;
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "30");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
2023-10-19 14:15:31 +08:00
QString str = QString("当前通道 %1,通道类型 %2转速参考通道 %3").arg(m_ChannelID).arg(m_ChannelType).arg(m_speedRefChannelId);
customLogMessageHandler(QtDebugMsg,str);
2023-04-27 19:48:15 +08:00
}
2023-04-14 19:30:30 +08:00
}
else if(ui->Btn_Fswave->isChecked())
{
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "32");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
}
}
2023-04-17 17:40:26 +08:00
void CWaveDisPlay::timerEvent(QTimerEvent *ev)
{
if(ev->timerId() == id1)
{
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "30");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
m_Times = m_Times + 1;
2023-04-27 19:48:15 +08:00
qDebug() << "m_Times" << m_Times << endl;
2023-04-17 17:40:26 +08:00
if(m_Times == 4){
killTimer(id1);
m_Times = 0;
}
}
2024-03-14 09:35:39 +08:00
if(ev->timerId() == id2){
m_PackgNum = 1;
bFlag = false;
ui->widget_wave->clearGraphs();
ui->widget_wave->clearPlottables();
ui->widget_wave->replot();
m_WaveData = "";
m_ListWaveData.clear();
if(ui->Btn_Timewave->isChecked()){
OneSecond = true;
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "30");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
}else if(ui->Btn_Fswave->isChecked())
{
QJsonObject allObj,cmdBody;
allObj.insert("cmd", "32");
cmdBody.insert("package",0);
cmdBody.insert("channelId",m_ChannelID);
allObj["cmdBody"] = cmdBody;
QNetworkRequest req;
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
req.setUrl(sUrl);
m_pNetMgr->PostJson(req,allObj);
}
}
2023-04-17 17:40:26 +08:00
}
void CWaveDisPlay::on_pushButton_1S_clicked()
{
2023-04-27 19:48:15 +08:00
OneSecond = true;
2023-04-17 17:40:26 +08:00
ui->pushButton_4S->setChecked(false);
2023-04-27 19:48:15 +08:00
if(ui->pushButton_1S->isChecked()){
2023-04-17 17:40:26 +08:00
2023-04-27 19:48:15 +08:00
on_comboBox_channel_2_currentTextChanged("");
2023-04-17 17:40:26 +08:00
return;
}
}
void CWaveDisPlay::on_pushButton_4S_clicked()
{
2023-04-27 19:48:15 +08:00
if(ui->Btn_Fswave->isChecked()){
QMessageBox::information(this, QStringLiteral("提示"), "请切换到时域图!");
ui->pushButton_4S->setChecked(false);
return;
}
OneSecond = false;
m_Times = 0;
2023-04-17 17:40:26 +08:00
ui->pushButton_1S->setChecked(false);
if(ui->pushButton_4S->isChecked()){
2023-04-27 19:48:15 +08:00
on_comboBox_channel_2_currentTextChanged("");
2023-04-17 17:40:26 +08:00
return;
}
}
2024-03-14 09:35:39 +08:00
void CWaveDisPlay::on_pushButton_refreshauto_clicked()
{
if(ui->comboBox_channel_2->count() < 1)
return;
m_PackgNum = 1;
bFlag = false;
ui->widget_wave->clearGraphs();
ui->widget_wave->clearPlottables();
ui->widget_wave->replot();
m_WaveData = "";
m_ListWaveData.clear();
QString strChannelName = ui->comboBox_channel_2->currentText();
if(strChannelName == "请选择通道..."){
return;
}
if(ui->pushButton_4S->isChecked()){
QMessageBox::information(this, QStringLiteral("提示"), "请切换到1秒时域图");
ui->pushButton_refreshauto->setChecked(false);
return;
}
if(ui->pushButton_refreshauto->isChecked()){
ui->pushButton_refreshauto->setText("关闭");
id2 = startTimer(2000); //参数1 间隔 单位 毫秒
//定时器第二种方式
QTimer * timer = new QTimer(this);
//启动定时器
timer->start(500);
}
if(!ui->pushButton_refreshauto->isChecked() && ui->pushButton_1S->isChecked()){
ui->pushButton_refreshauto->setText("自动刷新");
killTimer(id2);
return;
}
}