AtCore  1.0.70
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 /* Atelier KDE Printer Host for 3D Printing
2  Copyright (C) <2016>
3  Author: Patrick José Pereira - patrickjp@kde.org
4  Tomaz Canabrava <tcanabrava@kde.org>
5  Lays Rodrigues <lays.rodrigues@kde.org>
6  Chris Rizzitello <rizzitello@kde.org>
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #pragma once
23 
24 #include <QChartView>
25 #include <QWidget>
26 #include <QtCharts>
27 
28 #include "atcorewidgets_export.h"
29 
33 class ATCOREWIDGETS_EXPORT PlotWidget : public QWidget
34 {
35  Q_OBJECT
36 
37 public:
38  explicit PlotWidget(QWidget *parent = nullptr);
39  ~PlotWidget() = default;
40 
45  void addPlot(const QString &name);
46 
51  void removePlot(const QString &name);
52 
58  void appendPoint(const QString &name, float value);
59 
64  QStringList plots();
65 
70  void setMaximumPoints(const int newMax);
71 
76  void setMaximumTemperature(const uint maxTemp);
77 
78 private:
79  class plot
80  {
81  public:
82  explicit plot()
83  : _series(new QLineSeries())
84  {
85  }
86 
88  {
89  // Series will be deleted with chart
90  }
91 
92  void pushPoint(float value)
93  {
94  QDateTime now = QDateTime::currentDateTime();
95  _series->append(now.toMSecsSinceEpoch(), value);
96  }
97 
98  void setName(const QString &name)
99  {
100  _name = name;
101  _series->setName(_name);
102 
103  // Add 3 initial points to plot
104  QDateTime now = QDateTime::currentDateTime();
105  _series->append(now.toMSecsSinceEpoch() - 2 * 60e3, 0.0);
106  _series->append(now.toMSecsSinceEpoch() - 60e3, 0.0);
107  _series->append(now.toMSecsSinceEpoch(), 0.0);
108  }
109 
110  QLineSeries *serie() const
111  {
112  return _series;
113  }
114 
115  QString name() const
116  {
117  return _name;
118  }
119 
120  private:
121  QLineSeries *_series;
122  QString _name;
123  };
127  void update();
128 
129  QChartView *_chart;
130  QDateTimeAxis *_axisX;
131  QValueAxis *_axisY;
132  QMap<QString, plot> _plots;
134 };
void pushPoint(float value)
Definition: plotwidget.h:92
QChartView * _chart
Definition: plotwidget.h:129
~plot()
Definition: plotwidget.h:87
int m_maximumPoints
Definition: plotwidget.h:133
QDateTimeAxis * _axisX
Definition: plotwidget.h:130
QString _name
Definition: plotwidget.h:122
Definition: plotwidget.h:79
QString name() const
Definition: plotwidget.h:115
PlotWidget Show a graph of the temperature over time.
Definition: plotwidget.h:33
QValueAxis * _axisY
Definition: plotwidget.h:131
QMap< QString, plot > _plots
Definition: plotwidget.h:132
void setName(const QString &name)
Definition: plotwidget.h:98
plot()
Definition: plotwidget.h:82
QLineSeries * _series
Definition: plotwidget.h:121
QLineSeries * serie() const
Definition: plotwidget.h:110