250 lines
6.8 KiB
C++
250 lines
6.8 KiB
C++
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
#include <QDebug>
|
|
#include <QCompleter>
|
|
#include <QLabel>
|
|
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent), ui(new Ui::MainWindow), readThread(new ReadThread), customTime(new CustomThread) {
|
|
ui->setupUi(this);
|
|
// 创建版本号标签并添加到状态栏的右端
|
|
QLabel *m_versionLabel = new QLabel(tr("v1.3.0"), this);
|
|
ui->statusbar->addPermanentWidget(m_versionLabel);
|
|
//隐藏进度条
|
|
ui->progressBar->close();
|
|
|
|
/*信号和槽*/
|
|
//readThread
|
|
connect(readThread, &ReadThread::clearCombo, this, &MainWindow::clearCombo);
|
|
connect(readThread, &ReadThread::showStatusbar, this, &MainWindow::showStatusbar);
|
|
connect(readThread, &ReadThread::setProgressBar, this, &MainWindow::setProgressBar);
|
|
connect(readThread, &ReadThread::setTime, this, &MainWindow::setTime);
|
|
connect(readThread, &ReadThread::addCombo, this, &MainWindow::addCombo);
|
|
connect(readThread, &ReadThread::closeProg, this, &MainWindow::closeProg);
|
|
|
|
//customTime
|
|
connect(customTime, &CustomThread::setProgressBar, this, &MainWindow::setProgressBar);
|
|
connect(customTime, &CustomThread::setPlotView, this, &MainWindow::setPlotView);
|
|
connect(customTime, &CustomThread::setWidget, this, &MainWindow::setWidget);
|
|
|
|
}
|
|
|
|
MainWindow::~MainWindow() {
|
|
delete ui;
|
|
}
|
|
|
|
|
|
void MainWindow::on_openFileBtn_clicked() {
|
|
//选择文件,并获取文件名
|
|
QString fileName = QFileDialog::getOpenFileName();
|
|
//打开文件
|
|
file.setFileName(fileName);
|
|
//打开失败
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
QMessageBox::warning(this, "错误", "文件打开失败");
|
|
ui->statusbar->clearMessage();
|
|
clearCombo();
|
|
return;
|
|
}
|
|
//获取文件大小
|
|
qint64 fileSize = file.size();
|
|
//设置进度条
|
|
ui->progressBar->setMaximum((int) fileSize);
|
|
ui->progressBar->setValue(0);
|
|
ui->progressBar->show();
|
|
//执行读取
|
|
readThread->start();
|
|
}
|
|
|
|
|
|
void MainWindow::on_timeCustomBtn_clicked() {
|
|
//校验数据
|
|
if (!inspectionData()) { return; }
|
|
|
|
//运行线程
|
|
customTime->setIsTime(true);
|
|
customTime->start();
|
|
}
|
|
|
|
|
|
void MainWindow::on_dataCustomBtn_clicked() {
|
|
//校验数据
|
|
if (!inspectionData()) { return; }
|
|
|
|
//运行线程
|
|
customTime->setIsTime(false);
|
|
customTime->start();
|
|
}
|
|
|
|
bool MainWindow::inspectionData() {
|
|
//关闭打开的窗口
|
|
if (widget) {
|
|
widget->close();
|
|
delete widget;
|
|
widget = nullptr;
|
|
}
|
|
//判断是否已打开日志文件
|
|
if (file.fileName().isEmpty()) {
|
|
QMessageBox::warning(this, "警告", "请先打开一个日志");
|
|
return false;
|
|
}
|
|
//获取基带id
|
|
QVector<int> 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 false;
|
|
}
|
|
//获取时间
|
|
beginTime = ui->beginTimeEdit->dateTime();
|
|
endTime = ui->endTimeEdit->dateTime();
|
|
//判断时间是否合法
|
|
if (beginTime > endTime) {
|
|
QMessageBox::warning(this, "警告", "请选择正确的时间段");
|
|
return false;
|
|
}
|
|
//获取参数名
|
|
QString dataName = ui->comboBox->currentText();
|
|
//判断参数名是否正确
|
|
if (!namelist.keys().contains(dataName)) {
|
|
QMessageBox::warning(this, "警告", "未找到该数据");
|
|
return false;
|
|
}
|
|
//创建新窗口
|
|
widget = new QWidget();
|
|
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;
|
|
}
|
|
|
|
void MainWindow::clearCombo() {
|
|
ui->comboBox->clear();
|
|
}
|
|
|
|
void MainWindow::showStatusbar(const QString &str) {
|
|
ui->statusbar->showMessage(str);
|
|
}
|
|
|
|
void MainWindow::setProgressBar(int bytesRead) {
|
|
ui->progressBar->setValue(bytesRead);
|
|
}
|
|
|
|
void MainWindow::setTime() {
|
|
ui->beginTimeEdit->setDateTime(beginTime);
|
|
ui->endTimeEdit->setDateTime(endTime);
|
|
}
|
|
|
|
void MainWindow::addCombo(const QStringList &names) {
|
|
//设置下拉框数据
|
|
ui->comboBox->addItems(names);
|
|
//根据输入匹配下拉框
|
|
completer = new QCompleter(names);
|
|
completer->setFilterMode(Qt::MatchContains);
|
|
ui->comboBox->setCompleter(completer);
|
|
}
|
|
|
|
void MainWindow::closeProg() {
|
|
ui->progressBar->close();
|
|
}
|
|
|
|
void MainWindow::setPlotView(int jd, bool isNum, bool isTime) {
|
|
QCustomPlot *qCustomPlot = new QCustomPlot();
|
|
|
|
//标题
|
|
QCPTextElement *m_title;
|
|
qCustomPlot->plotLayout()->insertRow(0);
|
|
m_title = new QCPTextElement(qCustomPlot, QString("基带 %1").arg(jd + 1));
|
|
qCustomPlot->plotLayout()->addElement(0, 0, m_title);
|
|
|
|
// X轴
|
|
if (isTime) {
|
|
QSharedPointer<QCPAxisTickerDateTime> timeTicker(new QCPAxisTickerDateTime);
|
|
timeTicker->setDateTimeFormat("hh:mm:ss");
|
|
qCustomPlot->xAxis->setTicker(timeTicker);
|
|
}
|
|
|
|
// Y轴
|
|
if (!isNum) {
|
|
QVector<double> ticks;
|
|
QVector<QString> labels;
|
|
for (int i = 0; i < rule.size(); ++i) {
|
|
ticks.append(i);
|
|
labels.append(rule[i]);
|
|
}
|
|
QSharedPointer<QCPAxisTickerText> textTicker(new QCPAxisTickerText);
|
|
textTicker->addTicks(ticks, labels);
|
|
qCustomPlot->yAxis->setTicker(textTicker);
|
|
} else {
|
|
// qCustomPlot->yAxis->setNumberFormat("f"); //以数字形式显示
|
|
// qCustomPlot->yAxis->setNumberPrecision(2); //显示两位小数
|
|
}
|
|
|
|
// 添加图形
|
|
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());
|
|
}
|
|
|
|
m_PlotView.append(qCustomPlot);
|
|
}
|
|
|
|
void MainWindow::setWidget() {
|
|
// 设置布局
|
|
int wide = 850;
|
|
int hight = 600;
|
|
if (m_PlotView.size() > 1) {
|
|
wide = 1800;
|
|
}
|
|
QGridLayout *gridLayout = new QGridLayout(widget);
|
|
for (int i = 0, j = 0; i < m_PlotView.size(); i++) {
|
|
if (i != 0 && i % 2 == 0) {
|
|
j++;
|
|
hight += 350;
|
|
}
|
|
gridLayout->addWidget(m_PlotView[i], j, i - 2 * j);
|
|
}
|
|
widget->resize(wide, hight);
|
|
widget->move(70, 20);
|
|
widget->show();
|
|
|
|
ui->progressBar->close();
|
|
}
|
|
|