完成时间图绘制
This commit is contained in:
142
mainwindow.cpp
142
mainwindow.cpp
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow), readThread(new ReadThread) {
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow), readThread(new ReadThread), customTime(new CustomTimeThread) {
|
||||
ui->setupUi(this);
|
||||
// 创建版本号标签并添加到状态栏的右端
|
||||
QLabel *m_versionLabel = new QLabel(tr("v1.2.0"), this);
|
||||
@ -25,6 +25,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(readThread, &ReadThread::setEndTime, this, &MainWindow::setEndTime);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
@ -56,7 +62,69 @@ void MainWindow::on_openFileBtn_clicked() {
|
||||
|
||||
|
||||
void MainWindow::on_timeCustomBtn_clicked() {
|
||||
ui->progressBar->close();
|
||||
if (file.fileName().isEmpty()) {
|
||||
QMessageBox::warning(this, "警告", "请先打开一个日志");
|
||||
return;
|
||||
}
|
||||
|
||||
//关闭打开的窗口
|
||||
if (widget) {
|
||||
widget->close();
|
||||
delete widget;
|
||||
widget = nullptr;
|
||||
}
|
||||
|
||||
//获取基带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;
|
||||
}
|
||||
|
||||
//获取时间
|
||||
beginTime = ui->beginTimeEdit->dateTime();
|
||||
endTime = ui->endTimeEdit->dateTime();
|
||||
if (beginTime > endTime) {
|
||||
QMessageBox::warning(this, "警告", "请选择正确的时间段");
|
||||
return;
|
||||
}
|
||||
//获取参数名
|
||||
QString dataName = ui->comboBox->currentText();
|
||||
if (!namelist.keys().contains(dataName)) {
|
||||
QMessageBox::warning(this, "警告", "未找到该数据");
|
||||
return;
|
||||
}
|
||||
|
||||
//传入数据绘图
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@ -97,3 +165,73 @@ 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);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user