完成数据变化绘图

This commit is contained in:
2024-09-18 16:18:36 +08:00
parent 14d80194c5
commit c9e2c5a72f
8 changed files with 59 additions and 39 deletions

View File

@ -22,8 +22,8 @@ set(PROJECT_SOURCES
global.h global.h
readthread.cpp readthread.cpp
readthread.h readthread.h
customtime.h customthread.h
customtime.cpp customthread.cpp
qcustomplot.h qcustomplot.h
qcustomplot.cpp qcustomplot.cpp
) )

View File

@ -9,14 +9,14 @@ CONFIG += c++11
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \ SOURCES += \
customtime.cpp \ customthread.cpp \
main.cpp \ main.cpp \
mainwindow.cpp \ mainwindow.cpp \
qcustomplot.cpp \ qcustomplot.cpp \
readthread.cpp readthread.cpp
HEADERS += \ HEADERS += \
customtime.h \ customthread.h \
global.h \ global.h \
mainwindow.h \ mainwindow.h \
qcustomplot.h \ qcustomplot.h \

View File

@ -1,14 +1,14 @@
#include "customtime.h" #include "customthread.h"
CustomTime::CustomTime(QObject *parent) CustomThread::CustomThread(QObject *parent)
: QThread{parent} {} : QThread{parent} {}
void CustomTime::setValue(QVector<int> vector, QString string) { void CustomThread::setValue(QVector<int> vector, QString string) {
this->jd = vector; this->jd = vector;
this->dataName = string; this->dataName = string;
} }
void CustomTime::run() { void CustomThread::run() {
m_PlotView.clear(); m_PlotView.clear();
rule.clear(); rule.clear();
@ -20,6 +20,7 @@ void CustomTime::run() {
bool isEnum = namelist[dataName]; bool isEnum = namelist[dataName];
int bytesRead = 0; int bytesRead = 0;
for (int i = 0; i < jd.size(); ++i) { for (int i = 0; i < jd.size(); ++i) {
int X = 0;
QString tem = "这是一个无实际作用的标识"; QString tem = "这是一个无实际作用的标识";
for (int j = 0; j < g_param[jd[i]].size(); j++) { for (int j = 0; j < g_param[jd[i]].size(); j++) {
//更新进度条 //更新进度条
@ -27,15 +28,22 @@ void CustomTime::run() {
emit setProgressBar(bytesRead); emit setProgressBar(bytesRead);
QDateTime temTime = QDateTime::fromString(g_param[jd[i]][j]["时间"], "yyyy-MM-dd hh:mm:ss:zzz"); QDateTime temTime = QDateTime::fromString(g_param[jd[i]][j]["时间"], "yyyy-MM-dd hh:mm:ss:zzz");
if (temTime >= beginTime && temTime < endTime) { if (temTime >= beginTime && temTime <= endTime) {
if (g_param[jd[i]][j].contains(dataName)) { if (g_param[jd[i]][j].contains(dataName)) {
tem = g_param[jd[i]][j][dataName]; tem = g_param[jd[i]][j][dataName];
} else { } else {
if (!isTime) {
continue;
}
if (tem == "这是一个无实际作用的标识") { if (tem == "这是一个无实际作用的标识") {
continue; continue;
} }
} }
if (isTime) {
xData[jd[i]].append(temTime.toMSecsSinceEpoch() / 1000.0); xData[jd[i]].append(temTime.toMSecsSinceEpoch() / 1000.0);
} else {
xData[jd[i]].append(X++);
}
if (isEnum) { if (isEnum) {
yData[jd[i]].append(tem.toDouble()); yData[jd[i]].append(tem.toDouble());
} else { } else {
@ -48,10 +56,14 @@ void CustomTime::run() {
} }
} }
} }
emit setPlotView(jd[i], isEnum, true); emit setPlotView(jd[i], isEnum, isTime);
} }
emit setWidget(); emit setWidget();
quit(); quit();
} }
void CustomThread::setIsTime(bool IsTime) {
CustomThread::isTime = IsTime;
}

View File

@ -4,13 +4,15 @@
#include <QThread> #include <QThread>
#include "global.h" #include "global.h"
class CustomTime : public QThread { class CustomThread : public QThread {
Q_OBJECT Q_OBJECT
public: public:
explicit CustomTime(QObject *parent = nullptr); explicit CustomThread(QObject *parent = nullptr);
void setValue(QVector<int> vector, QString string); void setValue(QVector<int> vector, QString string);
void setIsTime(bool IsTime);
signals: signals:
void setProgressBar(int bytesRead); void setProgressBar(int bytesRead);
@ -25,6 +27,7 @@ protected:
private: private:
QVector<int> jd; QVector<int> jd;
QString dataName; QString dataName;
bool isTime;
}; };
#endif // CUSTOMTIMETHREAD_H #endif // CUSTOMTIMETHREAD_H

View File

@ -8,7 +8,7 @@
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow), readThread(new ReadThread), customTime(new CustomTime) { : QMainWindow(parent), ui(new Ui::MainWindow), readThread(new ReadThread), customTime(new CustomThread) {
ui->setupUi(this); ui->setupUi(this);
// 创建版本号标签并添加到状态栏的右端 // 创建版本号标签并添加到状态栏的右端
QLabel *m_versionLabel = new QLabel(tr("v1.2.0"), this); QLabel *m_versionLabel = new QLabel(tr("v1.2.0"), this);
@ -26,9 +26,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(readThread, &ReadThread::closeProg, this, &MainWindow::closeProg); connect(readThread, &ReadThread::closeProg, this, &MainWindow::closeProg);
//customTime //customTime
connect(customTime, &CustomTime::setProgressBar, this, &MainWindow::setProgressBar); connect(customTime, &CustomThread::setProgressBar, this, &MainWindow::setProgressBar);
connect(customTime, &CustomTime::setPlotView, this, &MainWindow::setPlotView); connect(customTime, &CustomThread::setPlotView, this, &MainWindow::setPlotView);
connect(customTime, &CustomTime::setWidget, this, &MainWindow::setWidget); connect(customTime, &CustomThread::setWidget, this, &MainWindow::setWidget);
} }
@ -64,27 +64,19 @@ void MainWindow::on_timeCustomBtn_clicked() {
//校验数据 //校验数据
if (!inspectionData()) { return; } if (!inspectionData()) { return; }
//传入数据绘图
customTime->setValue(jd, dataName);
// 获取文件大小
int fileSize = 0;
for (int i : jd) {
fileSize += g_param[i].size();
}
//设置进度条
ui->progressBar->setValue(0);
ui->progressBar->setMaximum(fileSize);
ui->progressBar->show();
//运行线程 //运行线程
customTime->setIsTime(true);
customTime->start(); customTime->start();
} }
void MainWindow::on_dataCustomBtn_clicked() { void MainWindow::on_dataCustomBtn_clicked() {
//校验数据
if (!inspectionData()) { return; }
//运行线程
customTime->setIsTime(false);
customTime->start();
} }
bool MainWindow::inspectionData() { bool MainWindow::inspectionData() {
@ -100,7 +92,7 @@ bool MainWindow::inspectionData() {
return false; return false;
} }
//获取基带id //获取基带id
jd.clear(); QVector<int> jd;
if (ui->jd1->isChecked()) { if (ui->jd1->isChecked()) {
jd.append(0); jd.append(0);
} }
@ -127,7 +119,7 @@ bool MainWindow::inspectionData() {
return false; return false;
} }
//获取参数名 //获取参数名
dataName = ui->comboBox->currentText(); QString dataName = ui->comboBox->currentText();
//判断参数名是否正确 //判断参数名是否正确
if (!namelist.keys().contains(dataName)) { if (!namelist.keys().contains(dataName)) {
QMessageBox::warning(this, "警告", "未找到该数据"); QMessageBox::warning(this, "警告", "未找到该数据");
@ -136,6 +128,20 @@ bool MainWindow::inspectionData() {
//创建新窗口 //创建新窗口
widget = new QWidget(); widget = new QWidget();
widget->setWindowTitle(dataName); widget->setWindowTitle(dataName);
//传入数据绘图
customTime->setValue(jd, dataName);
// 获取文件大小
int fileSize = 0;
for (int i: jd) {
fileSize += g_param[i].size();
}
//设置进度条
ui->progressBar->setValue(0);
ui->progressBar->setMaximum(fileSize);
ui->progressBar->show();
return true; return true;
} }

View File

@ -5,7 +5,7 @@
#include "global.h" #include "global.h"
#include "readthread.h" #include "readthread.h"
#include "customtime.h" #include "customthread.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { namespace Ui {
@ -61,9 +61,8 @@ private slots:
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
ReadThread *readThread; ReadThread *readThread;
CustomTime *customTime; CustomThread *customTime;
QVector<int> jd;
QString dataName;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -14,7 +14,7 @@ ReadThread::ReadThread(QObject *parent)
kexue.setPattern("^[0-9].[0-9]e[+-][0-9][0-9]"); kexue.setPattern("^[0-9].[0-9]e[+-][0-9][0-9]");
} }
bool ReadThread::isNumeric(QString data) { bool ReadThread::isNumeric(const QString& data) {
bool flag = false; bool flag = false;
patternMatch = pattern.match(data); patternMatch = pattern.match(data);
if (patternMatch.hasMatch()) { if (patternMatch.hasMatch()) {

View File

@ -13,7 +13,7 @@ Q_OBJECT
public: public:
explicit ReadThread(QObject *parent = nullptr); explicit ReadThread(QObject *parent = nullptr);
bool isNumeric(QString data); bool isNumeric(const QString &data);
signals: signals: