-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphworker.h
69 lines (61 loc) · 1.46 KB
/
graphworker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef GRAPHWORKER_H
#define GRAPHWORKER_H
#include <QWidget>
#include <libs/qcustomplot.h>
#include <QSharedPointer>
template <class T>
struct edge
{
T min;
T max;
T bias() {
return max - min;
}
};
template <class Key, class Value>
class GraphData
{
QVector<Key> xScale;
QVector<Value> yScale;
edge<Key> xEdge;
edge<Value> yEdge;
Key border = 0;
const int lastStorageTime = 3600; // sec
const int defaultWidth = 120; // sec
int displayWidth = defaultWidth; // sec
int borderPos = 0; // position in data arrays
int minPos = 0;
int maxPos = 0;
public:
GraphData();
~GraphData();
void appendPoint(const Key &key, const Value &value);
QVector<Key> &keys();
QVector<Value> &values();
edge<Key> getKeyEdge();
edge<Value> getValueEdge();
void scroll(int angleDelta);
void autoScroll();
};
class GraphWorker : public QCustomPlot
{
Q_OBJECT
static QLabel *label;
GraphData<double, double> data_;
QElapsedTimer timer;
unsigned int replotInterval = 1;
unsigned int step = 0;
QMenu menu;
QSharedPointer<QCPAxisTickerDateTime> dateTicker{new QCPAxisTickerDateTime};
public:
explicit GraphWorker(QWidget *parent = nullptr);
~GraphWorker();
static void addLabel(QLabel *lbl);
void setData(float data);
signals:
public slots:
private slots:
void mouseMove(QMouseEvent* event);
void scroll(QWheelEvent* event);
};
#endif // GRAPHWORKER_H