Qwt User's Guide 6.0.2

- Main Page
- Related Pages
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions
QwtPlotCurve Class Reference

`#include <qwt_plot_curve.h>`

Inheritance diagram for QwtPlotCurve:
[legend]

List of all members.

## Public Types
enum | CurveAttribute { Inverted = 0x01, Fitted = 0x02 }
typedef QFlags< CurveAttribute > | CurveAttributes
enum | CurveStyle { NoCurve = -1, Lines, Sticks, Steps, Dots, UserCurve = 100 }
enum | LegendAttribute { LegendNoAttribute = 0x00, LegendShowLine = 0x01, LegendShowSymbol = 0x02, LegendShowBrush = 0x04 }
typedef QFlags< LegendAttribute > | LegendAttributes
enum | PaintAttribute { ClipPolygons = 0x01, CacheSymbols = 0x02 }
typedef QFlags< PaintAttribute > | PaintAttributes

## Public Member Functions
| QwtPlotCurve (const QString &title=QString::null)
| QwtPlotCurve (const QwtText &title)
virtual | ~QwtPlotCurve ()
double | baseline () const
const QBrush & | brush () const
int | closestPoint (const QPoint &pos, double *dist=NULL) const
QwtCurveFitter * | curveFitter () const
virtual void | drawLegendIdentifier (QPainter *, const QRectF &) const
virtual void | drawSeries (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
double | maxXValue () const
double | maxYValue () const
double | minXValue () const
double | minYValue () const
const QPen & | pen () const
virtual int | rtti () const
void | setBaseline (double ref)
void | setBrush (const QBrush &)
void | setCurveAttribute (CurveAttribute, bool on=true)
void | setCurveFitter (QwtCurveFitter *)
void | setLegendAttribute (LegendAttribute, bool on=true)
void | setPaintAttribute (PaintAttribute, bool on=true)
void | setPen (const QPen &)
void | setRawSamples (const double *xData, const double *yData, int size)
void | setSamples (const double *xData, const double *yData, int size)
void | setSamples (const QVector< double > &xData, const QVector< double > &yData)
void | setSamples (const QVector< QPointF > &)
void | setStyle (CurveStyle style)
void | setSymbol (const QwtSymbol *s)
CurveStyle | style () const
const QwtSymbol * | symbol () const
bool | testCurveAttribute (CurveAttribute) const
bool | testLegendAttribute (LegendAttribute) const
bool | testPaintAttribute (PaintAttribute) const
virtual void | updateLegend (QwtLegend *) const
Public Member Functions inherited from QwtPlotSeriesItem< QPointF >
| QwtPlotSeriesItem (const QString &title=QString::null)
| QwtPlotSeriesItem (const QwtText &title)
virtual | ~QwtPlotSeriesItem ()
virtual QRectF | boundingRect () const
QwtSeriesData< QPointF > * | data ()
const QwtSeriesData< QPointF > * | data () const
size_t | dataSize () const
QPointF | sample (int index) const
void | setData (QwtSeriesData< QPointF > *)
virtual void | updateScaleDiv (const QwtScaleDiv &, const QwtScaleDiv &)
Public Member Functions inherited from QwtPlotAbstractSeriesItem
| QwtPlotAbstractSeriesItem (const QString &title=QString::null)
| QwtPlotAbstractSeriesItem (const QwtText &title)
virtual | ~QwtPlotAbstractSeriesItem ()
virtual void | draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &) const
Qt::Orientation | orientation () const
void | setOrientation (Qt::Orientation)
Public Member Functions inherited from QwtPlotItem
| QwtPlotItem (const QwtText &title=QwtText())
virtual | ~QwtPlotItem ()
void | attach (QwtPlot *plot)
void | detach ()
void | hide ()
bool | isVisible () const
virtual void | itemChanged ()
virtual QWidget * | legendItem () const
QRectF | paintRect (const QwtScaleMap &, const QwtScaleMap &) const
QwtPlot * | plot () const
QRectF | scaleRect (const QwtScaleMap &, const QwtScaleMap &) const
void | setAxes (int xAxis, int yAxis)
void | setItemAttribute (ItemAttribute, bool on=true)
void | setRenderHint (RenderHint, bool on=true)
void | setTitle (const QString &title)
void | setTitle (const QwtText &title)
virtual void | setVisible (bool)
void | setXAxis (int axis)
void | setYAxis (int axis)
void | setZ (double z)
void | show ()
bool | testItemAttribute (ItemAttribute) const
bool | testRenderHint (RenderHint) const
const QwtText & | title () const
int | xAxis () const
int | yAxis () const
double | z () const
Public Member Functions inherited from QwtLegendItemManager
| QwtLegendItemManager ()
virtual | ~QwtLegendItemManager ()

