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