-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosziview.cpp
93 lines (77 loc) · 2.72 KB
/
osziview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "osziview.h"
#include "ui_osziview.h"
#include <QChartView>
#include <QDebug>
OsziView::OsziView(QWidget * parent)
: QWidget(parent)
, ui(new Ui::OsziView)
{
ui->setupUi(this);
this->series = new QT_CHARTS_NAMESPACE::QLineSeries;
this->chart = new QT_CHARTS_NAMESPACE::QChart();
this->chartView = new QT_CHARTS_NAMESPACE::QChartView(this->chart);
this->chartView->setRubberBand(this->chartView->HorizontalRubberBand);
this->chartView->setRenderHint(QPainter::Antialiasing);
this->ui->graph_Layout->addWidget(chartView);
this->chart->setAnimationOptions(QT_CHARTS_NAMESPACE::QChart::SeriesAnimations);
this->chart->setAnimationDuration(100);
this->chart->legend()->hide();
this->chart->setAcceptHoverEvents(true);
this->chart->setPlotAreaBackgroundVisible(true);
this->series->setVisible(true);
this->chart->addSeries(series);
this->axisX = new QT_CHARTS_NAMESPACE::QValueAxis;
this->axisY = new QT_CHARTS_NAMESPACE::QValueAxis;
this->chartView->chart()->addAxis(this->axisY, Qt::AlignLeft);
this->chartView->chart()->addAxis(this->axisX, Qt::AlignBottom);
this->series->attachAxis(this->axisX);
this->series->attachAxis(this->axisY);
this->seriesXIncrement = -1;
this->axisX->setTickCount(10);
this->axisX->setLabelFormat("%d");
this->axisY->setTickCount(2);
this->axisY->setMinorTickCount(1);
// this->axisX->setGridLineColor(QColor(200,200,200));
// this->axisX->setMinorGridLineColor(QColor(240,240,240));
this->axisY->setLabelFormat("%f");
// axis minimal and maximal value for autoscale by new points
this->AxisYmax = -1;
this->AxisYmin =1;
}
OsziView::~OsziView()
{
delete ui;
}
void OsziView::addValue(QString parsedReadCommand)
{
// Check for escape characters
QString rawData;
if ((!ui->escapeCmd->text().isEmpty() || ui->escapeCmd->text() == "None") && parsedReadCommand.startsWith(ui->escapeCmd->text()))
{
//remove the escape characters from command
rawData = parsedReadCommand.remove(ui->escapeCmd->text()).remove(" ");
// get new min/max value on the fly
qDebug() << rawData;
qDebug() << rawData.toDouble();
this->AxisYmax = qMax(AxisYmax, rawData.toDouble());
this->AxisYmin = qMin(AxisYmin, rawData.toDouble());
this->series->append(this->seriesXIncrement, rawData.toDouble());
int currentLength = series->points().length();
if(currentLength > 500)
{
this->axisX->setRange(currentLength-500, currentLength);
}
else
{
this->axisX->setRange(0, currentLength);
}
this->axisY->setRange(this->AxisYmin , this->AxisYmax );
this->series->setPointsVisible();
this->seriesXIncrement++;
this->chartView->update();
}
else
{
// do something else with the data ?!
}
}