QwtPlotCurve Class Reference

Inheritance diagram for QwtPlotCurve:

Inheritance graph
[legend]
Collaboration diagram for QwtPlotCurve:

Collaboration graph
[legend]
List of all members.

Detailed Description

A class which draws curves.

This class can be used to display data as a curve in the x-y plane. It supports different display styles, spline interpolation and symbols.

Usage
A. Assign curve properties
When a curve is created, it is configured to draw black solid lines with QwtPlotCurve::Lines and no symbols. You can change this by calling setPen(), setStyle() and setSymbol().
B. Assign or change data.
Data can be set in two ways:
  • setData() is overloaded to initialize the x and y data by copying from different data structures with different kind of copy semantics.
  • setRawData() only stores the pointers and size information and is provided for backwards compatibility. This function is less safe (you must not delete the data while they are attached), but has been more efficient, and has been more convenient for dynamically changing data. Use of setData() in combination with a problem-specific subclass of QwtData is always preferrable.
C. Draw
draw() maps the data into pixel coordinates and paints them.
Example:
see examples/curvdemo
See also:
QwtData, QwtSymbol, QwtScaleMap

Definition at line 56 of file qwt_plot_curve.h.

Public Types

enum  CurveType {
  Yfx,
  Xfy
}
enum  CurveStyle {
  NoCurve,
  Lines,
  Sticks,
  Steps,
  Dots,
  UserCurve = 100
}
enum  CurveAttribute {
  Inverted = 1,
  Fitted = 2
}
enum  PaintAttribute {
  PaintFiltered = 1,
  ClipPolygons = 2
}

Public Member Functions

 QwtPlotCurve ()
 QwtPlotCurve (const QwtText &title)
 QwtPlotCurve (const QString &title)
virtual ~QwtPlotCurve ()
virtual int rtti () const
void setCurveType (CurveType)
CurveType curveType () const
void setPaintAttribute (PaintAttribute, bool on=true)
bool testPaintAttribute (PaintAttribute) const
void setRawData (const double *x, const double *y, int size)
void setData (const double *xData, const double *yData, int size)
void setData (const QwtArray< double > &xData, const QwtArray< double > &yData)
void setData (const QPolygonF &data)
void setData (const QwtData &data)
int closestPoint (const QPoint &pos, double *dist=NULL) const
QwtDatadata ()
const QwtDatadata () const
int dataSize () const
double x (int i) const
double y (int i) const
virtual QwtDoubleRect boundingRect () const
double minXValue () const
double maxXValue () const
double minYValue () const
double maxYValue () const
void setCurveAttribute (CurveAttribute, bool on=true)
bool testCurveAttribute (CurveAttribute) const
void setPen (const QPen &)
const QPen & pen () const
void setBrush (const QBrush &)
const QBrush & brush () const
void setBaseline (double ref)
double baseline () const
void setStyle (CurveStyle style)
CurveStyle style () const
void setSymbol (const QwtSymbol &s)
const QwtSymbolsymbol () const
void setCurveFitter (QwtCurveFitter *)
QwtCurveFittercurveFitter () const
virtual void draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const
virtual void draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
void draw (int from, int to) const
virtual void updateLegend (QwtLegend *) const

Protected Member Functions

void init ()
virtual void drawCurve (QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
virtual void drawSymbols (QPainter *p, const QwtSymbol &, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
void drawLines (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
void drawSticks (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
void drawDots (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
void drawSteps (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
void fillCurve (QPainter *, const QwtScaleMap &, const QwtScaleMap &, QwtPolygon &) const
void closePolyline (const QwtScaleMap &, const QwtScaleMap &, QwtPolygon &) const


Member Enumeration Documentation

enum QwtPlotCurve::CurveAttribute
 

Curve attributes.

See also:
setCurveAttribute, testCurveAttribute

Definition at line 85 of file qwt_plot_curve.h.

enum QwtPlotCurve::CurveStyle
 

Curve styles.

See also:
setStyle

Definition at line 69 of file qwt_plot_curve.h.

enum QwtPlotCurve::PaintAttribute
 

Paint attributes

See also:
setPaintAttribute, testPaintAttribute

Definition at line 95 of file qwt_plot_curve.h.


Constructor & Destructor Documentation

QwtPlotCurve::QwtPlotCurve  )  [explicit]
 

Ctor.

Definition at line 138 of file qwt_plot_curve.cpp.

References init().

QwtPlotCurve::QwtPlotCurve const QwtText title  )  [explicit]
 

Ctor.

Parameters:
title title of the curve

Definition at line 148 of file qwt_plot_curve.cpp.

References init().

QwtPlotCurve::QwtPlotCurve const QString &  title  )  [explicit]
 

Ctor.

Parameters:
title title of the curve

Definition at line 158 of file qwt_plot_curve.cpp.

References init().

QwtPlotCurve::~QwtPlotCurve  )  [virtual]
 

Dtor.

Definition at line 165 of file qwt_plot_curve.cpp.


Member Function Documentation

double QwtPlotCurve::baseline  )  const
 

Return the value of the baseline

See also:
setBaseline

Definition at line 1197 of file qwt_plot_curve.cpp.

QwtDoubleRect QwtPlotCurve::boundingRect  )  const [virtual]
 

