-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyplot.h
101 lines (75 loc) · 2.31 KB
/
myplot.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
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
#ifndef MYPLOT_H
#define MYPLOT_H
#include <QWidget>
#include <QBrush>
#include <QPen>
class Tick
{
public:
Tick();
Tick(double value, int pixel, double span);
int posPixel;
double unit, span;
QString getLabel(void);
private:
QString label;
};
class Axis
{
public:
Axis();
Axis(double min, double max, bool inverted);
double min, max;
void resize(int size);
QVector<Tick> majorTicks, minorTicks;
int getPixel(double unit);
private:
double unitsPerPixel, pixelsPerUnit, span;
bool inverted;
int size;
QVector<Tick> generateTicks(int tickCount);
void updateScale();
void updateTicks();
};
class XYData
{
public:
XYData();
XYData(QVector<double> X, QVector<double> Y, QColor lineColor, double lineWidth, QColor markerColor, double markerSize, QString label);
QVector<double> X, Y;
double lineWidth, markerSize;
QColor lineColor, markerColor;
QString label;
};
class MyPlot : public QWidget
{
Q_OBJECT
public:
explicit MyPlot(QWidget *parent = nullptr);
void plotXY(QVector<double> X, QVector<double> Y, QColor lineColor = Qt::blue, double lineWidth = 1.5, QColor markerColor = Qt::blue, double markerSize = 0, QString label = "");
void setAxes(double xmin, double xmax, double ymin, double ymax);
void setAxesAuto();
void setFramePen(QPen penFrame);
void setTicksPen(QPen penTicks);
void setXLabel(QString xLabel, int fontSize = 8);
void setYLabel(QString yLabel, int fontSize = 8);
void setGridPen(QPen penGrid);
void setPadding(int padLeft, int padTop, int padRight, int padBottom);
void clear();
protected:
void paintEvent(QPaintEvent *event) override;
private:
int padLeft = 60, padTop = 30, padRight = 30, padBottom = 60, posB, posR;
QColor colorGraphBackground;
QPen penFrame = QPen(Qt::black, 1), penTicks = QPen(Qt::black, 1), penGrid = QPen(Qt::gray, 1);
QString xLabel, yLabel;
int xLabelFontSize, yLabelFontSize;
Axis xAxis, yAxis;
QVector<XYData> xyDataList;
QVector<QPoint> pointsFromVectors(QVector<double> X, QVector<double> Y);
QPixmap frame, graph;
void renderFrame();
void renderGraph();
bool updateFrame;
};
#endif // MYPLOT_H