KDeclarative

plotter.h
1 /*
2  This file is part of the KDE project
3 
4  SPDX-FileCopyrightText: 2014 Fredrik Höglund <[email protected]>
5  SPDX-FileCopyrightText: 2014 Marco Martin <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef PLASMA_PLOTTER_H
11 #define PLASMA_PLOTTER_H
12 
13 
14 #include <epoxy/gl.h>
15 
16 // qopengl.h declares GLdouble as a typedef of float when Qt is built
17 // with GLES support. This conflicts with the epoxy/gl_generated.h
18 // declaration, so we have to prevent the Qt header from being #included.
19 #define QOPENGL_H
20 
21 #ifndef QOPENGLF_APIENTRY
22 #define QOPENGLF_APIENTRY GLAPIENTRY
23 #endif
24 
25 #ifndef QOPENGLF_APIENTRYP
26 #define QOPENGLF_APIENTRYP GLAPIENTRYP
27 #endif
28 
29 #include <QQuickItem>
30 #include <QQmlListProperty>
31 #include <QPointer>
32 #include <QQuickWindow>
33 #include <QMutex>
34 
35 class PlotSGNode;
36 
43 class PlotData : public QObject
44 {
45  Q_OBJECT
49  Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
50 
51 
54  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
55 
59  Q_PROPERTY(QList<qreal> values READ values NOTIFY valuesChanged)
60 
64  Q_PROPERTY(qreal max READ max NOTIFY maxChanged)
65 
69  Q_PROPERTY(qreal min READ min NOTIFY minChanged)
70 
71 public:
72  PlotData(QObject *parent = nullptr);
73 
74  void setColor(const QColor &color);
75  QColor color() const;
76 
77  void addSample(qreal value);
78 
79  QList<qreal> values() const;
80 
81  QVector<qreal> m_normalizedValues;
82 
83  qreal max() const;
84  qreal min() const;
85 
86  void setSampleSize(int size);
87 
88  QString label() const;
89  void setLabel(const QString &label);
90 
91 Q_SIGNALS:
92  void colorChanged();
93  void valuesChanged();
94  void maxChanged();
95  void minChanged();
96  void labelChanged();
97 
98 private:
99  QString m_label;
100  QColor m_color;
101  QList<qreal> m_values;
102 
103  qreal m_min;
104  qreal m_max;
105  int m_sampleSize;
106 };
107 
108 class Plotter : public QQuickItem
109 {
110  Q_OBJECT
111  Q_PROPERTY(QQmlListProperty<PlotData> dataSets READ dataSets)
112 
113 
116  Q_PROPERTY(qreal max READ max NOTIFY maxChanged)
117 
118 
121  Q_PROPERTY(qreal min READ min NOTIFY minChanged)
122 
123 
126  Q_PROPERTY(int sampleSize READ sampleSize WRITE setSampleSize NOTIFY sampleSizeChanged)
127 
128 
131  Q_PROPERTY(bool stacked READ isStacked WRITE setStacked NOTIFY stackedChanged)
132 
133 
136  Q_PROPERTY(bool autoRange READ isAutoRange WRITE setAutoRange NOTIFY autoRangeChanged)
137 
138 
142  Q_PROPERTY(qreal rangeMax READ rangeMax WRITE setRangeMax NOTIFY rangeMaxChanged)
143 
144 
148  Q_PROPERTY(qreal rangeMin READ rangeMin WRITE setRangeMin NOTIFY rangeMinChanged)
149 
150 
153  Q_PROPERTY(QColor gridColor READ gridColor WRITE setGridColor NOTIFY gridColorChanged)
154 
155 
156 
163  Q_PROPERTY(int horizontalGridLineCount READ horizontalGridLineCount WRITE setHorizontalGridLineCount NOTIFY horizontalGridLineCountChanged)
164 
165  //Q_CLASSINFO("DefaultProperty", "dataSets")
166 
167 public:
168  Plotter(QQuickItem *parent = nullptr);
169  ~Plotter();
170 
171  qreal max() const;
172  qreal min() const;
173 
174  int sampleSize() const;
175  void setSampleSize(int size);
176 
177  bool isStacked() const;
178  void setStacked(bool stacked);
179 
180  bool isAutoRange() const;
181  void setAutoRange(bool autorange);
182 
183  qreal rangeMax() const;
184  void setRangeMax(qreal max);
185 
186  qreal rangeMin() const;
187  void setRangeMin(qreal min);
188 
189  void setHorizontalGridLineCount(int count);
190  int horizontalGridLineCount();
191 
192  void setGridColor(const QColor &color);
193  QColor gridColor() const;
194 
195  QQmlListProperty<PlotData> dataSets();
196  static void dataSet_append(QQmlListProperty<PlotData> *list, PlotData *item);
197  static int dataSet_count(QQmlListProperty<PlotData> *list);
198  static PlotData *dataSet_at(QQmlListProperty<PlotData> *list, int pos);
199  static void dataSet_clear(QQmlListProperty<PlotData> *list);
200 
201  Q_INVOKABLE void addSample(qreal value);
202  Q_INVOKABLE void addSample(const QList<qreal> &value);
203 
204 protected:
205  void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
206 
207 private:
208  QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override final;
209  QPainterPath interpolate(const QVector<qreal> &p, qreal x0, qreal x1) const;
210  void normalizeData();
211 
212 Q_SIGNALS:
213  void maxChanged();
214  void minChanged();
215  void sampleSizeChanged();
216  void stackedChanged();
217  void autoRangeChanged();
218  void rangeMaxChanged();
219  void rangeMinChanged();
220  void gridColorChanged();
221  void horizontalGridLineCountChanged();
222 
223 private Q_SLOTS:
224  void render();
225 
226 private:
227  QList<PlotData *> m_plotData;
228 
229  GLuint m_fbo = 0;
230  PlotSGNode *m_node = nullptr;
231  qreal m_min;
232  qreal m_max;
233  qreal m_rangeMax;
234  qreal m_rangeMin;
235  int m_sampleSize;
236  int m_horizontalLineCount;
237  bool m_stacked;
238  bool m_autoRange;
239  QColor m_gridColor;
240 
241  QMatrix4x4 m_matrix;
242  bool m_initialized = false;
243  bool m_haveMSAA;
244  bool m_haveFramebufferBlit;
245  bool m_haveInternalFormatQuery;
246  GLenum m_internalFormat;
247  int m_samples;
248  QPointer <QQuickWindow> m_window;
249  QMutex m_mutex;
250 };
251 
252 #endif
Q_SIGNALSQ_SIGNALS
Q_OBJECTQ_OBJECT
qreal min
Minimum value of this data set.
Definition: plotter.h:69
a Plotter can draw a graph of values arriving from an arbitrary number of data sources to show their ...
Definition: plotter.h:43
Q_PROPERTY(...)
Q_INVOKABLEQ_INVOKABLE
Q_SLOTSQ_SLOTS
QObject * parent() const const
qreal max
Maximum value of this data set.
Definition: plotter.h:64
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 22:44:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.