Returns the bounding rectangle of the curve data. If there is no bounding rect, like for empty data the rectangle is invalid.

See also:
QwtData::boundingRect(), QwtDoubleRect::isValid()

Reimplemented from QwtPlotItem.

Definition at line 437 of file qwt_plot_curve.cpp.

References QwtData::boundingRect().

const QBrush & QwtPlotCurve::brush  )  const
 

Return the brush used to fill the area between lines and the baseline.

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

Definition at line 341 of file qwt_plot_curve.cpp.

void QwtPlotCurve::closePolyline const QwtScaleMap xMap,
const QwtScaleMap yMap,
QwtPolygon &  pa
const [protected]
 

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

Parameters:
xMap X map
yMap Y map
pa Polygon to be completed

Definition at line 1091 of file qwt_plot_curve.cpp.

References QwtScaleMap::transform().

Referenced by fillCurve().

QwtPlotCurve::CurveType QwtPlotCurve::curveType  )  const
 

Return the curve type

See also:
setCurveType()

Definition at line 1027 of file qwt_plot_curve.cpp.

const QwtData & QwtPlotCurve::data  )  const [inline]
 

Returns:
the the curve data

Definition at line 223 of file qwt_plot_curve.h.

QwtData & QwtPlotCurve::data  )  [inline]
 

Returns:
the the curve data

Definition at line 217 of file qwt_plot_curve.h.

Referenced by setData().

int QwtPlotCurve::dataSize  )  const
 

Return the size of the data arrays

See also:
setData()

Definition at line 1206 of file qwt_plot_curve.cpp.

References QwtData::size().

Referenced by closestPoint(), draw(), and drawCurve().

void QwtPlotCurve::draw int  from,
int  to
const
 

Draw a set of points of a curve.

When observing an measurement while it is running, new points have to be added to an existing curve. drawCurve can be used to display them avoiding a complete redraw of the canvas.

Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); will result in faster painting, if the paint engine of the canvas widget supports this feature.

Parameters:
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()

Definition at line 478 of file qwt_plot_curve.cpp.

References QwtPlot::canvas(), and QwtPlotItem::plot().

void QwtPlotCurve::draw QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
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.
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(), draSymbols(),

Definition at line 569 of file qwt_plot_curve.cpp.

References dataSize(), drawCurve(), and drawSymbols().

void QwtPlotCurve::draw QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
const QRect & 
const [virtual]
 

Draw the complete curve.

Parameters:
painter Painter
xMap Maps x-values into pixel coordinates.
yMap Maps y-values into pixel coordinates.
See also:
drawCurve(), drawSymbols()

Implements QwtPlotItem.

Definition at line 454 of file qwt_plot_curve.cpp.

void QwtPlotCurve::drawCurve QPainter *  painter,
int  style,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
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
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()

Definition at line 613 of file qwt_plot_curve.cpp.

References dataSize(), drawDots(), drawLines(), drawSteps(), drawSticks(), and testCurveAttribute().

Referenced by draw().

void QwtPlotCurve::drawDots QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
int  from,
int  to
const [protected]
 

Draw dots

Parameters:
painter Painter
xMap x map
yMap y map
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()

Definition at line 818 of file qwt_plot_curve.cpp.

References QwtPainter::drawPoint(), QwtScaleMap::transform(), x(), and y().

Referenced by drawCurve().

void QwtPlotCurve::drawLines QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
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
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()

Definition at line 659 of file qwt_plot_curve.cpp.

References x(), QwtScaleMap::xTransform(), and y().

Referenced by drawCurve().

void QwtPlotCurve::drawSteps QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
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
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()

Definition at line 914 of file qwt_plot_curve.cpp.

References QwtScaleMap::transform(), x(), and y().

Referenced by drawCurve().

void QwtPlotCurve::drawSticks QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
int  from,
int  to
const [protected]
 

Draw sticks

Parameters:
painter Painter
xMap x map
yMap y map
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()

