commit 64cd67ecf6432251e915cb7325bb55ef77cc8869 Author: Sherlock <1297399478@qq.com> Date: Thu Sep 12 17:31:39 2024 +0800 v1.1.0 diff --git a/gloab.cpp b/gloab.cpp new file mode 100644 index 0000000..f558af2 --- /dev/null +++ b/gloab.cpp @@ -0,0 +1,13 @@ +#include "gloab.h" + +QString Gloab::fileName=""; +QVector> Gloab::g_param[4]; +QMap Gloab::temData; +QMap Gloab::namelist; +QList Gloab::m_chartViews; +QWidget * Gloab::widget; +QVector Gloab::rule; +QFile Gloab::file; +qint64 Gloab::fileSize; +qint64 Gloab::bytesRead; +QCompleter *Gloab::completer; diff --git a/gloab.h b/gloab.h new file mode 100644 index 0000000..742aa3c --- /dev/null +++ b/gloab.h @@ -0,0 +1,33 @@ +// +// Created by Sherlock on 2024/8/12. +// + +#ifndef GLOAB_H +#define GLOAB_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +class Gloab{ +public: + static QString fileName; + static QVector> g_param[4]; + static QMap temData; + static QMap namelist; + static QList m_chartViews; + static QWidget *widget; + static QVector rule; + static QFile file; + static qint64 fileSize; + static qint64 bytesRead; + static QCompleter *completer; +}; + + +#endif //GLOAB_H diff --git a/log7.pro b/log7.pro new file mode 100644 index 0000000..f13cd78 --- /dev/null +++ b/log7.pro @@ -0,0 +1,32 @@ +QT += core gui charts + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + gloab.cpp \ + main.cpp \ + mainwindow.cpp \ + threadchart.cpp \ + threadpoltchart.cpp \ + threadread.cpp + +HEADERS += \ + gloab.h \ + mainwindow.h \ + threadchart.h \ + threadpoltchart.h \ + threadread.h + +FORMS += \ + mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/log7.pro.user b/log7.pro.user new file mode 100644 index 0000000..d426760 --- /dev/null +++ b/log7.pro.user @@ -0,0 +1,275 @@ + + + + + + EnvironmentId + {212c491d-8228-40db-8cc9-f183f9b9d8d0} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + 0 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 6 + true + + + + true + + + false + true + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Qt 5.12.0 (mingw73_64) + Qt 5.12.0 (mingw73_64) + {edc54fcd-f681-4a0a-ba77-11a1a5c94a66} + 0 + 0 + 0 + + 0 + C:\Work\CQT\Test_01\build-log7-Qt_5_12_0_mingw73_64-Debug + C:/Work/CQT/Test_01/build-log7-Qt_5_12_0_mingw73_64-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + C:\Work\CQT\Test_01\build-log7-Qt_5_12_0_mingw73_64-Release + C:/Work/CQT/Test_01/build-log7-Qt_5_12_0_mingw73_64-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + C:\Work\CQT\Test_01\build-log7-Qt_5_12_0_mingw73_64-Profile + C:/Work/CQT/Test_01/build-log7-Qt_5_12_0_mingw73_64-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + 部署 + 部署 + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + + 2 + + false + log72 + Qt4ProjectManager.Qt4RunConfiguration:C:/Work/QT/ReadLog/log7/log7.pro + C:/Work/QT/ReadLog/log7/log7.pro + true + true + true + true + C:/Work/CQT/Test_01/build-log7-Qt_5_12_0_mingw73_64-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..5b40f4d --- /dev/null +++ b/main.cpp @@ -0,0 +1,15 @@ +#include "mainwindow.h" + +#include +#include + +int main(int argc, char *argv[]) +{ + // qputenv("QT_SCALE_FACTOR", "2.0"); + QTextCodec *codec = QTextCodec::codecForName("UTF-8"); + QTextCodec::setCodecForLocale(codec); + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..6a8b93d --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,373 @@ +#include "mainwindow.h" + +#include + +#include "./ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), ui(new Ui::MainWindow) + , thread_read(new threadRead), thread_chart(new ThreadChart),thread_polt(new threadPoltChart){ + ui->setupUi(this); + this->setWindowTitle("日志查询工具"); + // 创建版本号标签 + m_versionLabel = new QLabel(tr("v1.1.0"), this); + // 将标签添加到状态栏的右端 + ui->statusbar->addPermanentWidget(m_versionLabel); + + connect(thread_read, &threadRead::clearCombo, this, &MainWindow::clearCombo); + connect(thread_read, &threadRead::showStatusbar, this, &MainWindow::showStatusbar); + connect(thread_read, &threadRead::setBeginTime, this, &MainWindow::setBeginTime); + connect(thread_read, &threadRead::setEndTime, this, &MainWindow::setEndTime); + connect(thread_read, &threadRead::addCombo, this, &MainWindow::addCombo); + connect(thread_read, &threadRead::setProgressBar, this, &MainWindow::setProgressBar); + connect(thread_read, &threadRead::closeProg, this, &MainWindow::closeProg); + + //chart + connect(thread_chart, &ThreadChart::newCandS, this, &MainWindow::newCandS); + connect(thread_chart, &ThreadChart::appSeries, this, &MainWindow::appSeries); + connect(thread_chart, &ThreadChart::setChartView, this, &MainWindow::setChartView); + connect(thread_chart, &ThreadChart::setWidget, this, &MainWindow::setWidget); + connect(thread_chart, &ThreadChart::setProgressBar, this, &MainWindow::setProgressBar); + + //plot + connect(thread_polt, &threadPoltChart::newCandS, this, &MainWindow::newPlotCandS); + connect(thread_polt, &threadPoltChart::appSeries, this, &MainWindow::appSeries); + connect(thread_polt, &threadPoltChart::setChartView, this, &MainWindow::setPlotChartView); + connect(thread_polt, &threadPoltChart::setWidget, this, &MainWindow::setWidget); + connect(thread_polt, &threadPoltChart::setProgressBar, this, &MainWindow::setProgressBar); +} + +MainWindow::~MainWindow() { + delete ui; +} + +void MainWindow::on_openFileBtn_clicked() { + Gloab::fileName = QFileDialog::getOpenFileName(); + //打开文件 + Gloab::file.setFileName(Gloab::fileName); + if (!Gloab::file.open(QIODevice::ReadOnly)) { + // 打开失败时弹窗 + QString dlgTitle = "错误"; + QString strInfo = "文件打开失败"; + QMessageBox::warning(this, dlgTitle, strInfo); + //退出 + return; + } + + //设置进度条 + layout = new QVBoxLayout(ui->widget); + progressBar = new QProgressBar(ui->widget); + layout->addWidget(progressBar); + ui->widget->show(); + + // 获取文件大小 + Gloab::fileSize = Gloab::file.size(); + Gloab::bytesRead = 0; + + thread_read->start(); +} + + +void MainWindow::clearCombo() { + ui->comboBox->clear(); +} + +void MainWindow::showStatusbar(const QString &message) { + ui->statusbar->showMessage(message); +} + +void MainWindow::setBeginTime(const QDateTime &begin) { + ui->beginTime->setDateTime(begin); +} + +void MainWindow::setEndTime(const QDateTime &begin) { + ui->endTime->setDateTime(begin); +} + +void MainWindow::addCombo(const QStringList &list) { + ui->comboBox->addItems(list); + //根据输入匹配下拉框 + Gloab::completer = new QCompleter(list); + ui->comboBox->setCompleter(Gloab::completer); + +} + +void MainWindow::setProgressBar(int percent) { + progressBar->setValue(percent); + // qApp->processEvents(); // 更新UI +} + +void MainWindow::closeProg() { + layout->deleteLater(); + progressBar->deleteLater(); + ui->widget->close(); +} + +void MainWindow::newCandS() { + chart = new QChart; + series = new QLineSeries; + // series->setPointsVisible(); +} + +void MainWindow::appSeries(qreal A, qreal B) { + series->append(A, B); +} + +void MainWindow::setChartView(int jd, bool isEnum) { + // 设置图表标题 + chart->setTitle(QString("基带 %1").arg(jd+1)); + chart->addSeries(series); + if (isEnum) { + chart->createDefaultAxes(); + // 获取X轴 + QList xAxes = chart->axes(Qt::Horizontal); + // 断开所有与该轴关联的系列 + series->detachAxis(xAxes[0]); + // 从图表中移除轴 + chart->removeAxis(xAxes[0]); + } else { + // 创建类别Y轴 + QCategoryAxis *axisY = new QCategoryAxis(); + for (int var = 1; var < Gloab::rule.size(); ++var) { + axisY->append(Gloab::rule[var], var); + } + //刻度线和刻度的label对齐 + axisY->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue); + axisY->setRange(0, Gloab::rule.size() + 1); + chart->setAxisY(axisY, series); + // series->attachAxis(axisY); + } + + + // 创建一个时间轴 + QDateTimeAxis *axisX = new QDateTimeAxis; + axisX->setTickCount(10); + axisX->setFormat("HH:mm"); // 设置时间格式 + chart->addAxis(axisX, Qt::AlignBottom); + series->attachAxis(axisX); + + + // 创建QChartView + QChartView *chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); + + // 将chartView添加到容器中 + Gloab::m_chartViews.append(chartView); +} + +void MainWindow::setWidget() { + // 设置布局 + int wide = 850; + int hight = 600; + if (Gloab::m_chartViews.size() > 1) { + wide = 1800; + } + QGridLayout *gridLayout = new QGridLayout(Gloab::widget); + for (int i = 0, j = 0; i < Gloab::m_chartViews.size(); i++) { + if (i != 0 && i % 2 == 0) { + j++; + hight += 350; + } + gridLayout->addWidget(Gloab::m_chartViews[i], j, i - 2 * j); + } + Gloab::widget->resize(wide, hight); + // Gloab::widget->setMaximumHeight(950); + + Gloab::widget->move(70, 20); + Gloab::widget->show(); + + layout->deleteLater(); + progressBar->deleteLater(); + ui->widget->close(); +} + +void MainWindow::newPlotCandS() { + chart = new QChart; + series = new QLineSeries; +// series->setPointsVisible(); +} + +void MainWindow::setPlotChartView(int jd, bool isEnum) { + // 设置图表标题 + chart->setTitle(QString("基带 %1").arg(jd+1)); + chart->addSeries(series); + if (isEnum) { + chart->createDefaultAxes(); + + } else { + //创建默认XY轴 + chart->createDefaultAxes(); + //删除Y轴 + // 获取Y轴 + QList yAxes = chart->axes(Qt::Vertical); + // 断开所有与该轴关联的系列 + series->detachAxis(yAxes[0]); + // 从图表中移除轴 + chart->removeAxis(yAxes[0]); + // 创建类别Y轴 + QCategoryAxis *axisY = new QCategoryAxis(); + for (int var = 1; var < Gloab::rule.size(); ++var) { + axisY->append(Gloab::rule[var], var); + } + //刻度线和刻度的label对齐 + axisY->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue); + axisY->setRange(0, Gloab::rule.size() + 1); + chart->setAxisY(axisY, series); + // plotSeries->attachAxis(axisY); + } + + + // 创建QChartView + QChartView *chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); + + // 将chartView添加到容器中 + Gloab::m_chartViews.append(chartView); +} + +void MainWindow::on_lineChart_clicked() { + if (Gloab::fileName.isEmpty()) { + QMessageBox::warning(this, "警告", "请先打开一个日志"); + return; + } + + //关闭打开的窗口 + if (Gloab::widget) { + Gloab::widget->close(); + delete Gloab::widget; + Gloab::widget = nullptr; + } + + //获取基带id + QVector jd; + if (ui->jd1->isChecked()) { + jd.append(0); + } + if (ui->jd2->isChecked()) { + jd.append(1); + } + if (ui->jd3->isChecked()) { + jd.append(2); + } + if (ui->jd4->isChecked()) { + jd.append(3); + } + + if (jd.isEmpty()) { + QMessageBox::warning(this, "警告", "请至少选择一个基带"); + return; + } + + //获取时间 + QDateTime beginTime = ui->beginTime->dateTime(); + QDateTime endTime = ui->endTime->dateTime(); + if (beginTime>endTime) { + QMessageBox::warning(this, "警告", "请选择正确的时间段"); + return; + } + //获取参数名 + QString dataName = ui->comboBox->currentText(); + if (!Gloab::namelist.keys().contains(dataName)) { + QMessageBox::warning(this, "警告", "未找到该数据"); + return; + } + + //传入数据绘图 + thread_chart->setValue(jd, dataName, beginTime, endTime); + Gloab::widget = new QWidget(); + Gloab::widget->setWindowTitle(dataName); + + //设置进度条 + layout = new QVBoxLayout(ui->widget); + progressBar = new QProgressBar(ui->widget); + layout->addWidget(progressBar); + ui->widget->show(); + + // 获取文件大小 + Gloab::fileSize=0; + for (int i = 0; i < jd.size(); ++i) { + Gloab::fileSize+=Gloab::g_param[jd[i]].size(); + } + Gloab::bytesRead = 0; + + thread_chart->start(); + +} + +bool MainWindow::isNumeric(const QString &str) { + // 正则表达式匹配数字和可选的正负号 + QRegularExpression pattern("^[+-]?([1-9][0-9]*|0)[.]?[0-9]*$"); + QRegularExpressionMatch patternMatch = pattern.match(str); + // 使用std::regex_match来检查字符串是否完全匹配模式 + return patternMatch.hasMatch(); +} + +void MainWindow::on_plotChart_clicked() +{ + if (Gloab::fileName.isEmpty()) { + QMessageBox::warning(this, "警告", "请先打开一个日志"); + return; + } + //关闭打开的窗口 + if (Gloab::widget) { + Gloab::widget->close(); + delete Gloab::widget; + Gloab::widget = nullptr; + } + + //获取基带id + QVector jd; + if (ui->jd1->isChecked()) { + jd.append(0); + } + if (ui->jd2->isChecked()) { + jd.append(1); + } + if (ui->jd3->isChecked()) { + jd.append(2); + } + if (ui->jd4->isChecked()) { + jd.append(3); + } + if (jd.isEmpty()) { + QMessageBox::warning(this, "警告", "请至少选择一个基带"); + return; + } + + //获取时间 + QDateTime beginTime = ui->beginTime->dateTime(); + QDateTime endTime = ui->endTime->dateTime(); + if (beginTime>endTime) { + QMessageBox::warning(this, "警告", "请选择正确的时间段"); + return; + } + + //获取参数名 + QString dataName = ui->comboBox->currentText(); + if (!Gloab::namelist.keys().contains(dataName)) { + QMessageBox::warning(this, "警告", "未找到该数据"); + return; + } + + + //传入数据绘图 + thread_polt->setValue(jd, dataName, beginTime, endTime); + Gloab::widget = new QWidget(); + Gloab::widget->setWindowTitle(dataName); + + //设置进度条 + layout = new QVBoxLayout(ui->widget); + progressBar = new QProgressBar(ui->widget); + layout->addWidget(progressBar); + ui->widget->show(); + + // 获取文件大小 + Gloab::fileSize=0; + for (int i = 0; i < jd.size(); ++i) { + Gloab::fileSize+=Gloab::g_param[jd[i]].size(); + } + Gloab::bytesRead = 0; + + thread_polt->start(); +} + diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..a7e6af8 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,68 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H +#include "gloab.h" +#include "threadread.h" + +#include +#include +#include +#include +#include + +#include "threadchart.h" +#include "threadpoltchart.h" + + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + void on_openFileBtn_clicked(); + + void clearCombo(); + void showStatusbar(const QString &message); + void setBeginTime(const QDateTime &begin); + void setEndTime(const QDateTime &begin); + void addCombo(const QStringList &list); + void setProgressBar(int percent); + void closeProg(); + + void newCandS(); + void appSeries(qreal A,qreal B); + void setChartView(int jd,bool isEnum); + void setWidget(); + + void newPlotCandS(); + void setPlotChartView(int jd,bool isEnum); + + void on_lineChart_clicked(); + + bool isNumeric(const QString &str); + + void on_plotChart_clicked(); + +private: + Ui::MainWindow *ui; + QLabel *m_versionLabel; + threadRead *thread_read; + ThreadChart *thread_chart; + threadPoltChart *thread_polt; + + QProgressBar *progressBar; + QVBoxLayout *layout; + QChart *chart; + QLineSeries *series; + +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..f4565fd --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,294 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + + + 14 + + + + 时间图 + + + + + + + + 12 + + + + 开始时间 + + + + + + + 14 + + + + yyyy/MM/dd HH:mm:ss + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 12 + + + + 选择基带 + + + + + + + 14 + + + + 基带1 + + + + + + + + 14 + + + + 基带4 + + + + + + + + 14 + + + + 基带3 + + + + + + + + 14 + + + + 基带2 + + + + + + + + + + + 12 + + + + 数据 + + + + + + true + + + + 14 + + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 12 + + + + 结束时间 + + + + + + + 14 + + + + yyyy/MM/dd HH:mm:ss + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + 14 + + + + 数据变化图 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 14 + + + + 打开文件 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 0 + 0 + 800 + 20 + + + + + + + + diff --git a/threadchart.cpp b/threadchart.cpp new file mode 100644 index 0000000..4a31f71 --- /dev/null +++ b/threadchart.cpp @@ -0,0 +1,82 @@ +#include "threadchart.h" +#include + +ThreadChart::ThreadChart(QObject *parent) + : QThread{parent} { +} + +void ThreadChart::setValue(QVector jd, QString dataName, QDateTime beginTime, QDateTime endTime) { + this->jd = jd; + this->dataName = dataName; + this->beginTime = beginTime; + this->endTime = endTime; +} + + +void ThreadChart::run() { + Gloab::m_chartViews.clear(); + Gloab::rule.clear(); + Gloab::rule.append("状态"); + //判断右侧数据是否为数字型 + bool isEnum = Gloab::namelist[dataName]; + for (int i = 0; i < jd.size(); ++i) { + emit newCandS(); + qreal y = 114.514; + QString tem1 = "无数据"; + // 为每个图表添加数据 + if (isEnum) { + for (int j = 0; j < Gloab::g_param[jd[i]].size(); j++) { + //更新进度条 + Gloab::bytesRead++; + int percent = Gloab::bytesRead * 100 / Gloab::fileSize; + emit setProgressBar(percent); + + QDateTime temTime = QDateTime::fromString(Gloab::g_param[jd[i]][j]["时间"], "yyyy-MM-dd hh:mm:ss:zzz"); + if (temTime >= beginTime && temTime < endTime) { + if (!Gloab::g_param[jd[i]][j].contains(dataName)) { + if (y != 114.514) { + emit appSeries(temTime.toMSecsSinceEpoch(), y); + } + } else { + if (Gloab::g_param[jd[i]][j][dataName].contains(".")) { + y = Gloab::g_param[jd[i]][j][dataName].toDouble(); + emit appSeries(temTime.toMSecsSinceEpoch(), y); + } else { + y = Gloab::g_param[jd[i]][j][dataName].toLongLong(); + emit appSeries(temTime.toMSecsSinceEpoch(), y); + } + } + } + } + } else { + for (int j = 0; j < Gloab::g_param[jd[i]].size(); j++) { + //更新进度条 + Gloab::bytesRead++; + int percent = Gloab::bytesRead * 100 / Gloab::fileSize; + emit setProgressBar(percent); + + QDateTime temTime = QDateTime::fromString(Gloab::g_param[jd[i]][j]["时间"], "yyyy-MM-dd hh:mm:ss:zzz"); + if (temTime >= beginTime && temTime < endTime) { + if (!Gloab::g_param[jd[i]][j].contains(dataName)) { + if (tem1 != "无数据") { + if (!Gloab::rule.contains(tem1)) { + Gloab::rule.append(tem1); + } + emit appSeries(temTime.toMSecsSinceEpoch(), Gloab::rule.indexOf(tem1)); + } + } else { + tem1 = Gloab::g_param[jd[i]][j][dataName]; + if (!Gloab::rule.contains(tem1)) { + Gloab::rule.append(tem1); + } + emit appSeries(temTime.toMSecsSinceEpoch(), Gloab::rule.indexOf(tem1)); + } + } + } + } + emit setChartView(jd[i], isEnum); + } + + emit setWidget(); + quit(); +} diff --git a/threadchart.h b/threadchart.h new file mode 100644 index 0000000..553bbd7 --- /dev/null +++ b/threadchart.h @@ -0,0 +1,44 @@ +#ifndef THREADCHART_H +#define THREADCHART_H + +#include +#include +#include +#include +using namespace QtCharts; +#include +#include +#include +#include +#include + + +#include "gloab.h" + +class ThreadChart : public QThread { + Q_OBJECT + +public: + explicit ThreadChart(QObject *parent = nullptr); + + void setValue(QVector jd, QString dataName, QDateTime beginTime, QDateTime endTime); + + +signals: + void newCandS(); + void appSeries(qreal A,qreal B); + void setChartView(int jd,bool isEnum); + void setWidget(); + void setProgressBar(int percent); + +protected: + void run() override; + +private: + QVector jd; + QDateTime beginTime; + QDateTime endTime; + QString dataName; +}; + +#endif // THREADCHART_H diff --git a/threadpoltchart.cpp b/threadpoltchart.cpp new file mode 100644 index 0000000..247ed58 --- /dev/null +++ b/threadpoltchart.cpp @@ -0,0 +1,87 @@ +#include "threadpoltchart.h" +#include + +threadPoltChart::threadPoltChart(QObject *parent) + : QThread{parent} { +} + +void threadPoltChart::setValue(QVector jd, QString dataName, QDateTime beginTime, QDateTime endTime) { + this->jd = jd; + this->dataName = dataName; + this->beginTime = beginTime; + this->endTime = endTime; +} + + + +void threadPoltChart::run() { + Gloab::m_chartViews.clear(); + Gloab::rule.clear(); + Gloab::rule.append("状态"); + for (int i = 0; i < jd.size(); ++i) { + int X = 1; + emit newCandS(); + + // 为每个图表添加数据 + //判断右侧数据是否为数字型 + bool isEnum = Gloab::namelist[dataName]; + if (dataName.contains("版本号")) { + isEnum = false; + } + if (isEnum) { + for (int j = 0; j < Gloab::g_param[jd[i]].size(); j++) { + //更新进度条 + Gloab::bytesRead++; + int percent = Gloab::bytesRead * 100 / Gloab::fileSize; + emit setProgressBar(percent); + + if (Gloab::g_param[jd[i]][j].keys().size()<=deleteName.size()) { + bool f=true; + for(auto key : Gloab::g_param[jd[i]][j].keys()) { + if (!deleteName.contains(key)) { + f=false; + break; + } + } + if (f) { + continue; + } + } + + + QDateTime temTime = QDateTime::fromString(Gloab::g_param[jd[i]][j]["时间"], "yyyy-MM-dd hh:mm:ss:zzz"); + if (temTime >= beginTime && temTime < endTime) { + if (Gloab::g_param[jd[i]][j].contains(dataName)) { + if (Gloab::g_param[jd[i]][j][dataName].contains(".")) { + emit appSeries(X++, Gloab::g_param[jd[i]][j][dataName].toDouble()); + } else { + emit appSeries(X++, Gloab::g_param[jd[i]][j][dataName].toLongLong()); + } + } + } + } + } else { + for (int j = 0; j < Gloab::g_param[jd[i]].size(); j++) { + //更新进度条 + Gloab::bytesRead++; + int percent = Gloab::bytesRead * 100 / Gloab::fileSize; + emit setProgressBar(percent); + + QDateTime temTime = QDateTime::fromString(Gloab::g_param[jd[i]][j]["时间"], "yyyy-MM-dd hh:mm:ss:zzz"); + if (temTime >= beginTime && temTime < endTime) { + if (Gloab::g_param[jd[i]][j].contains(dataName)) { + QString tem1 = Gloab::g_param[jd[i]][j][dataName]; + if (!Gloab::rule.contains(tem1)) { + Gloab::rule.append(tem1); + } + emit appSeries(X++, Gloab::rule.indexOf(tem1)); + } + } + } + } + emit setChartView(jd[i], isEnum); + } + + emit setWidget(); + quit(); +} diff --git a/threadpoltchart.h b/threadpoltchart.h new file mode 100644 index 0000000..2ddb65f --- /dev/null +++ b/threadpoltchart.h @@ -0,0 +1,49 @@ +#ifndef THREADPOLTCHART_H +#define THREADPOLTCHART_H + +#include +#include +#include +#include +using namespace QtCharts; +#include +#include +#include +#include +#include + + +#include "gloab.h" + +class threadPoltChart : public QThread { + Q_OBJECT + +public: + explicit threadPoltChart(QObject *parent = nullptr); + + void setValue(QVector jd, QString dataName, QDateTime beginTime, QDateTime endTime ); + + +signals: + void newCandS(); + + void appSeries(qreal A, qreal B); + + void setChartView(int jd, bool isEnum); + + void setWidget(); + + void setProgressBar(int percent); + +protected: + void run() override; + +private: + QVector jd; + QDateTime beginTime; + QDateTime endTime; + QString dataName; + QStringList deleteName; +}; + +#endif // THREADPOLTCHART_H diff --git a/threadread.cpp b/threadread.cpp new file mode 100644 index 0000000..37e8f11 --- /dev/null +++ b/threadread.cpp @@ -0,0 +1,121 @@ +#include "threadread.h" + +threadRead::threadRead(QObject *parent) + : QThread{parent} { +} + +bool threadRead::isNumeric(QString data) { + // 正则表达式匹配数字和可选的正负号 + QRegularExpression pattern("^[+-]?([1-9][0-9]*|0)[.]?[0-9]*$"); + QRegularExpressionMatch patternMatch =pattern.match(data); + // 使用std::regex_match来检查字符串是否完全匹配模式 + return patternMatch.hasMatch(); +} + +void threadRead::run() { + //正则表达式 + //时间 + QRegularExpression dateTimeRegex("([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{3})"); + QRegularExpressionMatch matchDateTime; + //基带 + QRegularExpression jdRegex("\\[.*(\\d)\\]"); + QRegularExpressionMatch matchLogLevel; + + + //初始化数据 + for (auto &i: Gloab::g_param) { + i.clear(); + } + //清除下拉框数据 + emit clearCombo(); + if(!Gloab::namelist.empty()){ + Gloab::namelist.clear(); + Gloab::completer->deleteLater(); + } + + //设置状态栏 + emit showStatusbar("正在打开文件"); + + //读取文件 + QTextStream in(&Gloab::file); + while (!in.atEnd()) { + //读取一行 + QString line = in.readLine(); + + //更新进度条 + Gloab::bytesRead += line.size(); + int percent = Gloab::bytesRead * 150 / Gloab::fileSize; + emit setProgressBar(percent); + + + /* 匹配数据 */ + //匹配日期时间 + QMap temMap; + int JD; + QString temtime; + QString temjd; + matchDateTime = dateTimeRegex.match(line); + if (matchDateTime.hasMatch()) { + temtime = matchDateTime.captured(1); + temMap["时间"] = temtime; + } else { + continue; + } + //匹配基带 + matchLogLevel = jdRegex.match(line); + if (matchLogLevel.hasMatch()) { + temjd = matchLogLevel.captured(1); + temMap["基带"] = temjd; + JD = temjd.toInt() - 1; + } else { + continue; + } + + //设置开始时间 + if (Gloab::temData.isEmpty()) { + emit setBeginTime(QDateTime::fromString(temtime, "yyyy-MM-dd hh:mm:ss:zzz")); + } + Gloab::temData.clear(); + Gloab::temData["时间"] = temtime; + //将左右拆分 + QStringList dataParts = line.split(']'); + //判断右侧是否有数据 + if (dataParts[1].isEmpty()) { + continue; + } + //将右侧数据拆分 + QStringList data = dataParts[1].split(','); + for (int i = 0; i < data.size(); i++) { + //将每一条数据拆为数据名和值 + QStringList tem = data[i].split('='); + if (tem.size() < 2) { + continue; + } + if (!Gloab::namelist.contains(tem[0])) { + Gloab::namelist[tem[0]]=isNumeric(tem[1]); + if (tem[0].contains("版本号")) { + Gloab::namelist[tem[0]] = false; + } + } + Gloab::temData[tem[0]] = tem[1]; + } + //记录数据 + Gloab::g_param[JD].append(Gloab::temData); + + } + + //设置结束时间 + emit setEndTime(QDateTime::fromString(Gloab::temData["时间"], "yyyy-MM-dd hh:mm:ss:zzz")); + + //设置状态栏 + emit showStatusbar("打开成功:" + Gloab::fileName); + + //添加下拉框数据 + emit addCombo(Gloab::namelist.keys()); + + //关闭 + emit closeProg(); + Gloab::file.close(); + Gloab::temData.clear(); + quit(); +} diff --git a/threadread.h b/threadread.h new file mode 100644 index 0000000..1e7621c --- /dev/null +++ b/threadread.h @@ -0,0 +1,31 @@ +#ifndef THREADREAD_H +#define THREADREAD_H + +#include "gloab.h" + +#include + +class threadRead : public QThread { + Q_OBJECT + +public: + explicit threadRead(QObject *parent = nullptr); + bool isNumeric(QString data); + +signals: + void clearCombo(); + void showStatusbar(QString message); + void setBeginTime(QDateTime begin); + void setEndTime(QDateTime begin); + void addCombo(QStringList list); + void setProgressBar(int percent); + void closeProg(); + +private: + + +protected: + void run() Q_DECL_OVERRIDE; +}; + +#endif // THREADREAD_H