diff --git a/customtime.cpp b/customtime.cpp index a2dca75..511f76d 100644 --- a/customtime.cpp +++ b/customtime.cpp @@ -1,14 +1,14 @@ #include "customtime.h" -CustomTimeThread::CustomTimeThread(QObject *parent) +CustomTime::CustomTime(QObject *parent) : QThread{parent} {} -void CustomTimeThread::setValue(QVector vector, QString string) { +void CustomTime::setValue(QVector vector, QString string) { this->jd = vector; this->dataName = string; } -void CustomTimeThread::run() { +void CustomTime::run() { m_PlotView.clear(); rule.clear(); diff --git a/customtime.h b/customtime.h index 807fe15..7c04bf0 100644 --- a/customtime.h +++ b/customtime.h @@ -4,10 +4,10 @@ #include #include "global.h" -class CustomTimeThread : public QThread { +class CustomTime : public QThread { Q_OBJECT public: - explicit CustomTimeThread(QObject *parent = nullptr); + explicit CustomTime(QObject *parent = nullptr); void setValue(QVector vector, QString string); diff --git a/global.h b/global.h index a6d5e49..aba8f61 100644 --- a/global.h +++ b/global.h @@ -15,12 +15,12 @@ extern QMap namelist; //存储数据名以及数据是否是数 extern QFile file; //打开文件 extern QCompleter *completer; //下拉框选项 extern QWidget *widget; //新窗口 -extern QDateTime beginTime; -extern QDateTime endTime; -extern QVector m_PlotView; -extern QVector rule; -extern QVector xData[4]; -extern QVector yData[4]; +extern QDateTime beginTime; //开始时间 +extern QDateTime endTime; //结束时间 +extern QVector m_PlotView; //custom图 +extern QVector rule; //Y轴映射 +extern QVector xData[4]; //X轴数据 +extern QVector yData[4]; //Y轴数据 #endif //READLOG_GLOBAL_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 0a59567..b360ff2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -8,7 +8,7 @@ MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent), ui(new Ui::MainWindow), readThread(new ReadThread), customTime(new CustomTimeThread) { + : QMainWindow(parent), ui(new Ui::MainWindow), readThread(new ReadThread), customTime(new CustomTime) { ui->setupUi(this); // 创建版本号标签并添加到状态栏的右端 QLabel *m_versionLabel = new QLabel(tr("v1.2.0"), this); @@ -21,15 +21,14 @@ MainWindow::MainWindow(QWidget *parent) connect(readThread, &ReadThread::clearCombo, this, &MainWindow::clearCombo); connect(readThread, &ReadThread::showStatusbar, this, &MainWindow::showStatusbar); connect(readThread, &ReadThread::setProgressBar, this, &MainWindow::setProgressBar); - connect(readThread, &ReadThread::setBeginTime, this, &MainWindow::setBeginTime); - connect(readThread, &ReadThread::setEndTime, this, &MainWindow::setEndTime); + connect(readThread, &ReadThread::setTime, this, &MainWindow::setTime); connect(readThread, &ReadThread::addCombo, this, &MainWindow::addCombo); connect(readThread, &ReadThread::closeProg, this, &MainWindow::closeProg); //customTime - connect(customTime, &CustomTimeThread::setProgressBar, this, &MainWindow::setProgressBar); - connect(customTime, &CustomTimeThread::setPlotView, this, &MainWindow::setPlotView); - connect(customTime, &CustomTimeThread::setWidget, this, &MainWindow::setWidget); + connect(customTime, &CustomTime::setProgressBar, this, &MainWindow::setProgressBar); + connect(customTime, &CustomTime::setPlotView, this, &MainWindow::setPlotView); + connect(customTime, &CustomTime::setWidget, this, &MainWindow::setWidget); } @@ -62,20 +61,46 @@ void MainWindow::on_openFileBtn_clicked() { void MainWindow::on_timeCustomBtn_clicked() { - if (file.fileName().isEmpty()) { - QMessageBox::warning(this, "警告", "请先打开一个日志"); - 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->start(); +} + + +void MainWindow::on_dataCustomBtn_clicked() { + +} + +bool MainWindow::inspectionData() { //关闭打开的窗口 if (widget) { widget->close(); delete widget; widget = nullptr; } - + //判断是否已打开日志文件 + if (file.fileName().isEmpty()) { + QMessageBox::warning(this, "警告", "请先打开一个日志"); + return false; + } //获取基带id - QVector jd; + jd.clear(); if (ui->jd1->isChecked()) { jd.append(0); } @@ -88,48 +113,30 @@ void MainWindow::on_timeCustomBtn_clicked() { if (ui->jd4->isChecked()) { jd.append(3); } - + //判断基带是否为空 if (jd.isEmpty()) { QMessageBox::warning(this, "警告", "请至少选择一个基带"); - return; + return false; } - //获取时间 beginTime = ui->beginTimeEdit->dateTime(); endTime = ui->endTimeEdit->dateTime(); + //判断时间是否合法 if (beginTime > endTime) { QMessageBox::warning(this, "警告", "请选择正确的时间段"); - return; + return false; } //获取参数名 - QString dataName = ui->comboBox->currentText(); + dataName = ui->comboBox->currentText(); + //判断参数名是否正确 if (!namelist.keys().contains(dataName)) { QMessageBox::warning(this, "警告", "未找到该数据"); - return; + return false; } - - //传入数据绘图 - customTime->setValue(jd, dataName); + //创建新窗口 widget = new QWidget(); widget->setWindowTitle(dataName); - - // 获取文件大小 - int fileSize = 0; - for (int i = 0; i < jd.size(); ++i) { - fileSize += g_param[jd[i]].size(); - } - - //设置进度条 - ui->progressBar->setValue(0); - ui->progressBar->setMaximum(fileSize); - ui->progressBar->show(); - - customTime->start(); -} - - -void MainWindow::on_dataCustomBtn_clicked() { - + return true; } void MainWindow::clearCombo() { @@ -144,11 +151,8 @@ void MainWindow::setProgressBar(int bytesRead) { ui->progressBar->setValue(bytesRead); } -void MainWindow::setBeginTime(const QDateTime &beginTime) { +void MainWindow::setTime() { ui->beginTimeEdit->setDateTime(beginTime); -} - -void MainWindow::setEndTime(const QDateTime &endTime) { ui->endTimeEdit->setDateTime(endTime); } @@ -167,6 +171,7 @@ void MainWindow::closeProg() { void MainWindow::setPlotView(int jd, bool isNum, bool isTime) { QCustomPlot *qCustomPlot = new QCustomPlot(); + //标题 QCPTextElement *m_title; qCustomPlot->plotLayout()->insertRow(0); @@ -200,12 +205,13 @@ void MainWindow::setPlotView(int jd, bool isNum, bool isTime) { qCustomPlot->addGraph(); qCustomPlot->graph(0)->setData(xData[jd], yData[jd]); - // 自动调整轴范围 qCustomPlot->rescaleAxes(); + //设置鼠标拖动和滚轮 qCustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); + //设置X轴范围 if (!xData[jd].empty()) { qCustomPlot->xAxis->setRange(xData[jd].first(), xData[jd].last()); } diff --git a/mainwindow.h b/mainwindow.h index 5ebe335..acb8220 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -33,6 +33,8 @@ private slots: /*绘制数据变化图*/ void on_dataCustomBtn_clicked(); + bool inspectionData(); + /*清空下拉框*/ void clearCombo(); @@ -42,11 +44,8 @@ private slots: /*设置进度条进度*/ void setProgressBar(int bytesRead); - /*设置开始时间*/ - void setBeginTime(const QDateTime &beginTime); - - /*设置结束时间*/ - void setEndTime(const QDateTime &endTime); + /*设置时间*/ + void setTime(); /*设置下拉框*/ void addCombo(const QStringList &names); @@ -62,7 +61,9 @@ private slots: private: Ui::MainWindow *ui; ReadThread *readThread; - CustomTimeThread *customTime; + CustomTime *customTime; + QVector jd; + QString dataName; }; #endif // MAINWINDOW_H diff --git a/readthread.cpp b/readthread.cpp index ced7faf..52ff2bd 100644 --- a/readthread.cpp +++ b/readthread.cpp @@ -78,9 +78,9 @@ void ReadThread::run() { continue; } - //设置开始时间 + //获取开始时间 if (isBeginTime) { - emit setBeginTime(QDateTime::fromString(temtime, "yyyy-MM-dd hh:mm:ss:zzz")); + beginTime = QDateTime::fromString(temtime, "yyyy-MM-dd hh:mm:ss:zzz"); isBeginTime = false; } temData.clear(); @@ -111,9 +111,11 @@ void ReadThread::run() { g_param[JD].append(temData); } + //获取结束时间 + endTime = QDateTime::fromString(temData["时间"], "yyyy-MM-dd hh:mm:ss:zzz"); - //设置结束时间 - emit setEndTime(QDateTime::fromString(temData["时间"], "yyyy-MM-dd hh:mm:ss:zzz")); + //设置时间 + emit setTime(); //设置状态栏 emit showStatusbar("打开成功:" + file.fileName()); diff --git a/readthread.h b/readthread.h index b33fdf1..0730c22 100644 --- a/readthread.h +++ b/readthread.h @@ -23,9 +23,7 @@ signals: void setProgressBar(int bytesRead); - void setBeginTime(QDateTime beginTime); - - void setEndTime(QDateTime beginTime); + void setTime(); void addCombo(QStringList names);