-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.h
More file actions
98 lines (91 loc) · 2.42 KB
/
plotter.h
File metadata and controls
98 lines (91 loc) · 2.42 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
#ifndef PLOTTER_H_INCLUDED
#define PLOTTER_H_INCLUDED
//#include <qpixmap.h>
//#include <qwidget.h>
//Added by qt3to4:
#include <QtGui>
#include <QtWidgets>
#include <QResizeEvent>
#include <QWheelEvent>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QPaintEvent>
#include <QVector>
#include <map>
class QToolButton;
class PlotSettings;
typedef QVector<double> CurveData;
class Plotter : public QWidget
{
Q_OBJECT
public:
Plotter(QWidget *parent = 0, Qt::WindowFlags flags=0);
//old Plotter(QWidget *parent = 0, const char *name=0,
//old Qt::WFlags flags=0);
void setPlotSettings(const PlotSettings &settings);
void setCurveData(int id, const CurveData &data);
void clearCurve(int id);
int firstUnusedId() const;
QSize minimumSizeHint() const;
QSize sizeHint() const;
public slots:
void scaleX();
void scaleY();
void zoomIn();
void zoomOut();
void zoomAll();
void clearAll();
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent *event);
void enterEvent(QEvent *event);
private:
void moveButtons();
void updateRubberBandRegion();
void refreshPixmap();
void drawGrid(QPainter *painter);
void drawCurves(QPainter *painter);
void captureBoundsToSettings();
enum {Margin = 60};
QToolButton *zoomInButton;
QToolButton *zoomOutButton;
QToolButton *zoomAllButton;
QToolButton *eraseButton;
QToolButton *scaleXButton;
QToolButton *scaleYButton;
std::map<int, CurveData> curveMap;
std::vector<PlotSettings> zoomStack;
int curZoom,yScale,xScale;
bool rubberBandIsShown;
bool savePlot();
bool openPlot();
bool savePlotAs();
QRect rubberBandRect;
QPixmap pixmap;
QString curFileCurve;
};
class PlotSettings
{
public:
PlotSettings();
void scroll(int dx, int dy);
void adjust();
double spanX() const {return maxX-minX;}
double spanY() const {return maxY-minY;}
double minX;
double maxX;
int numXTicks;
double minY;
double maxY;
int numYTicks;
private:
void adjustAxis(double &min, double &max, int &numTicks);
double nicenum(double x, int round);
double expt(double a, int n);
};
#endif /*PLOTTER_H_INCLUDED*/