OpenCurves  0.9
curves.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2015
5 //
6 #ifndef CURVES_H_
7 #define CURVES_H_
8 
9 #include "ocurvesconfig.h"
10 
11 #include <QHash>
12 #include <QList>
13 #include <QObject>
14 #include <QVariant>
15 
16 class PlotExpression;
17 class PlotInstance;
18 class PlotSource;
19 class QMutex;
20 class QwtPlotCurve;
21 
22 typedef QHash<QString, QVariant> VariantMap;
23 
36 class Curves : public QObject
37 {
38  Q_OBJECT
39 public:
46  class CurveList
47  {
48  public:
50  typedef QList<PlotInstance *>::iterator iterator;
51 
53  typedef QList<PlotInstance *>::const_iterator const_iterator;
54 
58  CurveList(QMutex &mutex, const QList<PlotInstance *> &curves);
59 
61  ~CurveList();
62 
64  void release();
65 
68  inline const_iterator begin() const { return _curves->begin(); }
69 
72  inline const_iterator end() const { return _curves->end(); }
73 
79  const QList<PlotInstance *> &list() const { return *_curves; }
80 
81  private:
82  QMutex *_mutex;
83  const QList<PlotInstance *> *_curves;
84  };
85 
88  Curves(QObject *parent = nullptr);
89 
91  ~Curves();
92 
95  CurveList curves() const;
96 
99  CurveList loadingCurves() const;
100 
103  CurveList realTimeCurves() const;
104 
108  unsigned removeUsingExpression(const PlotExpression *expression);
109 
111  void enumerateFileSources(QStringList &filePaths) const;
112 
116  void enumerateSources(QList<PlotSource *> &sources, unsigned type) const;
117 
123  inline const VariantMap &curvePropertiesMap() const { return _curvePropertiesMap; }
124 
130  void setCurvePropertiesMap(VariantMap &map);
131 
132 public slots:
138  void newCurve(PlotInstance *curve);
139 
141  void completeLoading(PlotInstance *curve);
142 
146  bool removeCurve(const PlotInstance *curve);
147 
150  void invalidate(const PlotInstance *curve);
151 
158  void invalidate(const PlotSource *source, bool invalidateCurves = false);
159 
161  void clearCurves();
162 
169  bool migrateLoadingData();
170 
171 public:
175  bool isLoading(const PlotInstance *curve) const;
176 
177 signals:
180  void curveAdded(PlotInstance *curve);
181 
184  void curveComplete(PlotInstance *curve);
185 
188  void curveDataChanged(const PlotInstance *curve);
189 
192  void curveRemoved(const PlotInstance *curve);
193 
196  void sourceDataChanged(const PlotSource *source);
197 
199  void curvesCleared();
200 
202  void loadingComplete();
203 
204 private:
208  bool restoreProperties(PlotInstance &curve) const;
209 
213  void addToDeathRow(const PlotInstance *curve);
214 
215 private slots:
217  void clearDeathRow();
218 
219 private:
220  QList<PlotInstance *> _curves;
221  QList<PlotInstance *> _loadingCurves;
222  QList<PlotInstance *> _realTimeCurves;
223  QList<PlotInstance *> _completedCurves;
224  QList<const PlotInstance *> _deathRow;
225  mutable QMutex *_curvesMutex;
226  mutable QMutex *_loadingMutex;
227  mutable QMutex *_realTimeMutex;
228  mutable QMutex *_deathRowMutex;
229  VariantMap _curvePropertiesMap;
230 };
231 
232 #endif // CURVES_H_
const VariantMap & curvePropertiesMap() const
Retrieve the curve properties map for pending curves.
Definition: curves.h:123
const_iterator end() const
End iterator.
Definition: curves.h:72
Curves(QObject *parent=nullptr)
Create a curves data model.
~CurveList()
Destructor: releases the mutex.
void curveComplete(PlotInstance *curve)
Signals that loading of a curve has finished.
void sourceDataChanged(const PlotSource *source)
Signals that a PlotSource has changed its data content - generally it's timing data.
CurveList realTimeCurves() const
Retrieve the complete list of real-time curves.
void enumerateFileSources(QStringList &filePaths) const
Enumerates the source files from which curves have been loaded.
void newCurve(PlotInstance *curve)
Add a new curve to the list of curves.
Holds data for a single curve.
Definition: plotinstance.h:43
void enumerateSources(QList< PlotSource * > &sources, unsigned type) const
Enumerates all sources of the requested type.
The data model for loaded plots and curves.
Definition: curves.h:36
CurveList curves() const
Retrieve the complete list of curves, loading or loaded.
A thread safe capture of a list of curves internal to a Curves object.
Definition: curves.h:46
void curvesCleared()
Signals all curve data has been cleared.
QList< PlotInstance * >::const_iterator const_iterator
The const_iterator type.
Definition: curves.h:53
bool removeCurve(const PlotInstance *curve)
Removes and deletes curve.
CurveList loadingCurves() const
Retrieve the complete list of loading curves.
void curveRemoved(const PlotInstance *curve)
Signals removal of a curve (and deletion).
Provides details about a source from which PlotInstance objects have been generated.
Definition: plotsource.h:28
void invalidate(const PlotInstance *curve)
Invalidates curve by raising the curveDataChanged() signal.
~Curves()
Destructor. Cleans up all owned curves.
void loadingComplete()
Signals that all loading curves have completed loading.
void clearCurves()
Clears all curve data.
void curveAdded(PlotInstance *curve)
Signals a curve is added (in the loading state).
QList< PlotInstance * >::iterator iterator
The iterator type.
Definition: curves.h:50
bool isLoading(const PlotInstance *curve) const
Checks if the given curve is loading.
const QList< PlotInstance * > & list() const
Direct access to the underlying list (thread-safe).
Definition: curves.h:79
void release()
Releases the curve list and lock allowing other threads to access the data. The object becomes invali...
void setCurvePropertiesMap(VariantMap &map)
Set the curve properties map.
A PlotExpression represents an operation in a plot equation.
Definition: plotexpression.h:91
void curveDataChanged(const PlotInstance *curve)
Signals that a curve has changed its data content.
CurveList(QMutex &mutex, const QList< PlotInstance * > &curves)
Constructor: internal use only.
const_iterator begin() const
Begin iteration of the curves.
Definition: curves.h:68
bool migrateLoadingData()
Migrates data from the back buffer of loading curves into the main display buffer.
unsigned removeUsingExpression(const PlotExpression *expression)
Remove all the curves which where generated from expression.
void completeLoading(PlotInstance *curve)
Signals successful completion of curve. It is no longer in the loading state.