更改为QCustplot
This commit is contained in:
107
mainwindow.cpp
107
mainwindow.cpp
@ -1,6 +1,7 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include "lib/qcustomplot.h"
|
||||
|
||||
#include "./ui_mainwindow.h"
|
||||
|
||||
@ -23,15 +24,11 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
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);
|
||||
@ -94,7 +91,6 @@ void MainWindow::addCombo(const QStringList &list) {
|
||||
|
||||
void MainWindow::setProgressBar(int percent) {
|
||||
progressBar->setValue(percent);
|
||||
// qApp->processEvents(); // 更新UI
|
||||
}
|
||||
|
||||
void MainWindow::closeProg() {
|
||||
@ -103,76 +99,30 @@ void MainWindow::closeProg() {
|
||||
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<QAbstractAxis *> 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);
|
||||
QCustPlot *qCustPlot = new QCustPlot(Gloab::xData, Gloab::yData, jd, isEnum, true);
|
||||
// 将qCustPlot添加到容器中
|
||||
Gloab::m_QCView.append(qCustPlot);
|
||||
}
|
||||
|
||||
void MainWindow::setWidget() {
|
||||
// 设置布局
|
||||
int wide = 850;
|
||||
int hight = 600;
|
||||
if (Gloab::m_chartViews.size() > 1) {
|
||||
if (Gloab::m_QCView.size() > 1) {
|
||||
wide = 1800;
|
||||
}
|
||||
QGridLayout *gridLayout = new QGridLayout(Gloab::widget);
|
||||
for (int i = 0, j = 0; i < Gloab::m_chartViews.size(); i++) {
|
||||
for (int i = 0, j = 0; i < Gloab::m_QCView.size(); i++) {
|
||||
if (i != 0 && i % 2 == 0) {
|
||||
j++;
|
||||
hight += 350;
|
||||
}
|
||||
gridLayout->addWidget(Gloab::m_chartViews[i], j, i - 2 * j);
|
||||
gridLayout->addWidget(Gloab::m_QCView[i], j, i - 2 * j);
|
||||
}
|
||||
Gloab::widget->resize(wide, hight);
|
||||
// Gloab::widget->setMaximumHeight(950);
|
||||
|
||||
Gloab::widget->move(70, 20);
|
||||
Gloab::widget->show();
|
||||
|
||||
@ -181,48 +131,13 @@ void MainWindow::setWidget() {
|
||||
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<QAbstractAxis *> 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);
|
||||
QCustPlot *qCustPlot = new QCustPlot(Gloab::xData, Gloab::yData, jd, isEnum, false);
|
||||
// 将qCustPlot添加到容器中
|
||||
Gloab::m_QCView.append(qCustPlot);
|
||||
}
|
||||
|
||||
void MainWindow::on_lineChart_clicked() {
|
||||
|
Reference in New Issue
Block a user