|
@ -4,7 +4,7 @@ |
|
|
|
|
|
|
|
|
#include "ui_widgetplot2d.h"
|
|
|
#include "ui_widgetplot2d.h"
|
|
|
|
|
|
|
|
|
WidgetPlot2D::WidgetPlot2D(QWidget* parent) : QWidget(parent), ui(new Ui::WidgetPlot2D), time(QTime::currentTime()) { |
|
|
|
|
|
|
|
|
WidgetPlot2D::WidgetPlot2D(QWidget* parent) : QWidget(parent), ui(new Ui::WidgetPlot2D) { |
|
|
ui->setupUi(this); |
|
|
ui->setupUi(this); |
|
|
// QCP绘图初始化
|
|
|
// QCP绘图初始化
|
|
|
initQCP(); |
|
|
initQCP(); |
|
@ -19,7 +19,7 @@ WidgetPlot2D::WidgetPlot2D(QWidget* parent) : QWidget(parent), ui(new Ui::Widget |
|
|
// 滚动条设置
|
|
|
// 滚动条设置
|
|
|
ui->horizontalScrollBar->setRange(0, 0); |
|
|
ui->horizontalScrollBar->setRange(0, 0); |
|
|
// 拖动水平滚动条,图幅跟随变化
|
|
|
// 拖动水平滚动条,图幅跟随变化
|
|
|
connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(horzScrollBarChanged(int))); |
|
|
|
|
|
|
|
|
// connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(horzScrollBarChanged(int)));
|
|
|
// 默认坐标范围
|
|
|
// 默认坐标范围
|
|
|
ui->customPlot->yAxis->setRange(-20, 20); |
|
|
ui->customPlot->yAxis->setRange(-20, 20); |
|
|
ui->customPlot->replot(); |
|
|
ui->customPlot->replot(); |
|
@ -113,17 +113,29 @@ void WidgetPlot2D::initGraphName(QStringList name) { |
|
|
void WidgetPlot2D::addData(QString name, double value, int offms) { |
|
|
void WidgetPlot2D::addData(QString name, double value, int offms) { |
|
|
// 如果点击了“暂停”按钮,则不绘制图形
|
|
|
// 如果点击了“暂停”按钮,则不绘制图形
|
|
|
if (ui->pausePBtn->text() == "开始") return; |
|
|
if (ui->pausePBtn->text() == "开始") return; |
|
|
|
|
|
|
|
|
|
|
|
double key = 0; |
|
|
|
|
|
double val = value; |
|
|
|
|
|
|
|
|
|
|
|
pointCnt[nameToGraphMap[name]]++; |
|
|
|
|
|
key = pointCnt[nameToGraphMap[name]]; |
|
|
|
|
|
|
|
|
|
|
|
if (ui->autoRangeCheck->isChecked()) { |
|
|
|
|
|
ui->customPlot->rescaleAxes(); |
|
|
|
|
|
} |
|
|
|
|
|
ui->customPlot->graph(nameToGraphMap[name])->addData(key, value); |
|
|
|
|
|
ui->customPlot->xAxis->setRange(key, ui->customPlot->xAxis->range().size(), Qt::AlignRight); |
|
|
|
|
|
ui->customPlot->replot(QCustomPlot::rpQueuedReplot); |
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
// 系统当前时间 = 系统运行初始时间 + 系统运行时间
|
|
|
// 系统当前时间 = 系统运行初始时间 + 系统运行时间
|
|
|
static double start = time.hour() * 60 * 60 + time.minute() * 60 + time.second() + time.msec() / 1000.0; |
|
|
static double start = time.hour() * 60 * 60 + time.minute() * 60 + time.second() + time.msec() / 1000.0; |
|
|
double key = start + time.elapsed() / 1000.0 + offms / 1000; |
|
|
double key = start + time.elapsed() / 1000.0 + offms / 1000; |
|
|
// double start = 0;
|
|
|
|
|
|
// static int key = 0;
|
|
|
|
|
|
// key++;
|
|
|
|
|
|
// qDebug() << "start" << start;
|
|
|
|
|
|
// qDebug() << "key" << key;
|
|
|
|
|
|
|
|
|
|
|
|
// 子网格显示
|
|
|
// 子网格显示
|
|
|
ui->customPlot->xAxis->grid()->setSubGridVisible(ui->subGridCheck->isChecked()); |
|
|
ui->customPlot->xAxis->grid()->setSubGridVisible(ui->subGridCheck->isChecked()); |
|
|
ui->customPlot->yAxis->grid()->setSubGridVisible(ui->subGridCheck->isChecked()); |
|
|
ui->customPlot->yAxis->grid()->setSubGridVisible(ui->subGridCheck->isChecked()); |
|
|
|
|
|
|
|
|
// 自适应量程
|
|
|
// 自适应量程
|
|
|
if (ui->autoRangeCheck->isChecked()) { |
|
|
if (ui->autoRangeCheck->isChecked()) { |
|
|
ui->customPlot->rescaleAxes(); |
|
|
ui->customPlot->rescaleAxes(); |
|
@ -165,6 +177,7 @@ void WidgetPlot2D::addData(QString name, double value, int offms) { |
|
|
valueLabelVector[t]->setText(QString::number(valueVector[t])); |
|
|
valueLabelVector[t]->setText(QString::number(valueVector[t])); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#endif
|
|
|
//----------------------------------------------------------------------------------------//
|
|
|
//----------------------------------------------------------------------------------------//
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -235,9 +248,9 @@ void WidgetPlot2D::initQCP() { |
|
|
// 可放大缩小和移动
|
|
|
// 可放大缩小和移动
|
|
|
ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
|
ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
|
// x轴以时间形式显示
|
|
|
// x轴以时间形式显示
|
|
|
QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime); |
|
|
|
|
|
timeTicker->setTimeFormat("%h:%m:%s"); |
|
|
|
|
|
ui->customPlot->xAxis->setTicker(timeTicker); |
|
|
|
|
|
|
|
|
// QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime);
|
|
|
|
|
|
// timeTicker->setTimeFormat("%h:%m:%s");
|
|
|
|
|
|
// ui->customPlot->xAxis->setTicker(timeTicker);
|
|
|
ui->customPlot->axisRect()->setupFullAxesBox(); |
|
|
ui->customPlot->axisRect()->setupFullAxesBox(); |
|
|
ui->customPlot->replot(); |
|
|
ui->customPlot->replot(); |
|
|
} |
|
|
} |
|
@ -382,7 +395,10 @@ void WidgetPlot2D::plotOperation() { |
|
|
// 先获得每条曲线的数据指针,然后删除数据
|
|
|
// 先获得每条曲线的数据指针,然后删除数据
|
|
|
ui->customPlot->graph(i)->data()->clear(); |
|
|
ui->customPlot->graph(i)->data()->clear(); |
|
|
ui->customPlot->replot(); |
|
|
ui->customPlot->replot(); |
|
|
time = QTime::currentTime(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < 100; i++) { |
|
|
|
|
|
pointCnt[i] = 0; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (btn->text() == "整图") { |
|
|
if (btn->text() == "整图") { |
|
@ -437,10 +453,4 @@ void WidgetPlot2D::savePlotPng() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* 水平滚动条移动 */ |
|
|
/* 水平滚动条移动 */ |
|
|
void WidgetPlot2D::horzScrollBarChanged(int value) { |
|
|
|
|
|
// 若全程显示,则不移动绘图坐标
|
|
|
|
|
|
if (ui->fullShowCheck->isChecked()) return; |
|
|
|
|
|
int timeAxis = ui->timeAxisSpin->value(); |
|
|
|
|
|
ui->customPlot->xAxis->setRange(value, timeAxis, Qt::AlignRight); |
|
|
|
|
|
ui->customPlot->replot(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void WidgetPlot2D::horzScrollBarChanged(int value) {} |