plot.h
1 /***************************************************************************
2  plot.h - description
3  -------------------
4  begin : Mon Aug 1 2005
5  copyright : (C) 2000-2015 by Thies Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef PLOT_H
19 #define PLOT_H
20 
21 #include <qobject.h> // Include Qt stuff first to avoid ambiguities with 'debug' symbol
22 
23 #include "odinqt.h"
24 
25  // forward declarations
26 class QwtPlot;
27 class QwtPlotCurve;
28 class QwtPlotMarker;
29 class QwtPlotGrid;
30 class QRect;
31 class QwtWheel;
32 class QwtScaleDraw;
33 class GuiPlotPicker;
34 
35 
36 // work around different declarations of QwtDoubleRect
37 #if QT_VERSION >= 0x040000
38 class QRectF;
39 typedef QRectF QwtDoubleRect;
40 #else
41 class QwtDoubleRect;
42 #endif
43 
44 
45 
47 
51 class GuiPlot : public QObject {
52  Q_OBJECT
53 
54  public:
55  GuiPlot(QWidget *parent, bool fixed_size=false, int width=_ARRAY_WIDGET_WIDTH_-20, int height=_ARRAY_WIDGET_HEIGHT_-20);
56  ~GuiPlot();
57 
58  void set_x_axis_label(const char *xAxisLabel, bool omit=false);
59  void set_y_axis_label(const char *yAxisLabelLeft, const char *yAxisLabelRight=0);
60 
61  long insert_curve(bool use_right_y_axis=false, bool draw_spikes=false, bool baseline=false);
62 
63  long insert_marker(const char* label, double x, bool outline=false, bool horizontal=false, bool animate=false);
64 
65  void remove_marker(long id);
66 
67  void set_marker_pos(long id, double x);
68 
69  // memory NOT managed by GuiPlot
70  void set_curve_data(long curveid, const double* x, const double* y, int n, bool symbol=false);
71 
72  void replot();
73 
74  void autoscale();
75 
76  void autoscale_y(double& maxBound);
77 
78  void rescale_y(double maxBound);
79 
80  void clear();
81 
82  void remove_markers();
83 
84  double get_x(int x_pixel) const;
85  double get_y(int y_pixel, bool right_axes=false) const;
86 
87  long closest_curve(int x, int y, int& dist) const;
88 
89  void highlight_curve(long id, bool flag);
90 
91  void set_x_axis_scale(double lbound, double ubound);
92  void set_y_axis_scale(double lbound, double ubound, bool right_axes=false);
93 
94  void set_curve_pen(long id, const char* color, int width=1);
95 
96  void set_rect_outline_style();
97  void set_line_outline_style(bool horizontal);
98 
99  void enable_axes(bool flag); // TODO: Use ArrayScale::enable to control this setting
100  void enable_grid(bool flag);
101 
102  void print(QPainter* painter, const QRect& rect) const;
103 
104 
105  QWidget* get_widget();
106 
107  signals:
108  void plotMousePressed(const QMouseEvent&);
109  void plotMouseReleased(const QMouseEvent&);
110  void plotMouseMoved(const QMouseEvent&);
111 
112  private slots:
113  void emit_plotMousePressed(const QMouseEvent& qme);
114  void emit_plotMouseReleased(const QMouseEvent& qme);
115  void emit_plotMouseMoved(const QMouseEvent& qme);
116 
117 
118  private:
119  friend class GuiPlotPicker;
120 
121  void set_axis_label(int axisId, const char* label, bool omit, int alignment);
122 
123  QwtPlot* qwtplotter;
124 
125  GuiPlotPicker* picker;
126 
127 
128  // Use functions with check to access curve_map/marker_map
129  QwtPlotCurve* get_curve(long id);
130  QwtPlotMarker* get_marker(long id);
131 
132 
133  // to emulate Qwt4 behaviour on Qwt5
134  STD_map<long,QwtPlotCurve*> curve_map;
135  STD_map<long,QwtPlotMarker*> marker_map;
136 
137  QwtPlotGrid* plotgrid;
138 
139  int canvas_framewidth;
140 
141  long baseline_id_cache;
142 };
143 
145 
146 
150 class GuiWheel : public QObject {
151  Q_OBJECT
152 
153  public:
154  GuiWheel(QWidget *parent);
155  ~GuiWheel();
156 
157  void set_range(double min, double max);
158 
159  void set_value(double newval);
160 
161  QWidget* get_widget();
162 
163  signals:
164  void valueChanged(double);
165 
166  private slots:
167  void emit_valueChanged(double newval);
168 
169  private:
170  QwtWheel* wheel;
171 
172 };
173 
174 
175 #endif
Definition: plot.h:150
Definition: plot.h:51