OpenCurves  0.9
plotsample.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2013
5 //
6 #ifndef __PLOTSAMPLE_H_
7 #define __PLOTSAMPLE_H_
8 
9 #include "plotsconfig.h"
10 
11 #include "plotexpression.h"
12 
14 
15 class QTextStream;
16 
24 {
25  QString name;
26  char quote;
27  bool regex;
28 
33  inline PlotSampleId(const QString &name = QString(), char quote = '\0', bool regex = false)
34  : name(name), quote(quote), regex(regex) { fixQuote(); }
35 
39  inline PlotSampleId(const QString &name, bool regex)
40  : name(name), quote('\0'), regex(regex) { fixQuote(); }
41 
44  inline PlotSampleId(const PlotSampleId &other)
45  : name(other.name), quote(other.quote), regex(other.regex) { }
46 
49  inline operator bool() const { return !name.isEmpty(); }
50 
53  inline bool operator !() const { return name.isEmpty(); }
54 
56  inline void fixQuote()
57  {
58  if (!quote && regex)
59  {
60  quote = '\'';
61  }
62  }
63 };
64 
73 QTextStream &operator << (QTextStream &stream, const PlotSampleId &sid);
74 
95 class PlotSample : public PlotExpression
96 {
97 public:
101  PlotSample(const QString &curveName, bool curveRegularExpression = false);
102 
108  PlotSample(const QString &curveName, const QString &fileName, bool curveRegularExpression = false, bool fileRegularExpression = false);
109 
113  PlotSample(const PlotSampleId &curveId, const PlotSampleId &fileId = PlotSampleId());
114 
117  PlotSample(const PlotSample &other);
118 
120  ~PlotSample();
121 
129  virtual double sample(double sampleTime) const;
130 
141  virtual BindResult bind(const QList<PlotInstance *> &curves, PlotBindingTracker &bindTracker,
142  PlotExpressionBindDomain &info, bool repeatLastBinding = false);
143 
145  virtual void unbind();
146 
149  virtual PlotExpression *clone() const;
150 
151 private:
153  virtual QString stringExpression() const;
154 
163  QString makeBoundName(const PlotInstance &plot) const;
164 
165  // Binding support.
166 
173  static bool nameMatch(const QString &name, const QString &searchName, const QRegExp *re = nullptr);
174 
175  PlotSampleId _curveId;
176  PlotSampleId _fileId;
177  QString _boundName;
178  PlotInstanceSampler *_sampler;
179  mutable unsigned int _previousSample;
180 };
181 
182 #endif // __PLOTSAMPLE_H_
virtual BindResult bind(const QList< PlotInstance * > &curves, PlotBindingTracker &bindTracker, PlotExpressionBindDomain &info, bool repeatLastBinding=false)
Attempts to bind to a curve mathcing curveName().
virtual PlotExpression * clone() const
Creates a deep copy of this object.
An adaptor class converting from PlotInstance data to QwtSeriesData.
Definition: plotinstancesampler.h:24
Supports multiple bindings of the same expression to different curves.
Definition: plotbindingtracker.h:34
PlotSample(const QString &curveName, bool curveRegularExpression=false)
Create a PlotSample which matches just a curve name in binding.
Details how an expression is referencing a plot sample.
Definition: plotsample.h:23
char quote
The quote char parsed to define the ID.
Definition: plotsample.h:26
bool regex
True if name is a regular expression.
Definition: plotsample.h:27
PlotSampleId(const QString &name=QString(), char quote= '\0', bool regex=false)
Constructor.
Definition: plotsample.h:33
Core data for binding a PlotExpression.
Definition: plotexpressionbinddomain.h:49
~PlotSample()
Destructor.
Holds data for a single curve.
Definition: plotinstance.h:43
BindResult
Return values for the PlotExpression::bind() method.
Definition: plotexpressionbinddomain.h:15
PlotSampleId(const PlotSampleId &other)
Copy constructor.
Definition: plotsample.h:44
QTextStream & operator<<(QTextStream &stream, const PlotSampleId &sid)
Stream operator for writing a PlotSampleId to QTextStream.
QString name
The plot name or regular expression.
Definition: plotsample.h:25
This expression class binds and references an existing curve.
Definition: plotsample.h:95
PlotSampleId(const QString &name, bool regex)
Constructor for unquoted references.
Definition: plotsample.h:39
bool operator!() const
Negation operator: true if not set.
Definition: plotsample.h:53
A PlotExpression represents an operation in a plot equation.
Definition: plotexpression.h:91
void fixQuote()
Ensures the quote character is set for regular expressions, defaulting to (').
Definition: plotsample.h:56
virtual void unbind()
Releases the current binding (if any).
virtual double sample(double sampleTime) const
Called to generate a sample at sampleTime.