-
Notifications
You must be signed in to change notification settings - Fork 9
/
graphwidget.h
68 lines (62 loc) · 2.37 KB
/
graphwidget.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
#ifndef GRAPHWIDGET_H
#define GRAPHWIDGET_H
#include <QtGui/QWidget>
#include <QtGui/QPainter>
#include <QtCore/QVector>
#include <QtCore/QPointF>
#include <QtCore/QSet>
#include <QtGui/QMouseEvent>
#include <QtCore/QTime>
#include <QtCore/QDebug>
#include <cmath>
class Path {
QVector < QPointF > v_data;
QColor s_color;
double s_target;
public:
inline QColor color() { return s_color; }
inline double target() {return s_target; }
inline void setColor(QColor clr) { s_color = clr; }
inline void setTarget(double trg) { s_target = trg; }
inline QVector < QPointF > data() { return v_data; }
inline QPointF& operator[] (int i) { return v_data[i]; }
inline void addPoint(const QPointF& pnt) { v_data.append(pnt); if(v_data.size()>1000){ v_data.remove(0);} }
inline int size() { return v_data.size(); }
void resize(int size) { v_data.resize(size); }
Path(const QVector<double> &x, const QVector<double> &y);
Path();
};
class GraphWidget : public QWidget
{
private:
QSet <Path*> paths;
QPointF trans;
double s_scale;
QPoint prevPos;
Path *t1;
Path *t2;
Path *t3;
qint64 createTime;
protected:
virtual void paintEvent(QPaintEvent*);
virtual void mouseMoveEvent ( QMouseEvent *);
virtual void mousePressEvent ( QMouseEvent *);
public:
static const int defaultScale = 1;
static const int maxScale = 100;
static const int minScale = 3;
inline int xToCanvX(double a_x) { return a_x*((double)width()/(double)120) + trans.x(); }
inline int yToCanvY(double a_y) { return -a_y*((double)height()/(double)300) + height(); }
inline void setScale(double s) { if (s>minScale && s<maxScale) s_scale = s; }
inline double scale() { return s_scale; }
bool addPath(Path* p);
Path* takePath(Path* p);
void clearPaths(bool del = false);
inline int pathCount() { return paths.size(); }
GraphWidget(QWidget *parent=NULL);
QSize minimumSizeHint() const;
QSize sizeHint() const;
void addMeasurment(double, double, double, qint64);
void setTargets(double, double, double);
};
#endif // GRAPHWIDGET_H