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 
72  explicit plot(const plot &other)
73  : _series(other.serie())
74  {
75  setName(other.name());
76  }
77 
79  {
80  delete _series;// Series will be deleted with chart
81  }
82 
83  void pushPoint(float value)
84  {
85  QDateTime now = QDateTime::currentDateTime();
86  _series->append(now.toMSecsSinceEpoch(), value);
87  }
88 
89  void setName(const QString &name)
90  {
91  _name = name;
92  _series->setName(_name);
93 
94  // Add 3 initial points to plot
95  QDateTime now = QDateTime::currentDateTime();
96  _series->append(now.toMSecsSinceEpoch() - 2 * 60e3, 0.0);
97  _series->append(now.toMSecsSinceEpoch() - 60e3, 0.0);
98  _series->append(now.toMSecsSinceEpoch(), 0.0);
99  }
100 
101  QLineSeries *serie() const
102  {
103  return _series;
104  }
105 
106  QString name() const
107  {
108  return _name;
109  }
110 
111  private:
112  QLineSeries *_series;
113  QString _name;
114  };
118  void update();
119 
120  QChartView *_chart;
121  QDateTimeAxis *_axisX;
122  QValueAxis *_axisY;
123  QMap<QString, plot*> _plots;
125 };
Definition: plotwidget.h:65
void setName(const QString &name)
Definition: plotwidget.h:89
plot()
Definition: plotwidget.h:67
QString name() const
Definition: plotwidget.h:106
plot(const plot &other)
Definition: plotwidget.h:72
void pushPoint(float value)
Definition: plotwidget.h:83
QString _name
Definition: plotwidget.h:113
~plot()
Definition: plotwidget.h:78
QLineSeries * serie() const
Definition: plotwidget.h:101
QLineSeries * _series
Definition: plotwidget.h:112
PlotWidget Show a graph of the temperature over time.
Definition: plotwidget.h:19
QValueAxis * _axisY
Definition: plotwidget.h:122
~PlotWidget()=default
QChartView * _chart
Definition: plotwidget.h:120
int m_maximumPoints
Definition: plotwidget.h:124
QMap< QString, plot * > _plots
Definition: plotwidget.h:123
QDateTimeAxis * _axisX
Definition: plotwidget.h:121