|
| 1 | +#include "plotrandomwidget.h" |
| 2 | + |
| 3 | +PlotRandomWidget::PlotRandomWidget(QWidget* parent) |
| 4 | + :IPlotRandomWidget (parent) |
| 5 | +{ |
| 6 | + QChartView *chartView = new QChartView(&_chart); |
| 7 | + _chart.addSeries(&_series); |
| 8 | + |
| 9 | + QValueAxis *axisX = new QValueAxis; |
| 10 | + axisX->setRange(0, _xDefaultAxsisMaximum); |
| 11 | + QValueAxis *axisY = new QValueAxis; |
| 12 | + axisY->setRange(0, 4); |
| 13 | + //_chart.addAxis(axisX, Qt::AlignBottom); |
| 14 | + //_chart.addAxis(axisY, Qt::AlignLeft); |
| 15 | + _chart.setAxisX(axisX, &_series); |
| 16 | + _chart.setAxisY(axisY, &_series); |
| 17 | + _chart.legend()->hide(); |
| 18 | + |
| 19 | + QHBoxLayout *mainLayout = new QHBoxLayout(parent); |
| 20 | + mainLayout->addWidget(chartView); |
| 21 | +} |
| 22 | + |
| 23 | +void PlotRandomWidget::addPoint(double y) |
| 24 | +{ |
| 25 | + _series.append(_xCurrent, y); |
| 26 | + //если текущее значение по оси X стало больше, чем Xscale перерисуем шкалу |
| 27 | + if(_xCurrent >= _xCurrentAxsisMaximum) |
| 28 | + { |
| 29 | + _xCurrentAxsisMaximum = _xCurrent + _xDefaultAxsisMaximum; |
| 30 | + rescaleAxsisX(_xCurrentAxsisMaximum); |
| 31 | + } |
| 32 | + |
| 33 | + const double xStep = 1; |
| 34 | + _xCurrent +=xStep; |
| 35 | +} |
| 36 | + |
| 37 | +void PlotRandomWidget::clear() |
| 38 | +{ |
| 39 | + _series.clear(); |
| 40 | + _xCurrent = 0; |
| 41 | + |
| 42 | + |
| 43 | + _xCurrentAxsisMaximum = _xDefaultAxsisMaximum; |
| 44 | + rescaleAxsisX(_xCurrentAxsisMaximum); |
| 45 | + |
| 46 | +} |
| 47 | + |
| 48 | +void PlotRandomWidget::rescaleAxsisX(double value) |
| 49 | +{ |
| 50 | + _chart.axisX()->setRange(0., value); |
| 51 | +} |
0 commit comments