AtCore  1.0.72
AtCore is a API to manage the serial connection between the computer and 3D Printers.
plotwidget.h
Go to the documentation of this file.
1 /* AtCore KDE Libary for 3D Printers
2  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
3  SPDX-FileCopyrightText: 2017 Patrick José Pereira <patrickjp@kde.org>
4  SPDX-FileCopyrightText: 2017-2018, 2020 Chris Rizzitello <rizzitello@kde.org>
5 */
6 
7 #pragma once
8 
9 #include <QChartView>
10 #include <QWidget>
11 #include <QtCharts>
12 
13 #include "atcorewidgets_export.h"
14 
18 class ATCOREWIDGETS_EXPORT PlotWidget : public QWidget
19 {
20  Q_OBJECT
21 
22 public:
23  explicit PlotWidget(QWidget *parent = nullptr);
24  ~PlotWidget() = default;
25 
30  void addPlot(const QString &name);
31 
36  void removePlot(const QString &name);
37 
43  void appendPoint(const QString &name, float value);
44 
49  QStringList plots();
50 
55  void setMaximumPoints(const int newMax);
56 
61  void setMaximumTemperature(const uint maxTemp);
62 
63 private:
64  class plot
65  {
66  public:
67  explicit plot()
68  : _series(new QLineSeries())
69  {
70  }
71 
73  {
74  // Series will be deleted with chart
75  }
76 
77  void pushPoint(float value)
78  {
79  QDateTime now = QDateTime::currentDateTime();
80  _series->append(now.toMSecsSinceEpoch(), value);
81  }
82 
83  void setName(const QString &name)
84  {
85  _name = name;
86  _series->setName(_name);
87 
88  // Add 3 initial points to plot
89  QDateTime now = QDateTime::currentDateTime();
90  _series->append(now.toMSecsSinceEpoch() - 2 * 60e3, 0.0);
91  _series->append(now.toMSecsSinceEpoch() - 60e3, 0.0);
92  _series->append(now.toMSecsSinceEpoch(), 0.0);
93  }
94 
95  QLineSeries *serie() const
96  {
97  return _series;
98  }
99 
100  QString name() const
101  {
102  return _name;
103  }
104 
105  private:
106  QLineSeries *_series;
107  QString _name;
108  };
112  void update();
113 
114  QChartView *_chart;
115  QDateTimeAxis *_axisX;
116  QValueAxis *_axisY;
117  QMap<QString, plot> _plots;
119 };
PlotWidget::plot::setName
void setName(const QString &name)
Definition: plotwidget.h:83
PlotWidget::m_maximumPoints
int m_maximumPoints
Definition: plotwidget.h:118
PlotWidget::plot::serie
QLineSeries * serie() const
Definition: plotwidget.h:95
PlotWidget::_plots
QMap< QString, plot > _plots
Definition: plotwidget.h:117
PlotWidget
PlotWidget Show a graph of the temperature over time.
Definition: plotwidget.h:18
PlotWidget::plot::_series
QLineSeries * _series
Definition: plotwidget.h:106
PlotWidget::_axisX
QDateTimeAxis * _axisX
Definition: plotwidget.h:115
PlotWidget::_chart
QChartView * _chart
Definition: plotwidget.h:114
PlotWidget::plot::pushPoint
void pushPoint(float value)
Definition: plotwidget.h:77
PlotWidget::plot::~plot
~plot()
Definition: plotwidget.h:72
PlotWidget::plot::_name
QString _name
Definition: plotwidget.h:107
PlotWidget::_axisY
QValueAxis * _axisY
Definition: plotwidget.h:116
PlotWidget::plot::plot
plot()
Definition: plotwidget.h:67
PlotWidget::plot::name
QString name() const
Definition: plotwidget.h:100
PlotWidget::plot
Definition: plotwidget.h:64