OpenCurves  0.9
plotview.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2015
5 //
6 #ifndef PLOTVIEW_H_
7 #define PLOTVIEW_H_
8 
9 #include "ocurvesconfig.h"
10 
11 #include <QColor>
12 #include <QFrame>
13 #include <QStringList>
14 #include <QVector>
15 
16 class Curves;
17 class PlotDataCurve;
18 class PlotInstance;
19 class PlotPanner;
20 class PlotZoomer;
21 
22 class QSettings;
23 class QwtLegend;
24 class QwtPlot;
25 
26 namespace Ui
27 {
28  class PlotView;
29 }
30 
36 class PlotView : public QFrame
37 {
38  Q_OBJECT
39 
40 public:
42  typedef QFrame Super;
43 
44  static const int SharedLegend;
45 
47  enum ToolMode
48  {
52 
53  ToolModeCount
54  };
55 
57  PlotView(Curves *curves, QWidget *parent = nullptr);
58 
60  ~PlotView();
61 
63  void showNone();
64 
68  void loadSettings(QSettings &settings);
69 
83  void saveSettings(QSettings &settings);
84 
87  inline QwtPlot *plot() { return _plot; }
88 
91  inline const QwtPlot *plot() const { return _plot; }
92 
95  inline ToolMode toolMode() const { return _toolMode; }
96 
107  int legendPosition() const;
108 
116  inline bool synchronised() const { return _synchronised; }
117 
120  inline PlotZoomer *zoomer() const { return _zoom; }
121 
124  inline PlotPanner *panner() const { return _panner; }
125 
128  void setHighlight(bool active);
129 
132  bool isHighlighted() const;
133 
145  void updateActive(const QStringList &sourceNames, const QStringList &curveNames);
146 
151  const QStringList &activeSourceNames() const { return _activeSourceNames; }
152 
157  const QStringList &visibleCurveNames() const { return _visibleCurveNames; }
158 
159 public slots:
165  void zoomToFit();
166 
172  void setSynchronised(bool sync);
173 
179  void setToolMode(ToolMode mode);
180 
182  inline void setMultiTool() { setToolMode(MultiTool); }
183 
185  inline void setPanTool() { setToolMode(PanTool); }
186 
188  inline void setZoomTool() { setToolMode(ZoomTool); }
189 
198  void setLegendPosition(int pos);
199 
208  void copyToClipboard();
209 
210 signals:
213  void focusGained();
214 
217  void focusLost();
218 
221  void synchronisedChanged(bool sync);
222 
225  void toolModeChanged(ToolMode mode);
226 
230  void legendChanged(QwtLegend *legend, int position);
231 
232 protected slots:
240  void addCurve(PlotInstance *curve);
241 
248  void removeCurve(const PlotInstance *curve);
249 
256  void curveDataChanged(const PlotInstance *curve);
257 
263  void curvesCleared();
264 
269  void legendSelectionChanged(int index);
270 
276  void toolActionToggled(bool checked);
277 
278 private:
279  friend class FocusPlot;
280 
283  void viewFocusGained();
284 
287  void viewFocusLost();
288 
289  QwtPlot *_plot;
290  Curves *_curves;
291  PlotZoomer *_zoom;
292  PlotPanner *_panner;
293  QStringList _activeSourceNames;
294  QStringList _visibleCurveNames;
295  QList<PlotDataCurve *> _displayCurves;
296  Ui::PlotView *_ui;
297  ToolMode _toolMode;
298  bool _synchronised;
299  bool _suppressEvents;
300 
302  QAction *_toolModeActions[ToolModeCount];
303 };
304 
305 #endif // PLOTVIEW_H_
void setMultiTool()
Set the tool mode to MultiTool.
Definition: plotview.h:182
void legendSelectionChanged(int index)
Handles changes to the legend position combo box.
const QwtPlot * plot() const
Access the primary plotting widget.
Definition: plotview.h:91
void legendChanged(QwtLegend *legend, int position)
The legend or its position has been changed, possibly to null.
PlotZoomer * zoomer() const
Access the zooming tool.
Definition: plotview.h:120
void setZoomTool()
Set the tool mode to ZoomTool.
Definition: plotview.h:188
void copyToClipboard()
Copies the current plot view content to the clipboard.
void updateActive(const QStringList &sourceNames, const QStringList &curveNames)
Updates which plots and files this view is showing.
Definition: coloursview.h:16
ToolMode toolMode() const
Get the current tool mode.
Definition: plotview.h:95
void removeCurve(const PlotInstance *curve)
Handles curve removal or deletion, removing the corresponding display adaptor.
void addCurve(PlotInstance *curve)
Handles a new curve definition by creating an appropriate display interface.
void setLegendPosition(int pos)
Set the legend position.
void focusGained()
Emitted when this PlotView gains focus.
~PlotView()
Destructor.
static const int SharedLegend
Special index for shared legend.
Definition: plotview.h:44
Pan/zoom combined tool.
Definition: plotview.h:49
int legendPosition() const
Request the current legend position.
void setSynchronised(bool sync)
Set or clear the synchronisation flag for this view.
Zoom only tool.
Definition: plotview.h:51
void zoomToFit()
Change the current zoom level to fit the currently selected plots.
An plot view viewing a Curves model.
Definition: plotview.h:36
void toolActionToggled(bool checked)
Ensures the current tool action stays checked.
void curvesCleared()
Handles removal of all curves.
void saveSettings(QSettings &settings)
Save settings for this view.
Holds data for a single curve.
Definition: plotinstance.h:43
const QStringList & visibleCurveNames() const
Retrieves the list of visible curves this view is displaying, or expecting to display.
Definition: plotview.h:157
The data model for loaded plots and curves.
Definition: curves.h:36
Custom zoom handler for Plot objects.
Definition: plotzoomer.h:22
QFrame Super
Parent class alias.
Definition: plotview.h:42
void toolModeChanged(ToolMode mode)
Emitted when the current tool mode is changed.
bool synchronised() const
Get the synchronisation state.
Definition: plotview.h:116
void setHighlight(bool active)
Set to display in the highlight or not.
A specialisation of QwtPlotCurve used to visualisation PlotInstanceData.
Definition: plotdatacurve.h:22
const QStringList & activeSourceNames() const
Retrieves the list of active sources this view is displaying, or expecting to display.
Definition: plotview.h:151
Pan only tool.
Definition: plotview.h:50
PlotView(Curves *curves, QWidget *parent=nullptr)
Create a view into curves.
Extension of QwtPlotPanner to expose moveCanvas() for synchronised panning.
Definition: plotpanner.h:15
void loadSettings(QSettings &settings)
Load settings for this view.
void setPanTool()
Set the tool mode to PanTool.
Definition: plotview.h:185
void curveDataChanged(const PlotInstance *curve)
Handles changes to curve data.
PlotPanner * panner() const
Access the panning tool.
Definition: plotview.h:124
void showNone()
Clear viewing of all items. No notification triggered.
bool isHighlighted() const
Request the current highlight state (as per setHighlight()).
void focusLost()
Emitted when this PlotView looses focus.
void synchronisedChanged(bool sync)
Emitted when the synchronised() flag changed.
QwtPlot * plot()
Access the primary plotting widget.
Definition: plotview.h:87
ToolMode
Modes for various interaction tools.
Definition: plotview.h:47
void setToolMode(ToolMode mode)
Set the tool mode for this view.