## Protected Member Functions
void | closePolyline (QPainter *, const QwtScaleMap &, const QwtScaleMap &, QPolygonF &) const
virtual void | drawCurve (QPainter *, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
void | drawDots (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
void | drawLines (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
void | drawSteps (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
void | drawSticks (QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
virtual void | drawSymbols (QPainter *, const QwtSymbol &, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
virtual void | fillCurve (QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRectF &canvasRect, QPolygonF &) const
void | init ()

## Additional Inherited Members
Protected Attributes inherited from QwtPlotSeriesItem< QPointF >
QwtSeriesData< QPointF > * | d_series

## Detailed Description

A plot item, that represents a series of points.

A curve is the representation of a series of points in the x-y plane. It supports different display styles, interpolation ( f.e. spline ) and symbols.

Usage
  a) Assign curve properties
    When a curve is created, it is configured to draw black solid lines with in QwtPlotCurve::Lines style and no symbols. You can change this by calling setPen(), setStyle() and setSymbol().
  b) Connect/Assign data.
    QwtPlotCurve gets its points using a QwtSeriesData object offering a bridge to the real storage of the points ( like QAbstractItemModel ). There are several convenience classes derived from QwtSeriesData, that also store the points inside ( like QStandardItemModel ). QwtPlotCurve also offers a couple of variations of setSamples(), that build QwtSeriesData objects from arrays internally.
  c) Attach the curve to a plot
    See QwtPlotItem::attach()

Example:
  see examples/bode

See also:
  QwtPointSeriesData, QwtSymbol, QwtScaleMap

## Member Enumeration Documentation

enum QwtPlotCurve::CurveAttribute

Attribute for drawing the curve

See also:
  setCurveAttribute(), testCurveAttribute(), curveFitter()

Enumerator:

  Inverted | For QwtPlotCurve::Steps only. Draws a step function from the right to the left.
  Fitted | Only in combination with QwtPlotCurve::Lines A QwtCurveFitter tries to interpolate/smooth the curve, before it is painted. Note: Curve fitting requires temorary memory for calculating coefficients and additional points. If painting in QwtPlotCurve::Fitted mode is slow it might be better to fit the points, before they are passed to QwtPlotCurve.

enum QwtPlotCurve::CurveStyle

Curve styles.

See also:
  setStyle(), style()

Enumerator:

  NoCurve | Don't draw a curve. Note: This doesn't affect the symbols.
  Lines | Connect the points with straight lines. The lines might be interpolated depending on the 'Fitted' attribute. Curve fitting can be configured using setCurveFitter().
  Sticks | Draw vertical or horizontal sticks ( depending on the orientation() ) from a baseline which is defined by setBaseline().
  Steps | Connect the points with a step function. The step function is drawn from the left to the right or vice versa, depending on the QwtPlotCurve::Inverted attribute.
  Dots | Draw dots at the locations of the data points. Note: This is different from a dotted line (see setPen()), and faster as a curve in QwtPlotCurve::NoStyle style and a symbol painting a point.
  UserCurve | Styles >= QwtPlotCurve::UserCurve are reserved for derived classes of QwtPlotCurve that overload drawCurve() with additional application specific curve types.

enum QwtPlotCurve::LegendAttribute

Attributes how to represent the curve on the legend

See also:
  setLegendAttribute(), testLegendAttribute(), drawLegendIdentifier()

Enumerator:

  LegendNoAttribute | QwtPlotCurve tries to find a color representing the curve and paints a rectangle with it.
  LegendShowLine | If the style() is not QwtPlotCurve::NoCurve a line is painted with the curve pen().
  LegendShowSymbol | If the curve has a valid symbol it is painted.
  LegendShowBrush | If the curve has a brush a rectangle filled with the curve brush() is painted.

enum QwtPlotCurve::PaintAttribute

Attributes to modify the drawing algorithm. The default setting enables ClipPolygons

See also:
  setPaintAttribute(), testPaintAttribute()

Enumerator:

  ClipPolygons | Clip polygons before painting them. In situations, where points are far outside the visible area (f.e when zooming deep) this might be a substantial improvement for the painting performance
  CacheSymbols | Paint the symbol to a QPixmap and paint the pixmap instead rendering the symbol for each point. The flag has no effect, when the curve is not painted to the canvas ( f.e when exporting the plot to a PDF document ).

## Constructor & Destructor Documentation

QwtPlotCurve::QwtPlotCurve | ( | const QString & | title = `QString::null` | ) |
| explicit

Constructor

Parameters:

  title | Title of the curve

QwtPlotCurve::QwtPlotCurve | ( | const QwtText & | title | ) |
| explicit

Constructor

Parameters:

  title | Title of the curve

## Member Function Documentation

double QwtPlotCurve::baseline | ( |  | ) | const

Returns:
  Value of the baseline

See also:
  setBaseline()

const QBrush & QwtPlotCurve::brush | ( |  | ) | const

Returns:
  Brush used to fill the area between lines and the baseline

See also:
  setBrush(), setBaseline(), baseline()

void QwtPlotCurve::closePolyline | ( | QPainter * | painter,
|  | const QwtScaleMap & | xMap,
|  | const QwtScaleMap & | yMap,
|  | QPolygonF & | polygon
| ) |  | const
| protected

Complete a polygon to be a closed polygon including the area between the original polygon and the baseline.

Parameters:

  painter | Painter
  xMap | X map
  yMap | Y map
  polygon | Polygon to be completed

int QwtPlotCurve::closestPoint | ( | const QPoint & | pos,
|  | double * | dist = `NULL`
| ) |  | const

Find the closest curve point for a specific position

Parameters:

  pos | Position, where to look for the closest curve point
  dist | If dist != NULL, closestPoint() returns the distance between the position and the clostest curve point

Returns:
  Index of the closest curve point, or -1 if none can be found ( f.e when the curve has no points )

Note:
  closestPoint() implements a dumb algorithm, that iterates over all points

QwtCurveFitter * QwtPlotCurve::curveFitter | ( |  | ) | const

Get the curve fitter. If curve fitting is disabled NULL is returned.

Returns:
  Curve fitter

See also:
  setCurveFitter(), Fitted

void QwtPlotCurve::drawCurve | ( | QPainter * | painter,
|  | int | style,
|  | const QwtScaleMap & | xMap,
|  | const QwtScaleMap & | yMap,
|  | const QRectF & | canvasRect,
|  | int | from,
|  | int | to
| ) |  | const
| protected virtual

Draw the line part (without symbols) of a curve interval.

Parameters:

  painter | Painter
  style | curve style, see QwtPlotCurve::CurveStyle
  xMap | x map
  yMap | y map
  canvasRect | Contents rect of the canvas
  from | index of the first point to be painted
  to | index of the last point to be painted

See also:
  draw(), drawDots(), drawLines(), drawSteps(), drawSticks()

void QwtPlotCurve::drawDots | ( | QPainter * | painter,
|  | const QwtScaleMap & | xMap,
|  | const QwtScaleMap & | yMap,
|  | const QRectF & | canvasRect,
|  | int | from,
|  | int | to
| ) |  | const
| protected

Draw dots

Parameters:

  painter | Painter
  xMap | x map
  yMap | y map
  canvasRect | Contents rect of the canvas
  from | index of the first point to be painted
  to | index of the last point to be painted

See also:
  draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()

void QwtPlotCurve::drawLegendIdentifier | ( | QPainter * | painter,
|  | const QRectF & | rect
| ) |  | const
| virtual

Draw the identifier representing the curve on the legend.

Parameters:

  painter | Painter
  rect | Bounding rectangle for the identifier

See also:
  setLegendAttribute(), QwtPlotItem::Legend

Reimplemented from QwtLegendItemManager.

void QwtPlotCurve::drawLines | ( | QPainter * | painter,
|  | const QwtScaleMap & | xMap,
|  | const QwtScaleMap & | yMap,
|  | const QRectF & | canvasRect,
|  | int | from,
|  | int | to
| ) |  | const
| protected

Draw lines.

If the CurveAttribute Fitted is enabled a QwtCurveFitter tries to interpolate/smooth the curve, before it is painted.

Parameters:

  painter | Painter
  xMap | x map
  yMap | y map
  canvasRect | Contents rect of the canvas
  from | index of the first point to be painted
  to | index of the last point to be painted

See also:
  setCurveAttribute(), setCurveFitter(), draw(), drawLines(), drawDots(), drawSteps(), drawSticks()

void QwtPlotCurve::drawSeries | ( | QPainter * | painter,
|  | const QwtScaleMap & | xMap,
|  | const QwtScaleMap & | yMap,
|  | const QRectF & | canvasRect,
|  | int | from,
|  | int | to
| ) |  | const
| virtual

Draw an interval of the curve

Parameters:

  painter | Painter
  xMap | Maps x-values into pixel coordinates.
  yMap | Maps y-values into pixel coordinates.
  canvasRect | Contents rect of the canvas
  from | Index of the first point to be painted
  to | Index of the last point to be painted. If to < 0 the curve will be painted to its last point.

See also:
  drawCurve(), drawSymbols(),

Implements QwtPlotAbstractSeriesItem.

void QwtPlotCurve::drawSteps | ( | QPainter * | painter,
|  | const QwtScaleMap & | xMap,
|  | const QwtScaleMap & | yMap,
|  | const QRectF & | canvasRect,
|  | int | from,
|  | int | to
| ) |  | const
| protected

Draw step function

The direction of the steps depends on Inverted attribute.

Parameters:

  painter | Painter
  xMap | x map
  yMap | y map
  canvasRect | Contents rect of the canvas
  from | index of the first point to be painted
  to | index of the last point to be painted

See also:
  CurveAttribute, setCurveAttribute(), draw(), drawCurve(), drawDots(), drawLines(), drawSticks()

void QwtPlotCurve::drawSticks | ( | QPainter * | painter,
|  | const QwtScaleMap & | xMap,
|  | const QwtScaleMap & | yMap,
|  | const QRectF & | canvasRect,
|  | int | from,
|  | int | to
| ) |  | const
| protected

Draw sticks

Parameters:

  painter | Painter
  xMap | x map
  yMap | y map
  canvasRect | Contents rect of the canvas
  from | index of the first point to be painted
  to | index of the last point to be painted

See also:
  draw(), drawCurve(), drawDots(), drawLines(), drawSteps()

void QwtPlotCurve::drawSymbols | ( | QPainter * | painter,
|  | const QwtSymbol & | symbol,
|  | const QwtScaleMap & | xMap,
|  | const QwtScaleMap & | yMap,
|  | const QRectF & | canvasRect,
|  | int | from,
|  | int | to
| ) |  | const
| protected virtual

Draw symbols

Parameters:

  painter | Painter
  symbol | Curve symbol
  xMap | x map
  yMap | y map
  canvasRect | Contents rect of the canvas
  from | Index of the first point to be painted
  to | Index of the last point to be painted

See also:
  setSymbol(), drawSeries(), drawCurve()

void QwtPlotCurve::fillCurve | ( | QPainter * | painter,
|  | const QwtScaleMap & | xMap,
|  | const QwtScaleMap & | yMap,
|  | const QRectF & | canvasRect,
|  | QPolygonF & | polygon
| ) |  | const
| protected virtual

Fill the area between the curve and the baseline with the curve brush

Parameters:

  painter | Painter
  xMap | x map
  yMap | y map
  canvasRect | Contents rect of the canvas
  polygon | Polygon - will be modified !

See also:
  setBrush(), setBaseline(), setStyle()

const QPen & QwtPlotCurve::pen | ( |  | ) | const

Returns:
  Pen used to draw the lines

See also:
  setPen(), brush()

int QwtPlotCurve::rtti | ( |  | ) | const
| virtual

Returns:
  QwtPlotItem::Rtti_PlotCurve

Reimplemented from QwtPlotItem.

void QwtPlotCurve::setBaseline | ( | double | value | ) |

Set the value of the baseline.

The baseline is needed for filling the curve with a brush or the Sticks drawing style.

The interpretation of the baseline depends on the orientation(). With Qt::Horizontal, the baseline is interpreted as a horizontal line at y = baseline(), with Qt::Vertical, it is interpreted as a vertical line at x = baseline().

The default value is 0.0.

Parameters:

  value | Value of the baseline

See also:
  baseline(), setBrush(), setStyle(), QwtPlotAbstractSeriesItem::orientation()

void QwtPlotCurve::setBrush | ( | const QBrush & | brush | ) |

Assign a brush.

In case of brush.style() != QBrush::NoBrush and style() != QwtPlotCurve::Sticks the area between the curve and the baseline will be filled.

In case !brush.color().isValid() the area will be filled by pen.color(). The fill algorithm simply connects the first and the last curve point to the baseline. So the curve data has to be sorted (ascending or descending).

Parameters:

  brush | New brush

See also:
  brush(), setBaseline(), baseline()

void QwtPlotCurve::setCurveAttribute | ( | CurveAttribute | attribute,
|  | bool | on = `true`
| ) |  |

Specify an attribute for drawing the curve

Parameters:

  attribute | Curve attribute
  on | On/Off

/sa testCurveAttribute(), setCurveFitter()

void QwtPlotCurve::setCurveFitter | ( | QwtCurveFitter * | curveFitter | ) |

Assign a curve fitter

The curve fitter "smooths" the curve points, when the Fitted CurveAttribute is set. setCurveFitter(NULL) also disables curve fitting.

The curve fitter operates on the translated points ( = widget coordinates) to be functional for logarithmic scales. Obviously this is less performant for fitting algorithms, that reduce the number of points.

For situations, where curve fitting is used to improve the performance of painting huge series of points it might be better to execute the fitter on the curve points once and to cache the result in the QwtSeriesData object.

Parameters:

  curveFitter() | Curve fitter

See also:
  Fitted

void QwtPlotCurve::setLegendAttribute | ( | LegendAttribute | attribute,
|  | bool | on = `true`
| ) |  |

Specify an attribute how to draw the legend identifier

Parameters:

  attribute | Attribute
  on | On/Off /sa testLegendAttribute()

void QwtPlotCurve::setPaintAttribute | ( | PaintAttribute | attribute,
|  | bool | on = `true`
| ) |  |

Specify an attribute how to draw the curve

Parameters:

  attribute | Paint attribute
  on | On/Off

See also:
  testPaintAttribute()

void QwtPlotCurve::setPen | ( | const QPen & | pen | ) |

Assign a pen

Parameters:

  pen | New pen

See also:
  pen(), brush()

void QwtPlotCurve::setRawSamples | ( | const double * | xData,
|  | const double * | yData,
|  | int | size
| ) |  |

Initialize the data by pointing to memory blocks which are not managed by QwtPlotCurve.

setRawSamples is provided for efficiency. It is important to keep the pointers during the lifetime of the underlying QwtCPointerData class.

Parameters:

  xData | pointer to x data
  yData | pointer to y data
  size | size of x and y

See also:
  QwtCPointerData

void QwtPlotCurve::setSamples | ( | const double * | xData,
|  | const double * | yData,
|  | int | size
| ) |  |

Set data by copying x- and y-values from specified memory blocks. Contrary to setRawSamples(), this function makes a 'deep copy' of the data.

Parameters:

  xData | pointer to x values
  yData | pointer to y values
  size | size of xData and yData

See also:
  QwtPointArrayData

void QwtPlotCurve::setSamples | ( | const QVector< double > & | xData,
|  | const QVector< double > & | yData
| ) |  |

Initialize data with x- and y-arrays (explicitly shared)

Parameters:

  xData | x data
  yData | y data

See also:
  QwtPointArrayData

void QwtPlotCurve::setSamples | ( | const QVector< QPointF > & | samples | ) |

Initialize data with an array of points (explicitly shared).

Parameters:

  samples | Vector of points

void QwtPlotCurve::setStyle | ( | CurveStyle | style | ) |

Set the curve's drawing style

Parameters:

  style | Curve style

See also:
  style()

void QwtPlotCurve::setSymbol | ( | const QwtSymbol * | symbol | ) |

Assign a symbol

The curve will take the ownership of the symbol, hence the previously set symbol will be delete by setting a new one. If `symbol` is `NULL` no symbol will be drawn.

Parameters:

  symbol | Symbol

See also:
  symbol()

QwtPlotCurve::CurveStyle QwtPlotCurve::style | ( |  | ) | const

Return the current style

See also:
  setStyle()

const QwtSymbol * QwtPlotCurve::symbol | ( |  | ) | const

Returns:
  Current symbol or NULL, when no symbol has been assigned

See also:
  setSymbol()

bool QwtPlotCurve::testCurveAttribute | ( | CurveAttribute | attribute | ) | const

Returns:
  true, if attribute is enabled

See also:
  setCurveAttribute()

bool QwtPlotCurve::testLegendAttribute | ( | LegendAttribute | attribute | ) | const

Return the current paint attributes.

See also:
  setLegendAttribute()

bool QwtPlotCurve::testPaintAttribute | ( | PaintAttribute | attribute | ) | const

Return the current paint attributes.

See also:
  setPaintAttribute()

void QwtPlotCurve::updateLegend | ( | QwtLegend * | legend | ) | const
| virtual

Update the widget that represents the item on the legend.

Parameters:

  legend | Legend

See also:
  drawLegendIdentifier(), legendItem(), QwtPlotItem::Legend

Reimplemented from QwtPlotItem.