OpenCurves  0.9
ocurvesui.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) 2012
5 //
6 #ifndef __PLOT_H_
7 #define __PLOT_H_
8 
9 #include "ocurvesconfig.h"
10 
11 #include "timesampling.h"
12 
13 #include <QMainWindow>
14 #include <QList>
15 #include <QRgb>
16 #include <QStringList>
17 #include <QVector>
18 
19 class QElapsedTimer;
20 class QMenu;
21 class QMimeData;
22 class QSettings;
23 class QSplitter;
24 class QwtLegend;
25 
26 class Curves;
27 class CurveProperties;
28 class PlotExpression;
29 class PlotGenerator;
30 class PlotInstance;
31 class PlotSource;
32 class PlotViewToolbar;
33 class LoadProgress;
34 class RealTimePlot;
35 class ToolbarWidgets;
36 class Expressions;
37 class ExpressionsView;
38 class PlotView;
39 class SplitPlotView;
40 
41 namespace Ui
42 {
43  class OCurvesUI;
44 }
45 
46 #define REFERENCE_SETTINGS(s) QSettings s(QSettings::IniFormat, QSettings::UserScope, "ocurves");
47 
63 class OCurvesUI : public QMainWindow
64 {
65  Q_OBJECT
66 
67 public:
70  explicit OCurvesUI(QWidget *parent = nullptr);
71 
73  ~OCurvesUI();
74 
77  inline Curves *curves() const { return _curves; }
78 
81  inline Expressions *expressions() const { return _expressions; }
82 
85  inline ExpressionsView *expressionsView() const { return _expressionsView; }
86 
89  inline SplitPlotView *splitPlotView() const { return _splitView; }
90 
98  void loadSettings(QSettings &settings, bool loadGeometry = true);
99 
101  void loadWindowsSettings();
102 
108  void loadWindowsSettings(QSettings &settings);
109 
120  void saveSettings(QSettings &settings, bool bookmarkCurrent = false);
121 
122 public slots:
130  void load(const QString &plotFile, bool append = false);
131 
143  void load(const QStringList &plotFiles, bool append = false, QVector<TimeSampling> *plotTiming = nullptr);
144 
148  void openDataFiles();
149 
156 
158  void reloadPlots();
159 
161  void clearPlots();
162 
165  void sourceSelectOnlyIndex(const QModelIndex &index);
166 
169  void sourceSelectOnly(int row);
170 
173  void plotsSelectOnlyIndex(const QModelIndex &index);
174 
177  void plotsSelectOnly(int row);
178 
182  void copyActiveView();
183 
185  void editColours();
186 
187 private slots:
189  void sourcesSelectionChanged();
190 
193  void sourcesContextMenu(const QPoint &where);
194 
196  void plotsSelectionChanged();
197 
200  void plotsContextMenu(const QPoint &where);
201 
204  void curveAdded(PlotInstance *curve);
205 
207  void beginNewCurves();
208 
210  void endNewCurves();
211 
214  void curveComplete(PlotInstance *curve);
215 
217  void curveLoadingComplete();
218 
222  void sourceDataChanged(const PlotSource *source);
223 
229  void loadComplete(int curveCount);
230 
242  void legendItemClicked(const QVariant &itemInfo, int index);
243 
245  void sourcesSelectOnlyCurrent();
246 
248  void sourcesReloadCurrent();
249 
251  void sourcesRemoveCurrent();
252 
254  void plotsSelectOnlyCurrent();
255 
258  void expressionAdded(PlotExpression *expression);
259 
262  void expressionRemoved(const PlotExpression *expression);
263 
266  void viewAdded(PlotView *view);
267 
271  void activeViewChanged(PlotView *newView, PlotView *oldView);
272 
277  void viewLegendChanged(QwtLegend *legend, int position);
278 
280  void gotoBookmark();
281 
283  void setBookmark();
284 
286  void clearBookmark();
287 
290  void clearBookmark(int id);
291 
293  void clearBookmarks();
294 
298  void exportBookmarks();
299 
303  void importBookmarks();
304 
306  void restoreLastSession();
307 
309  void viewHelp();
310 
312  void showAbout();
313 
314 protected:
322  void removeCurvesWithSource(const QString &sourceName);
323 
338  void updateColours(const QStringList &activeSources, const QStringList &activeCurves);
339 
343  virtual void timerEvent(QTimerEvent *) override;
344 
346  virtual void showEvent(QShowEvent *) override;
347 
349  virtual void closeEvent(QCloseEvent *) override;
350 
351 private:
353  enum PostLoaderAction
354  {
355  PLA_None,
356  PLA_GenerateExpressions,
357  PLA_CheckExpressions
358  };
359 
361  void setupToolbars();
362 
364  void setupBookmarks();
365 
369  QString bookmarkMenuName(unsigned id, const QString &name = QString());
370 
374  QAction *findGotoBookmarkAction(int id);
375 
379  QAction *findSetBookmarkAction(int id);
380 
384  QAction *findClearBookmarkAction(int id);
385 
392  void replot(bool force = false);
393 
395  void stopLoad();
396 
400  PostLoaderAction completeLoad(PlotGenerator *loader);
401 
403  void clearCurves();
404 
413  bool addToSourceList(const QString &displayName);
414 
417  void recolourCurves();
418 
422  void updateActivePlotView(bool updateSources, bool updatePlots);
423 
425  void updateSelectedSources();
426 
428  void populatePlotsList();
430  void updateSelectedPlots();
431 
433  void endStreams();
434 
437  void setTimeControls(PlotGenerator *generator);
438 
442  void activateLoader(PlotGenerator *newLoader, PostLoaderAction nextAction);
443 
447  void connectLoader(PlotGenerator *loader, LoadProgress *progress = nullptr);
448 
451  void dragEnterEvent(QDragEnterEvent *event) override;
452 
455  void dropEvent(QDropEvent *event) override;
456 
457  // Support functions.
458 
462  bool canAcceptDrop(const QMimeData &mimeData) const;
463 
467  QStringList extractDroppedFileList(const QMimeData &mimeData) const;
468 
469  Ui::OCurvesUI *_ui;
470  ToolbarWidgets *_toolbarWidgets;
471  PlotViewToolbar *_viewToolbar;
472  SplitPlotView *_splitView;
473  QwtLegend *_legend;
474  Curves *_curves;
475  QVector<QRgb> _colours;
476  ExpressionsView *_expressionsView;
477  bool _suppressEvents;
478  PostLoaderAction _postLoaderAction;
479  PlotGenerator *_loader;
480  QMenu *_sourcesContextMenu;
481  QMenu *_plotsContextMenu;
482  QPoint _lastContextPos;
483  Expressions *_expressions;
484  QElapsedTimer *_timeSinceLastPlot;
485  RealTimePlot *_streams;
486  CurveProperties *_properties;
487 
488  QString _loadDirectory;
489  QString _loadFilter;
490 
491  QString _streamDirectory;
492  QString _streamFilter;
493 
494  QString _originalWindowTitle;
495 
496  int _activeBookmark;
497 };
498 
499 #endif // __PLOT_H_
The main Open Curves UI window.
Definition: ocurvesui.h:63
void removeCurvesWithSource(const QString &sourceName)
Removes all curves which have a PlotSource::name() mathcing sourceName.
A toolbar for use with PlotView objects.
Definition: plotviewtoolbar.h:21
void plotsSelectOnly(int row)
Select only the curve name at row.
Definition: coloursview.h:16
Widgets added to the toolbar, supporting non-button widgets.
Definition: toolbarwidgets.h:26
Generates PlotInstance objects for plotting over real-time connections.
Definition: realtimeplot.h:112
void loadSettings(QSettings &settings, bool loadGeometry=true)
Loads saved settings saved by saveSettings() and applies them.
void sourceSelectOnly(int row)
Select only the source at row.
Expressions * expressions() const
Access the Expressions data.
Definition: ocurvesui.h:81
A widget for showing the progress of loading.
Definition: loadprogress.h:28
virtual void timerEvent(QTimerEvent *) override
Periodic event used to migrate background loaded data.
Curves * curves() const
Access the primary Curves data.
Definition: ocurvesui.h:77
An plot view viewing a Curves model.
Definition: plotview.h:36
void openDataFiles()
Show a dialog allowing the user to select data files to open.
virtual void showEvent(QShowEvent *) override
Handles reveling the window by restoring stored settings.
Holds data for a single curve.
Definition: plotinstance.h:43
The data model for loaded plots and curves.
Definition: curves.h:36
Manages and edits current expressions.
Definition: expressionsview.h:33
void reloadPlots()
Trigger a reload of a currently loaded sources. Does not include ones pending load.
void updateColours(const QStringList &activeSources, const QStringList &activeCurves)
Recolours all visible PlotInstance objects by cycling through the colour set.
virtual void closeEvent(QCloseEvent *) override
Ensures loading is stopped and settings are saved.
void loadWindowsSettings()
Loads and restores window geometry and other settings from the default settings.
Provides details about a source from which PlotInstance objects have been generated.
Definition: plotsource.h:28
void clearPlots()
Clears the display, removing all sources.
A special plotting view which can contain multiple splits, each with its own PlotView.
Definition: splitplotview.h:33
void sourceSelectOnlyIndex(const QModelIndex &index)
Handler for selecting a single source by model index.
void load(const QString &plotFile, bool append=false)
Request loading of the given file.
A curve generation thread.
Definition: plotgenerator.h:84
void copyActiveView()
Copy the active view content to the system clipboard (if available).
ExpressionsView * expressionsView() const
Access the view for expressions.
Definition: ocurvesui.h:85
OCurvesUI(QWidget *parent=nullptr)
Constructor.
Maintains the current expressions available for generation and plotting.
Definition: expressions.h:27
void plotsSelectOnlyIndex(const QModelIndex &index)
Handler for selecting a single curve name by model index.
void saveSettings(QSettings &settings, bool bookmarkCurrent=false)
Saves the application state and settings including both UI and data settings.
SplitPlotView * splitPlotView() const
Access the main plot view.
Definition: ocurvesui.h:89
A PlotExpression represents an operation in a plot equation.
Definition: plotexpression.h:91
UI for editing PlotSource and PlotInstance properties.
Definition: curveproperties.h:25
~OCurvesUI()
Destructor.
void editColours()
Shows the colour set editing dialog.
void connectToRealtimeSource()
Show a dialog allowing the user to select a real time source XML file to load.