OpenCurves
0.9
|
Holds data for a single curve. More...
#include <plotinstance.h>
Public Types | |
enum | Flag { DataComplete = (1 << 0), RingBuffer = (1 << 1), ExplicitColour = (1 << 2), FilterNaN = (1 << 3), FilterInf = (1 << 4), ExplicitTime = (1 << 5) } |
Status, control and display flags. More... | |
enum | Defaults { DefaultSymbolSize = 5 } |
Some default values for plots. More... | |
Public Member Functions | |
PlotInstance (const PlotSource::Ptr &source) | |
Create a plot instance from the given source. More... | |
PlotInstance (const PlotInstance &other) | |
Copy constructor. | |
~PlotInstance () | |
Destructor. | |
PlotSource & | source () |
Access the plot source. More... | |
const PlotSource & | source () const |
Access the plot source. More... | |
void | setDefaultProperties () |
Restore the default style, colour, etc properties. | |
QString | name () const |
Get the plot name. More... | |
void | setName (QString name) |
Set the plot name. More... | |
int | style () const |
Get the draw style: matches QwtPlotCurve::CurveStyle . More... | |
void | setStyle (unsigned style) |
Set the draw style: matches QwtPlotCurve::CurveStyle . More... | |
unsigned | width () const |
Get the draw width. More... | |
void | setWidth (unsigned width) |
Set the pen draw width: limited to 255. More... | |
int | symbol () const |
Get the draw symbol: matches QwtSymbol::Style . More... | |
void | setSymbol (int symbol) |
Set the draw symbol: matches QwtSymbol::Style . More... | |
unsigned | symbolSize () const |
Get the symbol size. More... | |
void | setSymbolSize (unsigned size) |
Set the symbol size: limited to 255. More... | |
const std::vector< QPointF > & | data () const |
Direct access to the data buffer. More... | |
const QRgb & | colour () const |
Get the display colour for the plot. More... | |
void | setColour (const QRgb &colour, bool markExplicit=true) |
Set the display colour, making it explicit unless requested otherwise. More... | |
const PlotExpression * | expression () const |
Get the expression which generated this plot (Expression source() only). More... | |
void | setExpression (const PlotExpression *expression) |
Sets the expression which generated this plot. More... | |
size_t | ringHead () const |
The read head of the ring buffer. More... | |
std::uint16_t | flags () const |
Get the status, control and display Flag values. More... | |
bool | testFlags (std::uint16_t flags) |
Sets that all flags are set in the flags() member. More... | |
bool | dataComplete () const |
Is data loading complete? More... | |
void | setComplete () |
Marks data complete. | |
bool | isRingBuffer () const |
Is this a ring buffer? More... | |
void | makeRingBuffer (size_t bufferSize) |
Converts the plot data to a ring buffer of the given size. More... | |
bool | explicitColour () const |
Using an explicit colour? More... | |
bool | filterNaN () const |
Filter NaN values on display? More... | |
void | setFilterNaN (bool filter) |
Set or clear NaN filtering. More... | |
bool | filterInf () const |
Filter infinite values on display? More... | |
void | setFilterInf (bool filter) |
Set or clear infinite value filtering. More... | |
bool | explicitTime () const |
Has the curve been generated with explicit time values? More... | |
void | setExplicitTime (bool explct) |
Set the state of the ExplicitTime Flag . More... | |
QPointF | sample (size_t index) const |
Samples the point at the given index. More... | |
void | addPoint (const QPointF &p) |
Add a point to the back buffer (thread-safe). More... | |
void | addPoints (const QPointF *points, size_t pointCount) |
Add multiple points to the back buffer. More... | |
bool | migrateBuffer () |
Migrate from the back buffer to data() . Main thread only. | |
PlotInstance & | operator= (const PlotInstance &other) |
Assignment operator. More... | |
Holds data for a single curve.
Supports thread-safe, double buffered loading. The data source thread should call addPoint()
or addPoints()
to add data. Meanwhile the main thread should periodically call migrateBuffer()
to move data into the front buffer. Note that only the back buffer is thread-safe. The sample()
function should only be called either by the main thread (the same thread doing the migration) or once all data are loaded.
While data can be sampled directly via sample()
, a PlotInstanceSampler
should be used to resolve time values and time scaling.
data
array is fixed size and added to as a ring buffer. The ringHead
marks the start of the ring buffer. The ring buffer is full once the data
size equals its capacity.The PlotInstanceSampler
handles sampling in ring buffer mode.
enum PlotInstance::Flag |
Status, control and display flags.
Enumerator | |
---|---|
DataComplete |
Set when all data have been loaded and the curve is complete. No further calls to |
RingBuffer |
Set if the |
ExplicitColour |
Set if the graph has been assigned an explicit colour. No colour shift will be performed in plotting the curve. |
FilterNaN |
Set to filter NaN values, replacing them with zero. |
FilterInf |
Set to filter infinite values, replacing them zero. |
ExplicitTime |
Has the curve been generated with explicit time samples? Some generated curves have explicit times and are not subject to time scaling, time shift or time columns. Such curves may need to be renenerated if timing information is changed. |
PlotInstance::PlotInstance | ( | const PlotSource::Ptr & | source | ) |
Create a plot instance from the given source.
source | The plot source. |
void PlotInstance::addPoint | ( | const QPointF & | p | ) |
Add a point to the back buffer (thread-safe).
p | The point to add. |
void PlotInstance::addPoints | ( | const QPointF * | points, |
size_t | pointCount | ||
) |
Add multiple points to the back buffer.
points | The points array to add. |
pointCount | The element count of points . |
|
inline |
Get the display colour for the plot.
May be colour shifted when explicitColour()
is false.
Referenced by setColour().
|
inline |
Direct access to the data buffer.
Use sample()
for controlled access including ring buffer handling.
|
inline |
Is data loading complete?
migrateBuffer()
required. References DataComplete.
|
inline |
|
inline |
Has the curve been generated with explicit time values?
References ExplicitTime.
|
inline |
Get the expression which generated this plot (Expression
source()
only).
Note: this is a shared pointer.
Referenced by setExpression().
|
inline |
|
inline |
|
inline |
Get the status, control and display Flag
values.
Flag
values. Referenced by testFlags().
|
inline |
void PlotInstance::makeRingBuffer | ( | size_t | bufferSize | ) |
Converts the plot data to a ring buffer of the given size.
This may (safely) resize the existing ring buffer if already a ring buffer.
bufferSize | The size of the ring buffer. |
|
inline |
PlotInstance& PlotInstance::operator= | ( | const PlotInstance & | other | ) |
Assignment operator.
Copies all members excluding the data back buffer.
other | The object to copy. |
|
inline |
QPointF PlotInstance::sample | ( | size_t | index | ) | const |
Samples the point at the given index.
This caters for ring buffer sampling.
For a non-ring buffer, the index
must be in range. For a ring buffer, the index is wrapped into the valid range, except when the buffer is empty.
index | The sampling index. |
|
inline |
Set the display colour, making it explicit unless requested otherwise.
colour | The new colour. |
markExplicit | True to make explictColour() true, preventing colour shift (default). |
References colour(), and ExplicitColour.
|
inline |
Set the state of the ExplicitTime
Flag
.
explct | True to set ExplicitTime , false to clear. |
References ExplicitTime.
|
inline |
Sets the expression which generated this plot.
Should only be called for Expression
source()
.
expression | The generating expression. |
References expression().
|
inline |
Set or clear infinite value filtering.
filter | True to turn on filtering, false to turn off. |
References FilterInf.
|
inline |
Set or clear NaN filtering.
filter | True to turn on filtering, false to turn off. |
References FilterNaN.
|
inline |
|
inline |
Set the draw style: matches QwtPlotCurve::CurveStyle
.
style | The new style. |
|
inline |
Set the draw symbol: matches QwtSymbol::Style
.
symbol | The new symbol. |
|
inline |
Set the symbol size: limited to 255.
size | The new symbol size. |
|
inline |
Set the pen draw width: limited to 255.
width | The new width. |
|
inline |
Access the plot source.
PlotSource
owning this plot.
|
inline |
Access the plot source.
PlotSource
owning this plot.
|
inline |
Get the draw style: matches QwtPlotCurve::CurveStyle
.
|
inline |
Get the draw symbol: matches QwtSymbol::Style
.
|
inline |
Get the symbol size.
|
inline |
|
inline |
Get the draw width.