SimCenterCommon
Common functionality used within different SimCenter projects
simfigure.h
Go to the documentation of this file.
1 #ifndef SIMFIGURE_H
2 #define SIMFIGURE_H
3 
4 #include <QFrame>
5 #include <QList>
6 #include <QMap>
7 #include <QPen>
8 #include <QBrush>
9 
10 //#include "simfigure_enums.h"
11 
12 class QwtPlot;
13 class QwtPlotGrid;
14 class QwtPlotItem;
15 class QwtPlotShapeItem;
16 class QwtPlotCurve;
17 class QwtPlotLegendItem;
18 class QString;
19 class QwtPlotPicker;
20 class QwtPlotZoomer;
21 
22 
23 namespace Ui {
24 class SimFigure;
25 }
26 
27 
28 class SimFigure : public QFrame
29 {
30  Q_OBJECT
31 
32 public:
33 
39  enum class AxisType { Default,
40  LogX,
41  LogY,
42  LogLog
43  };
44 
50  enum class LineType { None,
51  Solid,
52  Dotted,
53  Dashed,
54  DashDotted
55  };
56 
62  enum class Marker { None,
63  Asterisk,
64  Circle,
65  Plus,
66  Triangle,
67  DownTriangle,
68  RightTriangle,
69  LeftTriangle,
70  Box,
71  Ex
72  };
73 
79  enum class Location { Bottom,
80  Top,
81  Left,
82  Right,
83  TopLeft,
84  TopRight,
85  BottomLeft,
86  BottomRight,
87  North,
88  South,
89  East,
90  West,
91  NorthWest,
92  NorthEast,
93  SouthWest,
94  SouthEast
95  };
96 
102  enum class FileType {
103  PNG,
104  BMP,
105  PDF,
106  PS,
107  SVG
108  };
109 
110  explicit SimFigure(QWidget *parent = nullptr);
111  ~SimFigure();
112 
113  int plot(QVector<double> &, QVector<double> &, LineType lt = LineType::Solid, QColor col = Qt::red, Marker mk = Marker::None);
114  int scatter(QVector<double> &, QVector<double> &, QColor col = Qt::blue, Marker mk = Marker::Circle);
115 
116 
117  void clear(void);
118  void cla(void);
119 
120  void grid(bool mayor=true, bool minor=true);
121 
122  void legend(QList<QString> labels, Location loc=Location::South);
123  void moveLegend(Location loc);
124  void showLegend(bool = true);
125  bool legendVisible(void);
126 
127  void select(int);
128  void clearSelection(void);
129 
130  SimFigure::AxisType axisType(void);
131  void setAxisType( AxisType type);
132 
133  QString xLabel();
134  QString yLabel();
135  int labelFontSize();
136  QString title();
137  int titleFontSize();
138 
139  void setXLabel(QString lbl);
140  void setYLabel(QString lbl);
141  void setXLim(double xmin, double xmax);
142  void setYLim(double ymin, double ymax);
143 
145  void setXlimits(double xmin, double xmax) {setXLim(xmin,xmax);};
146 
148  void setYlimits(double ymin, double ymax) {setYLim(ymin,ymax);};
149  void setLabelFontSize(int);
150  void setTitle(QString title);
151  void setTitleFontSize(int);
152 
156  double minX() { return m_xmin; };
160  double maxX() { return m_xmax; };
164  double minY() { return m_ymin; };
168  double maxY() { return m_ymax; };
169 
170  int lineWidth(int ID);
171  void setLineWidth(int ID, int wd);
172 
173  double lineWidthF(int ID);
174  void setLineWidthF(int ID, double wd);
175 
176  SimFigure::LineType lineStyle(int ID);
177  void setLineStyle(int ID, LineType lt=LineType::Solid, Marker mk=Marker::None);
178 
179  QColor lineColor(int ID);
180  void setLineColor(int ID, QColor color);
181 
182  SimFigure::Marker marker(int ID);
183  int markerSize(int ID);
184  void setMarker(int ID, Marker mk, int size=10);
185 
186  void saveToFile(QString filename, SimFigure::FileType type=SimFigure::FileType::PNG, QSizeF size=QSizeF(300,200), int res=85);
187  void exportToFile(QString filename, SimFigure::FileType type=SimFigure::FileType::PNG, QSizeF size=QSizeF(300,200), int res=85);
188 
189 private slots:
190  void axisTypeChanged(void);
191 
192 public slots:
193  void on_picker_activated (bool on);
194  void on_picker_selected (const QPolygon &polygon);
195  void on_picker_appended (const QPoint &pos);
196  void on_picker_moved (const QPoint &pos);
197  void on_picker_removed (const QPoint &pos);
198  void on_picker_changed (const QPolygon &selection);
199  void showAxisControls(bool show);
200  void fit_data();
201 
202 signals:
203  void curve_selected(int ID);
204 
205 protected:
206  void select(QwtPlotItem *);
207  void setLineStyle(QwtPlotCurve *, LineType lt);
208  void setLineColor(QwtPlotCurve *, QColor color);
209  void setMarker(QwtPlotCurve *curve, Marker mk, int size);
210  QwtPlotItem* itemAt( const QPoint& pos ) const;
211  void rescale(void);
212  void refreshGrid(void);
213 
214 private:
215  Ui::SimFigure *ui;
216  QwtPlot *m_plot;
217  QwtPlotGrid *m_grid;
218  QwtPlotPicker *m_picker;
219  QwtPlotZoomer *m_zoomer = nullptr;
220  QwtPlotLegendItem *m_legend;
221  QMap<QwtPlotCurve *, int> m_plotInvMap;
222  QMap<QwtPlotItem *, int> m_itemInvMap;
223 
224  QVector<QwtPlotCurve *> m_curves;
225 
226  AxisType m_axisType;
227  double m_xmin = 1.e20;
228  double m_xmax = 1.e-20;
229  double m_ymin = 1.e20;
230  double m_ymax = 1.e-20;
231 
232  double m_data_xmin = 1.e20;
233  double m_data_xmax = 1.e-20;
234  double m_data_ymin = 1.e20;
235  double m_data_ymax = 1.e-20;
236 
237  struct SELECTION {
238  QPen pen;
239  QBrush brush;
240  int plotID = -1;
241  QwtPlotItem *object = nullptr;
242  } lastSelection;
243 
244  bool m_showMajorGrid = true;
245  bool m_showMinorGrid = true;
246 };
247 
248 #endif // SIMFIGURE_H
void setXlimits(double xmin, double xmax)
alias for setXLim(xmin,xmax)
Definition: simfigure.h:145
Location
The Location enum.
Definition: simfigure.h:79
void setYlimits(double ymin, double ymax)
alias for setYLim(ymin,ymax)
Definition: simfigure.h:148
Definition: dialogabout.h:6
const char * filename
Definition: ioapi.h:38
double maxY()
returns the currently displayed maximum value of y
Definition: simfigure.h:168
voidpf void uLong size
Definition: ioapi.h:39
portable network graphic file
LineType
The LineType enum.
Definition: simfigure.h:50
Marker
The Marker enum.
Definition: simfigure.h:62
FileType
The FileType enum.
Definition: simfigure.h:102
double minX()
returns the currently displayed minimum value of x
Definition: simfigure.h:156
AxisType
The AxisType enum.
Definition: simfigure.h:39
double maxX()
returns the currently displayed maximum value of x
Definition: simfigure.h:160
double minY()
returns the currently displayed minimum value of y
Definition: simfigure.h:164