-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimpletimeplot.h
More file actions
123 lines (105 loc) · 2.73 KB
/
simpletimeplot.h
File metadata and controls
123 lines (105 loc) · 2.73 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef SIMPLETIMEPLOT_H
#define SIMPLETIMEPLOT_H
#include <QWidget>
#include <QPaintEvent>
#include <QMutex>
#include <QMutexLocker>
#include <QPen>
#include <assert.h>
#include <map>
class SimpleTimePlot : public QWidget
{
Q_OBJECT
public:
explicit SimpleTimePlot(QWidget *parent = 0);
void paintEvent(QPaintEvent* event);
void addPoint(double x, double y)
{
if(!ValidDouble(x))
return;
QMutexLocker locker(&m_dataMutex);
m_data.insert(std::make_pair(x,y));
m_xMin = x - m_xRange;
m_xMax = x;
}
void addLine(int groupIdx, double x, QPen p)
{
if(!ValidDouble(x))
return;
QMutexLocker locker(&m_lineMutex);
if(m_lines.find(groupIdx) == m_lines.end()) {
m_lines[groupIdx] = LineGroup();
m_lines[groupIdx].pen = p;
m_lines[groupIdx].active = true;
}
LineGroup &lg = m_lines[groupIdx];
if(std::find(lg.positions.begin(),lg.positions.end(),x) == lg.positions.end())
lg.positions.push_back(x);
}
void setLineGroupActive(int groupIdx,bool active)
{
if(m_lines.find(groupIdx) != m_lines.end()) {
m_lines[groupIdx].active = active;
}
}
void setYRange(double yMin, double yMax)
{
if(!ValidDouble(yMin) || !ValidDouble(yMin))
return;
QMutexLocker locker(&m_dataMutex);
assert(yMin < yMax);
m_yMin = yMin;
m_yMax = yMax;
}
void setXRange(double xRange)
{
if(!ValidDouble(xRange))
return;
QMutexLocker locker(&m_dataMutex);
m_xRange = xRange;
}
void setTitle(QString title)
{
QMutexLocker locker(&m_dataMutex);
m_tite = title;
}
void cleanupMap();
void clear()
{
{
QMutexLocker locker(&m_dataMutex);
m_data.clear();
}
{
QMutexLocker locker(&m_lineMutex);
m_lines.clear();
}
}
private:
QRect drawFrame(QPainter *painter);
bool ValidDouble(double value)
{
if (value != value) {
return false;
} else if (value > std::numeric_limits<qreal>::max()) {
return false;
} else if (value < -std::numeric_limits<qreal>::max()) {
return false;
} else
return true;
}
private:
QMutex m_dataMutex;
double m_xRange;
double m_xMin, m_xMax, m_yMin, m_yMax;
std::map<double, double> m_data;
QMutex m_lineMutex;
typedef struct LineGroup {
std::vector<double> positions;
QPen pen;
bool active;
} LineGroup;
std::map<int,LineGroup> m_lines;
QString m_tite;
};
#endif // SIMPLETIMEPLOT_H