Definition at line 788 of file qwt_plot_curve.cpp.

References QwtPainter::drawLine(), QwtScaleMap::transform(), x(), and y().

Referenced by drawCurve().

void QwtPlotCurve::drawSymbols QPainter *  painter,
const QwtSymbol symbol,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
int  from,
int  to
const [protected, virtual]
 

Draw symbols.

Parameters:
painter Painter
symbol Curve symbol
xMap x map
yMap y map
from index of the first point to be painted
to index of the last point to be painted
See also:
setSymbol(), draw(), drawCurve()

Definition at line 1128 of file qwt_plot_curve.cpp.

References QwtSymbol::brush(), QwtSymbol::draw(), QwtPainter::metricsMap(), QwtSymbol::pen(), QwtSymbol::size(), symbol(), QwtScaleMap::transform(), x(), and y().

Referenced by draw().

void QwtPlotCurve::fillCurve QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
QwtPolygon &  pa
const [protected]
 

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

Parameters:
painter Painter
xMap x map
yMap y map
pa Polygon
See also:
setBrush(), setBaseline(), setCurveType()

Definition at line 1057 of file qwt_plot_curve.cpp.

References closePolyline(), and QwtPainter::drawPolygon().

void QwtPlotCurve::init  )  [protected]
 

Initialize data members.

Definition at line 174 of file qwt_plot_curve.cpp.

References QwtPlotItem::setItemAttribute(), and QwtPlotItem::setZ().

Referenced by QwtPlotCurve().

double QwtPlotCurve::maxXValue  )  const [inline]
 

boundingRect().right()

Definition at line 139 of file qwt_plot_curve.h.

References QwtPlotItem::boundingRect().

double QwtPlotCurve::maxYValue  )  const [inline]
 

boundingRect().bottom()

Definition at line 143 of file qwt_plot_curve.h.

References QwtPlotItem::boundingRect().

double QwtPlotCurve::minXValue  )  const [inline]
 

boundingRect().left()

Definition at line 137 of file qwt_plot_curve.h.

References QwtPlotItem::boundingRect().

double QwtPlotCurve::minYValue  )  const [inline]
 

boundingRect().top()

Definition at line 141 of file qwt_plot_curve.h.

References QwtPlotItem::boundingRect().

const QPen & QwtPlotCurve::pen  )  const
 

Return the pen used to draw the lines.

See also:
setPen(), brush()

Definition at line 311 of file qwt_plot_curve.cpp.

Referenced by updateLegend().

void QwtPlotCurve::setBaseline double  reference  ) 
 

Set the value of the baseline.

The baseline is needed for filling the curve with a brush or the Sticks drawing style. The default value is 0.0. The interpretation of the baseline depends on the CurveType. With QwtPlotCurve::Yfx, the baseline is interpreted as a horizontal line at y = baseline(), with QwtPlotCurve::Yfy, it is interpreted as a vertical line at x = baseline().

Parameters:
reference baseline
See also:
baseline(), setBrush(), setStyle(), setCurveType()

Definition at line 1184 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

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()

Definition at line 328 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

void QwtPlotCurve::setCurveAttribute CurveAttribute  attribute,
bool  on = true
 

Specify an attribute for drawing the curve.

The attributes can be used to modify the drawing style. The following attributes are defined:

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

Parameters:
attribute Curve attribute
on On/Off
/sa testCurveAttribute(), setCurveFitter()

Definition at line 976 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

void QwtPlotCurve::setCurveType CurveType  curveType  ) 
 

Assign the curve type

QwtPlotCurve::Yfx Draws y as a function of x (the default). The baseline is interpreted as a horizontal line with y = baseline().

QwtPlotCurve::Xfy Draws x as a function of y. The baseline is interpreted as a vertical line with x = baseline().

The baseline is used for aligning the sticks, or filling the curve with a brush.

See also:
curveType()

Definition at line 1014 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

void QwtPlotCurve::setData const QwtData data  ) 
 

Initialize data with a pointer to QwtData.

Parameters:
data Data
See also:
QwtData::copy()

Definition at line 404 of file qwt_plot_curve.cpp.

References QwtData::copy(), data(), and QwtPlotItem::itemChanged().

void QwtPlotCurve::setData const QPolygonF &  data  ) 
 

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

Parameters:
data Data
See also:
QwtPolygonFData

Definition at line 390 of file qwt_plot_curve.cpp.

void QwtPlotCurve::setData const QwtArray< double > &  xData,
const QwtArray< double > &  yData
 

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

Parameters:
xData x data
yData y data
See also:
QwtArrayData

Definition at line 373 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

void QwtPlotCurve::setData const double *  xData,
const double *  yData,
int  size
 

Set data by copying x- and y-values from specified memory blocks. Contrary to setCurveRawData(), 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:
QwtCPointerData

Definition at line 358 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

void QwtPlotCurve::setPaintAttribute PaintAttribute  attribute,
bool  on = true
 

Specify an attribute how to draw the curve.

The attributes can be used to modify the drawing algorithm.

The following attributes are defined:

PaintFiltered
Tries to reduce the data that has to be painted, by sorting out duplicates, or paintings outside the visible area. Might have a notable impact on curves with many close points. Only a couple of very basic filtering algos are implemented.
ClipPolygons
Clip polygons before painting them.

The default is, that no paint attributes are enabled.

Parameters:
attribute Paint attribute
on On/Off /sa testPaintAttribute()

Definition at line 211 of file qwt_plot_curve.cpp.

void QwtPlotCurve::setPen const QPen &  p  ) 
 

Assign a pen.

Parameters:
p New pen
See also:
pen(), brush()

Definition at line 298 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

void QwtPlotCurve::setRawData const double *  xData,
const double *  yData,
int  size
 

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

setRawData 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::setData.

Definition at line 424 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

void QwtPlotCurve::setStyle CurveStyle  style  ) 
 

Set the curve's drawing style.

Valid styles are:

NoCurve
Don't draw a curve. Note: This doesn't affect the symbol.
Lines
Connect the points with straight lines. The lines might be interpolated depending on the 'Fitted' option. Curve fitting can be configured using setCurveFitter.
Sticks
Draw vertical sticks 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 'Inverted' option.
Dots
Draw dots at the locations of the data points. Note: This is different from a dotted line (see setPen()).
UserCurve ...
Styles >= UserCurve are reserved for derived classes of QwtPlotCurve that overload drawCurve() with additional application specific curve types.
See also:
style()

Definition at line 255 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

void QwtPlotCurve::setSymbol const QwtSymbol s  ) 
 

Assign a symbol.

Parameters:
s symbol
See also:
symbol()

Definition at line 278 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

QwtPlotCurve::CurveStyle QwtPlotCurve::style  )  const
 

Return the current style.

See also:
setStyle

Definition at line 268 of file qwt_plot_curve.cpp.

Referenced by updateLegend().

const QwtSymbol & QwtPlotCurve::symbol  )  const
 

Return the current symbol.

See also:
setSymbol

Definition at line 288 of file qwt_plot_curve.cpp.

Referenced by drawSymbols(), and updateLegend().

bool QwtPlotCurve::testCurveAttribute CurveAttribute  attribute  )  const
 

Return the current curve attributes

See also:
setCurveAttribute()

Definition at line 993 of file qwt_plot_curve.cpp.

Referenced by drawCurve().

bool QwtPlotCurve::testPaintAttribute PaintAttribute  attribute  )  const
 

Return the current paint attributes.

See also:
setPaintAttribute

Definition at line 223 of file qwt_plot_curve.cpp.

void QwtPlotCurve::updateLegend QwtLegend legend  )  const [virtual]
 

Update the widget that represents the item on the legend.

updateLegend() is called from itemChanged() to adopt the widget representing the item on the legend to its new configuration.

The default implementation is made for QwtPlotCurve and updates a QwtLegendItem(), but an item could be represented by any type of widget, by overloading legendItem() and updateLegend().

See also:
legendItem(), itemChanged(), QwtLegend()

Reimplemented from QwtPlotItem.

Definition at line 1240 of file qwt_plot_curve.cpp.

References QwtLegend::displayPolicy(), QwtLegend::find(), QwtLegend::identifierMode(), QwtPlotItem::legendItem(), pen(), style(), symbol(), QwtPlotItem::title(), and QwtPlotItem::updateLegend().

double QwtPlotCurve::x int  i  )  const [inline]
 

Parameters:
i index
Returns:
x-value at position i

Definition at line 232 of file qwt_plot_curve.h.

References QwtData::x().

Referenced by closestPoint(), drawDots(), drawLines(), drawSteps(), drawSticks(), and drawSymbols().

double QwtPlotCurve::y int  i  )  const [inline]
 

Parameters:
i index
Returns:
y-value at position i

Definition at line 241 of file qwt_plot_curve.h.

References QwtData::y().

Referenced by closestPoint(), drawDots(), drawLines(), drawSteps(), drawSticks(), and drawSymbols().


Generated on Mon Feb 26 21:24:56 2007 for Qwt User's Guide by  doxygen 1.4.6