OpenCurves  0.9
PlotInstance Class Reference

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.
 
PlotSourcesource ()
 Access the plot source. More...
 
const PlotSourcesource () 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 PlotExpressionexpression () 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.
 
PlotInstanceoperator= (const PlotInstance &other)
 Assignment operator. More...
 

Detailed Description

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.

Ring Buffer Mode
The structure may be operating in ring buffer mode, in which case the 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.

Member Enumeration Documentation

Some default values for plots.

Enumerator
DefaultSymbolSize 

Default size for displaying plot symbols.

Status, control and display flags.

Enumerator
DataComplete 

Set when all data have been loaded and the curve is complete.

No further calls to migrateBuffer() required.

RingBuffer 

Set if the data member acts as a ring buffer. Affects sample(), addPoint(), addPoints().

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.

Constructor & Destructor Documentation

PlotInstance::PlotInstance ( const PlotSource::Ptr source)

Create a plot instance from the given source.

Parameters
sourceThe plot source.

Member Function Documentation

void PlotInstance::addPoint ( const QPointF &  p)

Add a point to the back buffer (thread-safe).

Parameters
pThe point to add.
void PlotInstance::addPoints ( const QPointF *  points,
size_t  pointCount 
)

Add multiple points to the back buffer.

Parameters
pointsThe points array to add.
pointCountThe element count of points.
const QRgb& PlotInstance::colour ( ) const
inline

Get the display colour for the plot.

May be colour shifted when explicitColour() is false.

Returns
The preferred display colour.

Referenced by setColour().

const std::vector<QPointF>& PlotInstance::data ( ) const
inline

Direct access to the data buffer.

Use sample() for controlled access including ring buffer handling.

Returns
The internal data buffer (visible buffer).
bool PlotInstance::dataComplete ( ) const
inline

Is data loading complete?

Returns
True if all data are present. No further calls to migrateBuffer() required.

References DataComplete.

bool PlotInstance::explicitColour ( ) const
inline

Using an explicit colour?

Returns
True if using an explicit colour.

References ExplicitColour.

bool PlotInstance::explicitTime ( ) const
inline

Has the curve been generated with explicit time values?

Returns
True if generated with explicit time values.

References ExplicitTime.

const PlotExpression* PlotInstance::expression ( ) const
inline

Get the expression which generated this plot (Expression source() only).

Note: this is a shared pointer.

Returns
The generating expression.

Referenced by setExpression().

bool PlotInstance::filterInf ( ) const
inline

Filter infinite values on display?

Returns
True if filtering infinite values.

References FilterInf.

bool PlotInstance::filterNaN ( ) const
inline

Filter NaN values on display?

Returns
True if filtering NaN.

References FilterNaN.

std::uint16_t PlotInstance::flags ( ) const
inline

Get the status, control and display Flag values.

Returns
The set Flag values.

Referenced by testFlags().

bool PlotInstance::isRingBuffer ( ) const
inline

Is this a ring buffer?

Returns
True if using a ring buffer.

References RingBuffer.

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.

Parameters
bufferSizeThe size of the ring buffer.
QString PlotInstance::name ( ) const
inline

Get the plot name.

Returns
The plot name.

Referenced by setName().

PlotInstance& PlotInstance::operator= ( const PlotInstance other)

Assignment operator.

Copies all members excluding the data back buffer.

Parameters
otherThe object to copy.
size_t PlotInstance::ringHead ( ) const
inline

The read head of the ring buffer.

Always zero if not isRingBuffer().

Returns
The read head index.
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.

Parameters
indexThe sampling index.
void PlotInstance::setColour ( const QRgb &  colour,
bool  markExplicit = true 
)
inline

Set the display colour, making it explicit unless requested otherwise.

Parameters
colourThe new colour.
markExplicitTrue to make explictColour() true, preventing colour shift (default).

References colour(), and ExplicitColour.

void PlotInstance::setExplicitTime ( bool  explct)
inline

Set the state of the ExplicitTime Flag.

Parameters
explctTrue to set ExplicitTime, false to clear.

References ExplicitTime.

void PlotInstance::setExpression ( const PlotExpression expression)
inline

Sets the expression which generated this plot.

Should only be called for Expression source().

Parameters
expressionThe generating expression.

References expression().

void PlotInstance::setFilterInf ( bool  filter)
inline

Set or clear infinite value filtering.

Parameters
filterTrue to turn on filtering, false to turn off.

References FilterInf.

void PlotInstance::setFilterNaN ( bool  filter)
inline

Set or clear NaN filtering.

Parameters
filterTrue to turn on filtering, false to turn off.

References FilterNaN.

void PlotInstance::setName ( QString  name)
inline

Set the plot name.

Parameters
nameThe new plot name.

References name().

void PlotInstance::setStyle ( unsigned  style)
inline

Set the draw style: matches QwtPlotCurve::CurveStyle.

Parameters
styleThe new style.
void PlotInstance::setSymbol ( int  symbol)
inline

Set the draw symbol: matches QwtSymbol::Style.

Parameters
symbolThe new symbol.
void PlotInstance::setSymbolSize ( unsigned  size)
inline

Set the symbol size: limited to 255.

Parameters
sizeThe new symbol size.
void PlotInstance::setWidth ( unsigned  width)
inline

Set the pen draw width: limited to 255.

Parameters
widthThe new width.
PlotSource & PlotInstance::source ( )
inline

Access the plot source.

Returns
The PlotSource owning this plot.
const PlotSource & PlotInstance::source ( ) const
inline

Access the plot source.

Returns
The PlotSource owning this plot.
int PlotInstance::style ( ) const
inline

Get the draw style: matches QwtPlotCurve::CurveStyle.

Returns
The style type.
int PlotInstance::symbol ( ) const
inline

Get the draw symbol: matches QwtSymbol::Style.

Returns
The symbol type.
unsigned PlotInstance::symbolSize ( ) const
inline

Get the symbol size.

Returns
The symbol size.
bool PlotInstance::testFlags ( std::uint16_t  flags)
inline

Sets that all flags are set in the flags() member.

Returns
True if all bits an values are set internally.

References flags().

unsigned PlotInstance::width ( ) const
inline

Get the draw width.

Returns
The line width.

The documentation for this class was generated from the following file: