Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

# QwtCurve Class Reference

Inheritance diagram for QwtCurve:

[legend]
Collaboration diagram for QwtCurve:

[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 QwtCurve::Lines and no symbols. You can change this by calling QwtCurve::setPen(), QwtCurve::setStyle() and QwtCurve::setSymbol().
  B. Assign or change data.
    Data can be set in two ways:
    - QwtCurve::setData() is overloaded to initialize the x and y data by copying from different data structures with different kind of copy semantics.
    - QwtCurve::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 QwtCurve::setData() in combination with a problem-specific subclass of QwtData is always preferrable.
  C. Draw
    QwtCurve::draw() maps the data into pixel coordinates and paints them.

Example:
  see examples/curvdemo

See also:
  QwtData, QwtSymbol, QwtDiMap

Definition at line 60 of file qwt_curve.h.

## Public Types
enum | CurveStyle { NoCurve, Lines, Sticks, Steps, Dots, Spline, UserCurve = 100 }
enum | CurveOption { Auto = 0, Yfx = 1, Xfy = 2, Parametric = 4, Periodic = 8, Inverted = 16 }
## Public Member Functions
| QwtCurve (const QString &title=QString::null)
| QwtCurve (const QwtCurve &c)
virtual | ~QwtCurve ()
const QwtCurve & | operator= (const QwtCurve &c)
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 QwtArray< QwtDoublePoint > &data)
void | setData (const QwtData &data)
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 | setOptions (int t)
int | options () const
void | setTitle (const QString &title)
const QString & | title () 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 (int style, int options=0)
int | style () const
void | setSymbol (const QwtSymbol &s)
const QwtSymbol & | symbol () const
void | setSplineSize (int s)
int | splineSize () const
virtual void | draw (QPainter *p, const QwtDiMap &xMap, const QwtDiMap &yMap, int from=0, int to=-1)
## Protected Member Functions
void | init (const QString &title)
void | copy (const QwtCurve &c)
virtual void | drawCurve (QPainter *p, int style, const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
virtual void | drawSymbols (QPainter *p, QwtSymbol &, const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
void | drawLines (QPainter *p, const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
void | drawSticks (QPainter *p, const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
void | drawDots (QPainter *p, const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
void | drawSteps (QPainter *p, const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
void | drawSpline (QPainter *p, const QwtDiMap &xMap, const QwtDiMap &yMap)
void | closePolyline (const QwtDiMap &, const QwtDiMap &, QPointArray &) const
virtual void | curveChanged ()
int | verifyRange (int &i1, int &i2)
## Protected Attributes
QwtSpline | d_spx
QwtSpline | d_spy

## Member Enumeration Documentation

enum QwtCurve::CurveOption

| Curve options. See also: QwtCurve::setOptions Definition at line 82 of file qwt_curve.h.

enum QwtCurve::CurveStyle

| Curve styles. See also: QwtCurve::setStyle Definition at line 67 of file qwt_curve.h.

## Constructor & Destructor Documentation

QwtCurve::QwtCurve | ( | const QString & | title = `QString::null` | ) |

  | Ctor. Parameters:
  | title | title of the curve
Definition at line 321 of file qwt_curve.cpp. References init().

QwtCurve::QwtCurve | ( | const QwtCurve & | c | ) |

| Copy Constructor. Definition at line 60 of file qwt_curve.cpp. References copy(), d_title, and init().

QwtCurve::~QwtCurve | ( |  | ) | `[virtual]`

| Dtor. Definition at line 52 of file qwt_curve.cpp.

## Member Function Documentation

double QwtCurve::baseline | ( |  | ) | const

| Return the value of the baseline. See also: QwtCurve::setBaseline Definition at line 907 of file qwt_curve.cpp. Referenced by QwtPlot::curveBaseline().

QwtDoubleRect QwtCurve::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: QwtDoubleRect.isValid() == FALSE Definition at line 309 of file qwt_curve.cpp. References QwtData::boundingRect(). Referenced by QwtPlot::updateAxes().

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

| Return the brush used to fill the area between lines and the baseline. See also: QwtCurve::setBrush, QwtCurve::setBaseline, QwtCurve::baseline Definition at line 196 of file qwt_curve.cpp. Referenced by QwtPlot::curveBrush().

void QwtCurve::closePolyline | ( | const QwtDiMap & | xMap,
|  | const QwtDiMap & | yMap,
|  | QPointArray & | 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 831 of file qwt_curve.cpp. References QwtDiMap::transform(). Referenced by drawDots(), drawLines(), drawSpline(), and drawSteps().

void QwtCurve::copy | ( | const QwtCurve & | c | ) | `[protected]`

| Copy the contents of a curve into another curve. Definition at line 36 of file qwt_curve.cpp. References QwtData::copy(), d_data, d_options, d_pen, d_ref, d_splineSize, d_style, d_sym, and d_title. Referenced by operator=(), and QwtCurve().

void QwtCurve::curveChanged | ( |  | ) | `[protected, virtual]`

| Notify a change of attributes. This virtual function is called when an attribute of the curve has changed. It can be redefined by derived classes. The default implementation does nothing. Reimplemented in QwtPlotCurve. Definition at line 927 of file qwt_curve.cpp. Referenced by operator=(), setBaseline(), setBrush(), setData(), setOptions(), setPen(), setRawData(), setSplineSize(), setStyle(), setSymbol(), and setTitle().

int QwtCurve::dataSize | ( |  | ) | const

| Return the size of the data arrays Definition at line 915 of file qwt_curve.cpp. References QwtData::size(). Referenced by QwtPlot::closestCurve(), draw(), drawCurve(), drawSpline(), and verifyRange().

void QwtCurve::draw | ( | QPainter * | painter,
|  | const QwtDiMap & | xMap,
|  | const QwtDiMap & | yMap,
|  | int | from = `0`,
|  | int | to = `-1`
| ) | `[virtual]`

  | Draw an intervall 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: QwtCurve::drawCurve, QwtCurve::drawDots, QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSteps, QwtCurve::drawSticks Definition at line 357 of file qwt_curve.cpp. References dataSize(), drawCurve(), drawSymbols(), QwtSymbol::style(), and verifyRange(). Referenced by QwtPlot::drawCanvasItems(), and QwtPlot::drawCurve().

void QwtCurve::drawCurve | ( | QPainter * | painter,
|  | int | style,
|  | const QwtDiMap & | xMap,
|  | const QwtDiMap & | yMap,
|  | int | from,
|  | int | to
| ) | `[protected, virtual]`

  | Draw the line part (without symbols) of a curve interval. Parameters:
  | painter | Painter
  | style | curve style, see QwtCurve::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: QwtCurve::draw, QwtCurve::drawDots, QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSteps, QwtCurve::drawSticks Definition at line 401 of file qwt_curve.cpp. References dataSize(), drawDots(), drawLines(), drawSpline(), drawSteps(), and drawSticks(). Referenced by draw().

void QwtCurve::drawDots | ( | QPainter * | painter,
|  | const QwtDiMap & | xMap,
|  | const QwtDiMap & | yMap,
|  | int | from,
|  | int | to
| ) | `[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: QwtCurve::drawPolyline, QwtCurve::drawLine, QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSteps QwtCurve::drawPolyline, QwtCurve::drawPolygon Definition at line 502 of file qwt_curve.cpp. References closePolyline(), QwtPainter::drawPoint(), QwtPainter::drawPolygon(), QwtDiMap::transform(), x(), and y(). Referenced by drawCurve().

void QwtCurve::drawLines | ( | QPainter * | painter,
|  | const QwtDiMap & | xMap,
|  | const QwtDiMap & | yMap,
|  | int | from,
|  | int | to
| ) | `[protected]`

  | Draw lines. 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: QwtCurve::draw, QwtCurve::drawLines, QwtCurve::drawDots, QwtCurve::drawSpline, QwtCurve::drawSteps, QwtCurve::drawSticks Definition at line 441 of file qwt_curve.cpp. References closePolyline(), QwtPainter::drawPolygon(), QwtPainter::drawPolyline(), QwtDiMap::transform(), x(), and y(). Referenced by drawCurve(), and drawSpline().

void QwtCurve::drawSpline | ( | QPainter * | painter,
|  | const QwtDiMap & | xMap,
|  | const QwtDiMap & | yMap
| ) | `[protected]`

  | Draw a spline. Parameters:
  | painter | Painter
  | xMap | x map
  | yMap | y map
See also: QwtCurve::draw, QwtCurve::drawCurve, QwtCurve::drawDots, QwtCurve::drawLines, QwtCurve::drawSteps, QwtCurve::drawSticks Definition at line 583 of file qwt_curve.cpp. References closePolyline(), dataSize(), drawLines(), QwtPainter::drawPolygon(), QwtPainter::drawPolyline(), qwtSqr(), QwtSpline::recalc(), QwtSpline::value(), x(), QwtDiMap::xTransform(), and y(). Referenced by drawCurve().

void QwtCurve::drawSteps | ( | QPainter * | painter,
|  | const QwtDiMap & | xMap,
|  | const QwtDiMap & | yMap,
|  | int | from,
|  | int | to
| ) | `[protected]`

  | Draw step function. 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: QwtCurve::draw, QwtCurve::drawCurve, QwtCurve::drawDots, QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSticks Definition at line 539 of file qwt_curve.cpp. References closePolyline(), QwtPainter::drawPolygon(), QwtPainter::drawPolyline(), QwtDiMap::transform(), x(), and y(). Referenced by drawCurve().

void QwtCurve::drawSticks | ( | QPainter * | painter,
|  | const QwtDiMap & | xMap,
|  | const QwtDiMap & | yMap,
|  | int | from,
|  | int | to
| ) | `[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: QwtCurve::draw, QwtCurve::drawCurve, QwtCurve::drawDots, QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSteps Definition at line 473 of file qwt_curve.cpp. References QwtPainter::drawLine(), QwtDiMap::transform(), x(), and y(). Referenced by drawCurve().

void QwtCurve::drawSymbols | ( | QPainter * | painter,
|  | QwtSymbol & | symbol,
|  | const QwtDiMap & | xMap,
|  | const QwtDiMap & | yMap,
|  | int | from,
|  | int | to
| ) | `[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
Definition at line 865 of file qwt_curve.cpp. References QwtSymbol::brush(), QwtSymbol::draw(), QwtSymbol::pen(), QwtSymbol::size(), QwtDiMap::transform(), x(), and y(). Referenced by draw().

void QwtCurve::init | ( | const QString & | title | ) | `[protected]`

| Initialize data members. Definition at line 22 of file qwt_curve.cpp. Referenced by QwtCurve().

double QwtCurve::maxXValue | ( |  | ) | const

| boundingRect().x2() Definition at line 113 of file qwt_curve.h.

double QwtCurve::maxYValue | ( |  | ) | const

| boundingRect().y2() Definition at line 117 of file qwt_curve.h.

double QwtCurve::minXValue | ( |  | ) | const

| boundingRect().x1() Definition at line 111 of file qwt_curve.h.

double QwtCurve::minYValue | ( |  | ) | const

| boundingRect().y1() Definition at line 115 of file qwt_curve.h.

const QwtCurve & QwtCurve::operator= | ( | const QwtCurve & | c | ) |

| Copy Assignment. Definition at line 69 of file qwt_curve.cpp. References copy(), and curveChanged(). Referenced by QwtPlotCurve::operator=().

int QwtCurve::options | ( |  | ) | const

| Return the current style options. See also: QwtCurve::setOptions Definition at line 795 of file qwt_curve.cpp. Referenced by QwtPlot::curveOptions().

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

| Return the pen used to draw the lines. See also: QwtCurve::setPen Definition at line 165 of file qwt_curve.cpp. Referenced by QwtPlotPrintFilter::apply(), QwtPlot::curvePen(), QwtPlotPrintFilter::reset(), and QwtPlot::updateLegendItem().

void QwtCurve::setBaseline | ( | double | ref | ) |

  | Set the value of the baseline. The baseline is needed for filling the curve with a brush or the QwtCurve::Sticks drawing style. The default value is 0.0. The interpretation of the baseline depends on the style options. With QwtCurve::Yfx, the baseline is interpreted as a horizontal line at y = baseline(), with QwtCurve::Yfy, it is interpreted as a vertical line at x = baseline(). Parameters:
  | ref | baseline
See also: QwtCurve::setBrush(), QwtCurve::setStyle(), QwtCurve::setOptions() Definition at line 897 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlot::setCurveBaseline().

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

  | Assign a brush. In case of brush.style() != QBrush::NoBrush and style() != QwtCurve::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: QwtCurve::brush, QwtCurve::setBaseline, QwtCurve::baseline Definition at line 182 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlot::setCurveBrush().

void QwtCurve::setData | ( | const QwtData & | data | ) |

  | Initialize data with a pointer to QwtData. Parameters:
  | data | Data
See also: QwtData::copy. Definition at line 257 of file qwt_curve.cpp. References QwtData::copy(), and curveChanged().

void QwtCurve::setData | ( | const QwtArray< QwtDoublePoint > & | data | ) |

  | Initialize data with an array of points (explicitly shared). Parameters:
  | data | Data
See also: QwtDoublePointData::setData. Definition at line 243 of file qwt_curve.cpp. References curveChanged().

void QwtCurve::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: QwtData::setData. Definition at line 228 of file qwt_curve.cpp. References curveChanged().

void QwtCurve::setData | ( | const double * | xData,
|  | const double * | yData,
|  | int | size
| ) |

  | Set data by copying x- and y-values from specified memory blocks Contrary to QwtPlot::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: QwData::setData. Definition at line 213 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlot::setCurveData().

void QwtCurve::setOptions | ( | int | opt | ) |

  | Specify options for the drawing style. The options can be used to modify the drawing style. Options can be or-combined. The following options are defined: QwtCurve::Auto The default setting. For QwtCurve::spline, this means that the type of the spline is determined automatically, depending on the data. For all other styles, this means that y is regarded as a function of x. QwtCurve::Yfx Draws y as a function of x (the default). The baseline is interpreted as a horizontal line with y = baseline(). QwtCurve::Xfy Draws x as a function of y. The baseline is interpreted as a vertical line with x = baseline(). QwtCurve::Parametric For QwtCurve::Spline only. Draws a parametric spline. QwtCurve::Periodic For QwtCurve::Spline only. Draws a periodic spline. QwtCurve::Inverted For QwtCurve::Steps only. Draws a step function from the right to the left. Parameters:
  | opt | new options /sa QwtCurve::options()
Definition at line 785 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlot::setCurveOptions().

void QwtCurve::setPen | ( | const QPen & | p | ) |

  | Assign a pen. Parameters:
  | p | New pen
Definition at line 152 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlotPrintFilter::apply(), QwtPlotPrintFilter::reset(), and QwtPlot::setCurvePen().

void QwtCurve::setRawData | ( | const double * | xData,
|  | const double * | yData,
|  | int | size
| ) |

  | Initialize the data by pointing to memory blocks which are not managed by QwtCurve. 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 277 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlot::setCurveRawData().

void QwtCurve::setSplineSize | ( | int | s | ) |

  | Change the number of interpolated points. Parameters:
  | s | new size
Warning: The default is 250 points. Definition at line 805 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlot::setCurveSplineSize().

void QwtCurve::setStyle | ( | int | style,
|  | int | options = `0`
| ) |

| Set the curve's drawing style. Valid styles are: QwtCurve::NoCurve Don't draw a curve. Note: This doesn't affect the symbol. QwtCurve::Lines Connect the points with straight lines. QwtCurve::Sticks Draw vertical sticks from a baseline which is defined by setBaseline(). QwtCurve::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. QwtCurves::Dots Draw dots at the locations of the data points. Note: This is different from a dotted line (see setPen()). QwtCurve::Spline Interpolate the points with a spline. The spline type can be specified with setOptions(), the size of the spline (= number of interpolated points) can be specified with setSplineSize(). QwtCurve::UserCurve ... Styles >= QwtCurve::UserCurve are reserved for derived classes of QwtCurve that overload QwtCurve::draw() with additional application specific curve types. See also: QwtCurve::style() Definition at line 110 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlot::setCurveStyle().

void QwtCurve::setSymbol | ( | const QwtSymbol & | s | ) |

  | Assign a symbol. Parameters:
  | s | symbol
See also: QwtSymbol Definition at line 132 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlotPrintFilter::apply(), QwtPlotPrintFilter::reset(), and QwtPlot::setCurveSymbol().

void QwtCurve::setTitle | ( | const QString & | title | ) |

  | Assign a title to a curve. Parameters:
  | title | new title
Definition at line 288 of file qwt_curve.cpp. References curveChanged(). Referenced by QwtPlot::insertCurve(), and QwtPlot::setCurveTitle().

int QwtCurve::splineSize | ( |  | ) | const

| Return the spline size. See also: QwtCurve::setSplineSize Definition at line 817 of file qwt_curve.cpp. Referenced by QwtPlot::curveSplineSize().

int QwtCurve::style | ( |  | ) | const

| Return the current style. See also: QwtCurve::setStyle Definition at line 122 of file qwt_curve.cpp. Referenced by QwtPlot::curveStyle(), and QwtPlot::updateLegendItem().

const QwtSymbol & QwtCurve::symbol | ( |  | ) | const

| Return the current symbol. See also: QwtCurve::setSymbol Definition at line 142 of file qwt_curve.cpp. Referenced by QwtPlotPrintFilter::apply(), QwtPlot::curveSymbol(), QwtPlotPrintFilter::reset(), and QwtPlot::updateLegendItem().

const QString & QwtCurve::title | ( |  | ) | const

| Return the title. See also: QwtCurve::setTitle Definition at line 298 of file qwt_curve.cpp. Referenced by QwtPlot::curveTitle(), and QwtPlot::updateLegendItem().

int QwtCurve::verifyRange | ( | int & | i1,
|  | int & | i2
| ) | `[protected]`

  | Checks if a range of indices is valid and corrects it if necessary. Parameters:
  | i1 | Index 1
  | i2 | Index 2
Definition at line 331 of file qwt_curve.cpp. References dataSize(), qwtLim(), and qwtSort(). Referenced by draw().

double QwtCurve::x | ( | int | i | ) | const

  | Parameters:
  | i | index
Returns: x-value at position i Definition at line 205 of file qwt_curve.h. Referenced by QwtPlot::closestCurve(), drawDots(), drawLines(), drawSpline(), drawSteps(), drawSticks(), and drawSymbols().

double QwtCurve::y | ( | int | i | ) | const

  | Parameters:
  | i | index
Returns: y-value at position i Definition at line 214 of file qwt_curve.h. References QwtData::y(). Referenced by QwtPlot::closestCurve(), drawDots(), drawLines(), drawSpline(), drawSteps(), drawSticks(), and drawSymbols().