Classes | Public Types | Public Member Functions | Protected Member Functions

QwtPlotCurve Class Reference

A plot item, that represents a series of points. More...

#include <qwt_plot_curve.h>

Inheritance diagram for QwtPlotCurve:
Inheritance graph
[legend]
Collaboration diagram for QwtPlotCurve:
Collaboration graph
[legend]

List of all members.

Classes

class  PrivateData

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 ()
 Constructor.
 QwtPlotCurve (const QwtText &title)
 QwtPlotCurve (const QString &title)
virtual ~QwtPlotCurve ()
 Destructor.
virtual int rtti () const
void setCurveType (CurveType)
CurveType curveType () const
void setPaintAttribute (PaintAttribute, bool on=true)
bool testPaintAttribute (PaintAttribute) const
 Return the current paint attributes.
void setRawData (const double *x, const double *y, int size)
 Initialize the data by pointing to memory blocks which are not managed by QwtPlotCurve.
void setData (const double *xData, const double *yData, int size)
void setData (const QMemArray< double > &xData, const QMemArray< double > &yData)
void setData (const QMemArray< QwtDoublePoint > &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
 boundingRect().left()
double maxXValue () const
 boundingRect().right()
double minYValue () const
 boundingRect().top()
double maxYValue () const
 boundingRect().bottom()
void setCurveAttribute (CurveAttribute, bool on=true)
bool testCurveAttribute (CurveAttribute) const
void setPen (const QPen &)
const QPen & pen () const
 Return the pen used to draw the lines.
void setBrush (const QBrush &)
 Assign a brush.
const QBrush & brush () const
 Return the brush used to fill the area between lines and the baseline.
void setBaseline (double ref)
 Set the value of the baseline.
double baseline () const
void setStyle (CurveStyle style)
CurveStyle style () const
void setSymbol (const QwtSymbol &s)
 Assign a symbol.
const QwtSymbolsymbol () const
 Return the current symbol.
void setCurveFitter (QwtCurveFitter *)
QwtCurveFittercurveFitter () const
virtual void draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const
 Draw the complete curve.
virtual void draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
 Draw an interval of the curve.
void draw (int from, int to) const
 Draw a set of points of a curve.
virtual void updateLegend (QwtLegend *) const
 Update the widget that represents the curve on the legend.

Protected Member Functions

void init ()
 Initialize data members.
virtual void drawCurve (QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
 Draw the line part (without symbols) of a curve interval.
virtual void drawSymbols (QPainter *p, const QwtSymbol &, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
 Draw symbols.
void drawLines (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
 Draw lines.
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
 Complete a polygon to be a closed polygon including the area between the original polygon and the baseline.

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 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 QwtData object offering a bridge to the real storage of the points ( like QAbstractItemModel ). There are several convenience classes derived from QwtData, that also store the points inside ( like QStandardItemModel ). QwtPlotCurve also offers a couple of variations of setData(), that build QwtData objects from arrays internally.
c) Attach the curve to a plot
See QwtPlotItem::attach()
Example:
see examples/bode
See also:
QwtPlot, QwtData, QwtSymbol, QwtScaleMap

Definition at line 54 of file qwt_plot_curve.h.


Member Enumeration Documentation

Attribute for drawing the curve

  • Fitted ( in combination with the Lines QwtPlotCurve::CurveStyle 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.
See also:
setCurveAttribute(), testCurveAttribute(), curveFitter()
Enumerator:
Inverted 
Fitted 

Definition at line 134 of file qwt_plot_curve.h.

    {
        Inverted = 1,
        Fitted = 2
    };

Curve styles.

  • 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(Yfx) or horizontal(Xfy) 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' 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 NoStyle style and a symbol painting a point.
  • UserCurve
    Styles >= UserCurve are reserved for derived classes of QwtPlotCurve that overload drawCurve() with additional application specific curve types.
See also:
setStyle(), style()
Enumerator:
NoCurve 
Lines 
Sticks 
Steps 
Dots 
UserCurve 

Definition at line 106 of file qwt_plot_curve.h.

Curve type.

  • Yfx
    Draws y as a function of x (the default). The baseline is interpreted as a horizontal line with y = baseline().
  • 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:
setCurveType(), curveType(), baseline() brush()
Enumerator:
Yfx 
Xfy 

Definition at line 73 of file qwt_plot_curve.h.

    {
        Yfx,
        Xfy
    };

Attributes to modify the drawing algorithm.

  • 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. 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 ( especially on Windows ).

The default is, that no paint attributes are enabled.

See also:
setPaintAttribute(), testPaintAttribute()
Enumerator:
PaintFiltered 
ClipPolygons 

Definition at line 158 of file qwt_plot_curve.h.

    {
        PaintFiltered = 1,
        ClipPolygons = 2
    };

Constructor & Destructor Documentation

QwtPlotCurve::QwtPlotCurve (  ) [explicit]

Constructor.

Definition at line 225 of file qwt_plot_curve.cpp.

References init().

                          :
    QwtPlotItem(QwtText())
{
    init();
}
QwtPlotCurve::QwtPlotCurve ( const QwtText title ) [explicit]

Constructor

Parameters:
titleTitle of the curve

Definition at line 235 of file qwt_plot_curve.cpp.

References init().

                                              :
    QwtPlotItem(title)
{
    init();
}
QwtPlotCurve::QwtPlotCurve ( const QString &  title ) [explicit]

Constructor

Parameters:
titleTitle of the curve

Definition at line 245 of file qwt_plot_curve.cpp.

References init().

QwtPlotCurve::~QwtPlotCurve (  ) [virtual]

Destructor.

Definition at line 252 of file qwt_plot_curve.cpp.

{
    delete d_xy;
    delete d_data;
}

Member Function Documentation

double QwtPlotCurve::baseline (  ) const

Return the value of the baseline

See also:
setBaseline()

Definition at line 1231 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::reference.

{ 
    return d_data->reference; 
}
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 499 of file qwt_plot_curve.cpp.

References QwtData::boundingRect().

{
    if ( d_xy == NULL )
        return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid

    return d_xy->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 402 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::brush.

Referenced by setBrush().

{
    return d_data->brush;
}
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:
xMapX map
yMapY map
paPolygon to be completed

Definition at line 1123 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::curveType, QwtPlotCurve::PrivateData::reference, QwtScaleMap::transform(), and Xfy.

Referenced by fillCurve().

{
    const int sz = pa.size();
    if ( sz < 2 )
        return;

    pa.resize(sz + 2);

    if ( d_data->curveType == QwtPlotCurve::Xfy )
    {
        pa.setPoint(sz,
            xMap.transform(d_data->reference), pa.point(sz - 1).y());
        pa.setPoint(sz + 1,
            xMap.transform(d_data->reference), pa.point(0).y());
    }
    else
    {
        pa.setPoint(sz,
            pa.point(sz - 1).x(), yMap.transform(d_data->reference));
        pa.setPoint(pa.size() - 1,
            pa.point(0).x(), yMap.transform(d_data->reference));
    }
}
int QwtPlotCurve::closestPoint ( const QPoint &  pos,
double *  dist = NULL 
) const

Find the closest curve point for a specific position

Parameters:
posPosition, where to look for the closest curve point
distIf 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

Definition at line 1256 of file qwt_plot_curve.cpp.

References QwtPlot::canvasMap(), dataSize(), QwtPlotItem::plot(), qwtSqr(), QuadProgPP::sqrt(), x(), QwtPlotItem::xAxis(), QwtScaleMap::xTransform(), y(), and QwtPlotItem::yAxis().

{
    if ( plot() == NULL || dataSize() <= 0 )
        return -1;

    const QwtScaleMap xMap = plot()->canvasMap(xAxis());
    const QwtScaleMap yMap = plot()->canvasMap(yAxis());

    int index = -1;
    double dmin = 1.0e10;

    for (int i=0; i < dataSize(); i++)
    {
        const double cx = xMap.xTransform(x(i)) - pos.x();
        const double cy = yMap.xTransform(y(i)) - pos.y();

        const double f = qwtSqr(cx) + qwtSqr(cy);
        if (f < dmin)
        {
            index = i;
            dmin = f;
        }
    }
    if ( dist )
        *dist = sqrt(dmin);

    return index;
}
QwtCurveFitter * QwtPlotCurve::curveFitter (  ) const

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

Returns:
Curve fitter

Definition at line 1074 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::curveFitter.

Referenced by setCurveFitter().

{
    return d_data->curveFitter;
}
QwtPlotCurve::CurveType QwtPlotCurve::curveType (  ) const

Return the curve type

See also:
CurveType, setCurveType()

Definition at line 1051 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::curveType.

Referenced by setCurveType().

{
    return d_data->curveType;
}
QwtData & QwtPlotCurve::data (  ) [inline]
Returns:
the the curve data

Definition at line 280 of file qwt_plot_curve.h.

{
    return *d_xy;
}
const QwtData & QwtPlotCurve::data (  ) const [inline]
Returns:
the the curve data

Definition at line 286 of file qwt_plot_curve.h.

{
    return *d_xy;
}
int QwtPlotCurve::dataSize (  ) const

Return the size of the data arrays

See also:
setData()

Definition at line 1240 of file qwt_plot_curve.cpp.

References QwtData::size().

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

{
    return d_xy->size();
}
void QwtPlotCurve::draw ( QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
const QRect &   
) const [virtual]

Draw the complete curve.

Parameters:
painterPainter
xMapMaps x-values into pixel coordinates.
yMapMaps y-values into pixel coordinates.
See also:
drawCurve(), drawSymbols()

Implements QwtPlotItem.

Definition at line 516 of file qwt_plot_curve.cpp.

Referenced by draw().

{
    draw(painter, xMap, yMap, 0, -1);
}
void QwtPlotCurve::draw ( QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
int  from,
int  to 
) const [virtual]

Draw an interval of the curve.

Parameters:
painterPainter
xMapmaps x-values into pixel coordinates.
yMapmaps y-values into pixel coordinates.
fromindex of the first point to be painted
toindex 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 626 of file qwt_plot_curve.cpp.

References dataSize(), drawCurve(), drawSymbols(), QwtSymbol::NoSymbol, QwtPlotCurve::PrivateData::pen, QwtPainter::scaledPen(), QwtSymbol::style(), QwtPlotCurve::PrivateData::style, QwtPlotCurve::PrivateData::symbol, and verifyRange().

{
    if ( !painter || dataSize() <= 0 )
        return;

    if (to < 0)
        to = dataSize() - 1;

    if ( verifyRange(dataSize(), from, to) > 0 )
    {
        painter->save();
        painter->setPen(QwtPainter::scaledPen(d_data->pen));

        /*
          Qt 4.0.0 is slow when drawing lines, but it's even 
          slower when the painter has a brush. So we don't
          set the brush before we really need it.
         */

        drawCurve(painter, d_data->style, xMap, yMap, from, to);
        painter->restore();

        if (d_data->symbol->style() != QwtSymbol::NoSymbol)
        {
            painter->save();
            drawSymbols(painter, *d_data->symbol, xMap, yMap, from, to);
            painter->restore();
        }
    }
}
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:
fromIndex of the first point to be painted
toIndex 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 540 of file qwt_plot_curve.cpp.

References QwtGuardedPainter::begin(), QwtPlot::canvas(), QwtPlot::canvasMap(), draw(), QwtPlotCurve::PrivateData::guardedPainter, QwtPlotCanvas::paintCache(), QwtPlotCanvas::PaintCached, QwtPlotItem::plot(), QwtPlotCanvas::testPaintAttribute(), QwtPlotItem::xAxis(), and QwtPlotItem::yAxis().

{
    if ( !plot() )
        return;

    QwtPlotCanvas *canvas = plot()->canvas();

#if QT_VERSION >= 0x040000
#if 0
    if ( canvas->paintEngine()->type() == QPaintEngine::OpenGL )
    {
        /*
            OpenGL alway repaint the complete widget.
            So for this operation OpenGL is one of the slowest
            environments.
         */
        canvas->repaint();
        return;
    }
#endif

    if ( !canvas->testAttribute(Qt::WA_WState_InPaintEvent) &&
        !canvas->testAttribute(Qt::WA_PaintOutsidePaintEvent) )
    {
        /*
          We save curve and range in helper and call repaint.
          The helper filters the Paint event, to repeat
          the QwtPlotCurve::draw, but now from inside the paint
          event.
         */

        QwtPlotCurvePaintHelper helper(this, from, to);
        canvas->installEventFilter(&helper);

        const bool noSystemBackground =
            canvas->testAttribute(Qt::WA_NoSystemBackground);
        canvas->setAttribute(Qt::WA_NoSystemBackground, true);
        canvas->repaint();
        canvas->setAttribute(Qt::WA_NoSystemBackground, noSystemBackground);

        return;
    }
#endif

    const QwtScaleMap xMap = plot()->canvasMap(xAxis());
    const QwtScaleMap yMap = plot()->canvasMap(yAxis());

    if ( canvas->testPaintAttribute(QwtPlotCanvas::PaintCached) &&
        canvas->paintCache() && !canvas->paintCache()->isNull() )
    {
        QPainter cachePainter((QPixmap *)canvas->paintCache());
        cachePainter.translate(-canvas->contentsRect().x(),
            -canvas->contentsRect().y());

        draw(&cachePainter, xMap, yMap, from, to);
    }

#if QT_VERSION >= 0x040000
    if ( canvas->testAttribute(Qt::WA_WState_InPaintEvent) )
    {
        QPainter painter(canvas);

        painter.setClipping(true);
        painter.setClipRect(canvas->contentsRect());

        draw(&painter, xMap, yMap, from, to);
    }
    else
#endif
    {
        QPainter *painter = d_data->guardedPainter.begin(canvas);
        draw(painter, xMap, yMap, from, to);
    }
}
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:
painterPainter
stylecurve style, see QwtPlotCurve::CurveStyle
xMapx map
yMapy map
fromindex of the first point to be painted
toindex of the last point to be painted
See also:
draw(), drawDots(), drawLines(), drawSteps(), drawSticks()

Definition at line 670 of file qwt_plot_curve.cpp.

References dataSize(), Dots, drawDots(), drawLines(), drawSteps(), drawSticks(), Fitted, Lines, NoCurve, Steps, Sticks, and testCurveAttribute().

Referenced by draw().

{
    switch (style)
    {
        case Lines:
            if ( testCurveAttribute(Fitted) )
            {
                // we always need the complete 
                // curve for fitting
                from = 0;
                to = dataSize() - 1;
            }
            drawLines(painter, xMap, yMap, from, to);
            break;
        case Sticks:
            drawSticks(painter, xMap, yMap, from, to);
            break;
        case Steps:
            drawSteps(painter, xMap, yMap, from, to);
            break;
        case Dots:
            drawDots(painter, xMap, yMap, from, to);
            break;
        case NoCurve:
        default:
            break;
    }
}
void QwtPlotCurve::drawDots ( QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
int  from,
int  to 
) const [protected]

Draw dots

Parameters:
painterPainter
xMapx map
yMapy map
fromindex of the first point to be painted
toindex of the last point to be painted
See also:
draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()

Definition at line 872 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::brush, QwtClipper::clipPolygon(), ClipPolygons, QwtPainter::drawPoint(), fillCurve(), QwtPlotCurve::PrivateData::paintAttributes, PaintFiltered, QwtPlotCurve::PrivateData::PixelMatrix::testPixel(), QwtScaleMap::transform(), x(), and y().

Referenced by drawCurve().

{
    const QRect window = painter->window();
    if ( window.isEmpty() )
        return;

    const bool doFill = d_data->brush.style() != Qt::NoBrush;

    QwtPolygon polyline;
    if ( doFill )
        polyline.resize(to - from + 1);

    if ( to > from && d_data->paintAttributes & PaintFiltered )
    {
        if ( doFill )   
        {
            QPoint pp( xMap.transform(x(from)), yMap.transform(y(from)) );

            QwtPainter::drawPoint(painter, pp.x(), pp.y());
            polyline.setPoint(0, pp);

            int count = 1;
            for (int i = from + 1; i <= to; i++)
            {
                const QPoint pi(xMap.transform(x(i)), yMap.transform(y(i)));
                if ( pi != pp )
                {
                    QwtPainter::drawPoint(painter, pi.x(), pi.y());

                    polyline.setPoint(count, pi);
                    count++;

                    pp = pi;
                }
            }
            if ( int(polyline.size()) != count )
                polyline.resize(count);
        }
        else
        {
            // if we don't need to fill, we can sort out
            // duplicates independent from the order

            PrivateData::PixelMatrix pixelMatrix(window);

            for (int i = from; i <= to; i++)
            {
                const QPoint p( xMap.transform(x(i)),
                    yMap.transform(y(i)) );

                if ( pixelMatrix.testPixel(p) )
                    QwtPainter::drawPoint(painter, p.x(), p.y());
            }
        }
    }
    else
    {
        for (int i = from; i <= to; i++)
        {
            const int xi = xMap.transform(x(i));
            const int yi = yMap.transform(y(i));
            QwtPainter::drawPoint(painter, xi, yi);

            if ( doFill )
                polyline.setPoint(i - from, xi, yi);
        }
    }

    if ( doFill )
    {
        if ( d_data->paintAttributes & ClipPolygons )
            polyline = QwtClipper::clipPolygon(painter->window(), polyline);

        fillCurve(painter, xMap, yMap, polyline);
    }
}
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:
painterPainter
xMapx map
yMapy map
fromindex of the first point to be painted
toindex of the last point to be painted
See also:
setCurveAttribute(), setCurveFitter(), draw(), drawLines(), drawDots(), drawSteps(), drawSticks()

Definition at line 716 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::attributes, QwtPlotCurve::PrivateData::brush, QwtClipper::clipPolygon(), ClipPolygons, QwtPlotCurve::PrivateData::curveFitter, QwtPainter::drawPolyline(), fillCurve(), QwtCurveFitter::fitCurve(), Fitted, QwtPlotCurve::PrivateData::paintAttributes, PaintFiltered, QwtDoublePoint::setX(), QwtDoublePoint::setY(), QwtScaleMap::transform(), x(), QwtScaleMap::xTransform(), and y().

Referenced by drawCurve().

{
    int size = to - from + 1;
    if ( size <= 0 )
        return;

    QwtPolygon polyline;
    if ( ( d_data->attributes & Fitted ) && d_data->curveFitter )
    {
        // Transform x and y values to window coordinates
        // to avoid a distinction between linear and
        // logarithmic scales.

#if QT_VERSION < 0x040000
        QwtArray<QwtDoublePoint> points(size);
#else
        QPolygonF points(size);
#endif
        for (int i = from; i <= to; i++)
        {
            QwtDoublePoint &p = points[i];
            p.setX( xMap.xTransform(x(i)) );
            p.setY( yMap.xTransform(y(i)) );
        }

        points = d_data->curveFitter->fitCurve(points);
        size = points.size();

        if ( size == 0 )
            return;

        // Round QwtDoublePoints to QPoints
        // When Qwt support for Qt3 has been dropped (Qwt 6.x)
        // we will use a doubles for painting and the following
        // step will be obsolete.

        polyline.resize(size);

        const QwtDoublePoint *p = points.data();
        QPoint *pl = polyline.data();
        if ( d_data->paintAttributes & PaintFiltered )
        {

            QPoint pp(qRound(p[0].x()), qRound(p[0].y()));
            pl[0] = pp;

            int count = 1;
            for (int i = 1; i < size; i++)
            {
                const QPoint pi(qRound(p[i].x()), qRound(p[i].y()));
                if ( pi != pp )
                {
                    pl[count++] = pi;
                    pp = pi;
                }
            }
            if ( count != size )
                polyline.resize(count);
        }
        else
        {
            for ( int i = 0; i < size; i++ )
            {
                pl[i].setX( qRound(p[i].x()) );
                pl[i].setY( qRound(p[i].y()) );
            }
        }
    }
    else
    {
        polyline.resize(size);

        if ( d_data->paintAttributes & PaintFiltered )
        {
            QPoint pp( xMap.transform(x(from)), yMap.transform(y(from)) );
            polyline.setPoint(0, pp);

            int count = 1;
            for (int i = from + 1; i <= to; i++)
            {
                const QPoint pi(xMap.transform(x(i)), yMap.transform(y(i)));
                if ( pi != pp )
                {
                    polyline.setPoint(count, pi);
                    count++;

                    pp = pi;
                }
            }
            if ( count != size )
                polyline.resize(count);
        }
        else
        {
            for (int i = from; i <= to; i++)
            {
                int xi = xMap.transform(x(i));
                int yi = yMap.transform(y(i));

                polyline.setPoint(i - from, xi, yi);
            }
        }
    }

    if ( d_data->paintAttributes & ClipPolygons )
        polyline = QwtClipper::clipPolygon(painter->window(), polyline);

    QwtPainter::drawPolyline(painter, polyline);

    if ( d_data->brush.style() != Qt::NoBrush )
        fillCurve(painter, xMap, yMap, polyline);
}
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:
painterPainter
xMapx map
yMapy map
fromindex of the first point to be painted
toindex of the last point to be painted
See also:
CurveAttribute, setCurveAttribute(), draw(), drawCurve(), drawDots(), drawLines(), drawSticks()

Definition at line 965 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::attributes, QwtPlotCurve::PrivateData::brush, QwtClipper::clipPolygon(), ClipPolygons, QwtPlotCurve::PrivateData::curveType, QwtPainter::drawPolyline(), fillCurve(), Inverted, QwtPlotCurve::PrivateData::paintAttributes, QwtScaleMap::transform(), x(), y(), and Yfx.

Referenced by drawCurve().

{
    QwtPolygon polyline(2 * (to - from) + 1);

    bool inverted = d_data->curveType == Yfx;
    if ( d_data->attributes & Inverted )
        inverted = !inverted;

    int i,ip;
    for (i = from, ip = 0; i <= to; i++, ip += 2)
    {
        const int xi = xMap.transform(x(i));
        const int yi = yMap.transform(y(i));

        if ( ip > 0 )
        {
            if (inverted)
                polyline.setPoint(ip - 1, polyline[ip-2].x(), yi);
            else
                polyline.setPoint(ip - 1, xi, polyline[ip-2].y());
        }

        polyline.setPoint(ip, xi, yi);
    }

    if ( d_data->paintAttributes & ClipPolygons )
        polyline = QwtClipper::clipPolygon(painter->window(), polyline);

    QwtPainter::drawPolyline(painter, polyline);

    if ( d_data->brush.style() != Qt::NoBrush )
        fillCurve(painter, xMap, yMap, polyline);
}
void QwtPlotCurve::drawSticks ( QPainter *  painter,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
int  from,
int  to 
) const [protected]

Draw sticks

Parameters:
painterPainter
xMapx map
yMapy map
fromindex of the first point to be painted
toindex of the last point to be painted
See also:
draw(), drawCurve(), drawDots(), drawLines(), drawSteps()

Definition at line 842 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::curveType, QwtPainter::drawLine(), QwtPlotCurve::PrivateData::reference, QwtScaleMap::transform(), x(), Xfy, and y().

Referenced by drawCurve().

{
    int x0 = xMap.transform(d_data->reference);
    int y0 = yMap.transform(d_data->reference);

    for (int i = from; i <= to; i++)
    {
        const int xi = xMap.transform(x(i));
        const int yi = yMap.transform(y(i));

        if (d_data->curveType == Xfy)
            QwtPainter::drawLine(painter, x0, yi, xi, yi);
        else
            QwtPainter::drawLine(painter, xi, y0, xi, yi);
    }
}
void QwtPlotCurve::drawSymbols ( QPainter *  painter,
const QwtSymbol symbol,
const QwtScaleMap xMap,
const QwtScaleMap yMap,
int  from,
int  to 
) const [protected, virtual]

Draw symbols.

Parameters:
painterPainter
symbolCurve symbol
xMapx map
yMapy map
fromindex of the first point to be painted
toindex of the last point to be painted
See also:
setSymbol(), draw(), drawCurve()

Definition at line 1160 of file qwt_plot_curve.cpp.

References QwtSymbol::brush(), QwtSymbol::draw(), QwtPainter::metricsMap(), QwtPlotCurve::PrivateData::paintAttributes, PaintFiltered, QwtSymbol::pen(), QwtPainter::scaledPen(), QwtMetricsMap::screenToLayout(), QwtSymbol::size(), QwtPlotCurve::PrivateData::PixelMatrix::testPixel(), QwtScaleMap::transform(), x(), and y().

Referenced by draw().

{
    painter->setBrush(symbol.brush());
    painter->setPen(QwtPainter::scaledPen(symbol.pen()));

    const QwtMetricsMap &metricsMap = QwtPainter::metricsMap();

    QRect rect;
    rect.setSize(metricsMap.screenToLayout(symbol.size()));

    if ( to > from && d_data->paintAttributes & PaintFiltered )
    {
        const QRect window = painter->window();
        if ( window.isEmpty() )
            return;

        PrivateData::PixelMatrix pixelMatrix(window);

        for (int i = from; i <= to; i++)
        {
            const QPoint pi( xMap.transform(x(i)),
                yMap.transform(y(i)) );

            if ( pixelMatrix.testPixel(pi) )
            {
                rect.moveCenter(pi);
                symbol.draw(painter, rect);
            }
        }
    }
    else
    {
        for (int i = from; i <= to; i++)
        {
            const int xi = xMap.transform(x(i));
            const int yi = yMap.transform(y(i));

            rect.moveCenter(QPoint(xi, yi));
            symbol.draw(painter, rect);
        }
    }
}
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:
painterPainter
xMapx map
yMapy map
paPolygon
See also:
setBrush(), setBaseline(), setCurveType()

Definition at line 1090 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::brush, closePolyline(), QwtPainter::drawPolygon(), and QwtPlotCurve::PrivateData::pen.

Referenced by drawDots(), drawLines(), and drawSteps().

{
    if ( d_data->brush.style() == Qt::NoBrush )
        return;

    closePolyline(xMap, yMap, pa);
    if ( pa.count() <= 2 ) // a line can't be filled
        return;

    QBrush b = d_data->brush;
    if ( !b.color().isValid() )
        b.setColor(d_data->pen.color());

    painter->save();

    painter->setPen(QPen(Qt::NoPen));
    painter->setBrush(b);

    QwtPainter::drawPolygon(painter, pa);

    painter->restore();
}
void QwtPlotCurve::init (  ) [protected]

Initialize data members.

Definition at line 261 of file qwt_plot_curve.cpp.

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

Referenced by QwtPlotCurve().

{
    setItemAttribute(QwtPlotItem::Legend);
    setItemAttribute(QwtPlotItem::AutoScale);

    d_data = new PrivateData;
    d_xy = new QwtPolygonFData(QwtArray<QwtDoublePoint>());

    setZ(20.0);
}
double QwtPlotCurve::maxXValue (  ) const [inline]

boundingRect().right()

Definition at line 202 of file qwt_plot_curve.h.

References QwtPlotItem::boundingRect(), and QwtDoubleRect::right().

{ return boundingRect().right(); }
double QwtPlotCurve::maxYValue (  ) const [inline]

boundingRect().bottom()

Definition at line 206 of file qwt_plot_curve.h.

References QwtDoubleRect::bottom(), and QwtPlotItem::boundingRect().

{ return boundingRect().bottom(); }
double QwtPlotCurve::minXValue (  ) const [inline]

boundingRect().left()

Definition at line 200 of file qwt_plot_curve.h.

References QwtPlotItem::boundingRect(), and QwtDoubleRect::left().

{ return boundingRect().left(); }
double QwtPlotCurve::minYValue (  ) const [inline]

boundingRect().top()

Definition at line 204 of file qwt_plot_curve.h.

References QwtPlotItem::boundingRect(), and QwtDoubleRect::top().

{ return boundingRect().top(); }
const QPen & QwtPlotCurve::pen (  ) const

Return the pen used to draw the lines.

See also:
setPen(), brush()

Definition at line 369 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::pen.

Referenced by QwtPlotPrintFilter::apply(), QwtPlotPrintFilter::reset(), setPen(), and updateLegend().

{ 
    return d_data->pen; 
}
int QwtPlotCurve::rtti (  ) const [virtual]
Returns:
QwtPlotItem::Rtti_PlotCurve

Reimplemented from QwtPlotItem.

Definition at line 273 of file qwt_plot_curve.cpp.

References QwtPlotItem::Rtti_PlotCurve.

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:
referencebaseline
See also:
baseline(), setBrush(), setStyle(), setCurveType()

Definition at line 1218 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged(), and QwtPlotCurve::PrivateData::reference.

{
    if ( d_data->reference != reference )
    {
        d_data->reference = reference;
        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:
brushNew brush
See also:
brush(), setBaseline(), baseline()

Definition at line 389 of file qwt_plot_curve.cpp.

References brush(), QwtPlotCurve::PrivateData::brush, and QwtPlotItem::itemChanged().

{
    if ( brush != d_data->brush )
    {
        d_data->brush = brush;
        itemChanged();
    }
}
void QwtPlotCurve::setCurveAttribute ( CurveAttribute  attribute,
bool  on = true 
)

Specify an attribute for drawing the curve

Parameters:
attributeCurve attribute
onOn/Off

/sa CurveAttribute, testCurveAttribute(), setCurveFitter()

Definition at line 1010 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::attributes, and QwtPlotItem::itemChanged().

{
    if ( bool(d_data->attributes & attribute) == on )
        return;

    if ( on )
        d_data->attributes |= attribute;
    else
        d_data->attributes &= ~attribute;

    itemChanged();
}
void QwtPlotCurve::setCurveFitter ( QwtCurveFitter curveFitter )

Assign a curve fitter setCurveFitter(NULL) disables curve fitting.

Parameters:
curveFitterCurve fitter

Definition at line 1062 of file qwt_plot_curve.cpp.

References curveFitter(), QwtPlotCurve::PrivateData::curveFitter, and QwtPlotItem::itemChanged().

{
    delete d_data->curveFitter;
    d_data->curveFitter = curveFitter;

    itemChanged();
}
void QwtPlotCurve::setCurveType ( CurveType  curveType )

Assign the curve type

Parameters:
curveTypeYfx or Xfy
See also:
CurveType, curveType()

Definition at line 1038 of file qwt_plot_curve.cpp.

References curveType(), QwtPlotCurve::PrivateData::curveType, and QwtPlotItem::itemChanged().

{
    if ( d_data->curveType != curveType )
    {
        d_data->curveType = curveType;
        itemChanged();
    }
}
void QwtPlotCurve::setData ( const QMemArray< QwtDoublePoint > &  data )

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

Parameters:
dataData
Note:
Internally the data is stored in a QwtPolygonFData object

Definition at line 450 of file qwt_plot_curve.cpp.

{
    delete d_xy;
    d_xy = new QwtPolygonFData(data);
    itemChanged();
}
void QwtPlotCurve::setData ( const QMemArray< double > &  xData,
const QMemArray< double > &  yData 
)

Initialize data with x- and y-arrays (explicitly shared) ( Builds an QwtArrayData object internally )

Parameters:
xDatax data
yDatay data
Note:
Internally the data is stored in a QwtArrayData object

Definition at line 435 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

{
    delete d_xy;
    d_xy = new QwtArrayData(xData, yData);
    itemChanged();
}
void QwtPlotCurve::setData ( const QwtData data )

Initialize data with a pointer to QwtData.

Parameters:
dataData
See also:
QwtData::copy()

Definition at line 466 of file qwt_plot_curve.cpp.

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

{
    delete d_xy;
    d_xy = data.copy();
    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:
xDataPointer to x values
yDataPointer to y values
sizeSize of xData and yData
Note:
Internally the data is stored in a QwtArrayData object

Definition at line 419 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

{
    delete d_xy;
    d_xy = new QwtArrayData(xData, yData, size);
    itemChanged();
}
void QwtPlotCurve::setPaintAttribute ( PaintAttribute  attribute,
bool  on = true 
)

Specify an attribute how to draw the curve

Parameters:
attributePaint attribute
onOn/Off /sa PaintAttribute, testPaintAttribute()

Definition at line 285 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::paintAttributes.

{
    if ( on )
        d_data->paintAttributes |= attribute;
    else
        d_data->paintAttributes &= ~attribute;
}
void QwtPlotCurve::setPen ( const QPen &  pen )

Assign a pen

The width of non cosmetic pens is scaled according to the resolution of the paint device.

Parameters:
penNew pen
See also:
pen(), brush(), QwtPainter::scaledPen()

Definition at line 356 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged(), pen(), and QwtPlotCurve::PrivateData::pen.

Referenced by QwtPlotPrintFilter::apply(), and QwtPlotPrintFilter::reset().

{
    if ( pen != d_data->pen )
    {
        d_data->pen = pen;
        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:
xDatapointer to x data
yDatapointer to y data
sizesize of x and y
Note:
Internally the data is stored in a QwtCPointerData object

Definition at line 486 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged().

{
    delete d_xy;
    d_xy = new QwtCPointerData(xData, yData, size);
    itemChanged();
}
void QwtPlotCurve::setStyle ( CurveStyle  style )

Set the curve's drawing style

Parameters:
styleCurve style
See also:
CurveStyle, style()

Definition at line 308 of file qwt_plot_curve.cpp.

References QwtPlotItem::itemChanged(), style(), and QwtPlotCurve::PrivateData::style.

{
    if ( style != d_data->style )
    {
        d_data->style = style;
        itemChanged();
    }
}
void QwtPlotCurve::setSymbol ( const QwtSymbol symbol )

Assign a symbol.

Parameters:
symbolSymbol
See also:
symbol()

Definition at line 331 of file qwt_plot_curve.cpp.

References QwtSymbol::clone(), QwtPlotItem::itemChanged(), and QwtPlotCurve::PrivateData::symbol.

Referenced by QwtPlotPrintFilter::apply(), and QwtPlotPrintFilter::reset().

{
    delete d_data->symbol;
    d_data->symbol = symbol.clone();
    itemChanged();
}
QwtPlotCurve::CurveStyle QwtPlotCurve::style (  ) const

Return the current style

See also:
CurveStyle, setStyle()

Definition at line 321 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::style.

Referenced by setStyle(), and updateLegend().

{ 
    return d_data->style; 
}
const QwtSymbol & QwtPlotCurve::symbol (  ) const

Return the current symbol.

See also:
setSymbol()

Definition at line 342 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::symbol.

Referenced by QwtPlotPrintFilter::apply(), QwtPlotPrintFilter::reset(), and updateLegend().

{ 
    return *d_data->symbol; 
}
bool QwtPlotCurve::testCurveAttribute ( CurveAttribute  attribute ) const
Returns:
true, if attribute is enabled
See also:
CurveAttribute, setCurveAttribute()

Definition at line 1027 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::attributes.

Referenced by drawCurve().

{ 
    return d_data->attributes & attribute;
}
bool QwtPlotCurve::testPaintAttribute ( PaintAttribute  attribute ) const

Return the current paint attributes.

See also:
PaintAttribute, setPaintAttribute()

Definition at line 297 of file qwt_plot_curve.cpp.

References QwtPlotCurve::PrivateData::paintAttributes.

{
    return (d_data->paintAttributes & attribute);
}
void QwtPlotCurve::updateLegend ( QwtLegend legend ) const [virtual]

Update the widget that represents the curve on the legend.

Reimplemented from QwtPlotItem.

Definition at line 1286 of file qwt_plot_curve.cpp.

References QwtLegend::AutoIdentifier, QwtLegend::displayPolicy(), QwtLegend::find(), QwtLegend::FixedIdentifier, QwtLegend::identifierMode(), QwtPlotItem::legendItem(), NoCurve, QwtSymbol::NoSymbol, pen(), QwtLegendItem::setCurvePen(), QwtLegendItem::setIdentifierMode(), QwtLegendItem::setSymbol(), QwtLegendItem::setText(), QwtLegendItem::ShowLine, QwtLegendItem::ShowSymbol, QwtLegendItem::ShowText, style(), symbol(), and QwtPlotItem::title().

{
    if ( !legend )
        return;

    QwtPlotItem::updateLegend(legend);

    QWidget *widget = legend->find(this);
    if ( !widget || !widget->inherits("QwtLegendItem") )
        return;

    QwtLegendItem *legendItem = (QwtLegendItem *)widget;

#if QT_VERSION < 0x040000
    const bool doUpdate = legendItem->isUpdatesEnabled();
#else
    const bool doUpdate = legendItem->updatesEnabled();
#endif
    legendItem->setUpdatesEnabled(false);

    const int policy = legend->displayPolicy();

    if (policy == QwtLegend::FixedIdentifier)
    {
        int mode = legend->identifierMode();

        if (mode & QwtLegendItem::ShowLine)
            legendItem->setCurvePen(pen());

        if (mode & QwtLegendItem::ShowSymbol)
            legendItem->setSymbol(symbol());

        if (mode & QwtLegendItem::ShowText)
            legendItem->setText(title());
        else
            legendItem->setText(QwtText());

        legendItem->setIdentifierMode(mode);
    }
    else if (policy == QwtLegend::AutoIdentifier)
    {
        int mode = 0;

        if (QwtPlotCurve::NoCurve != style())
        {
            legendItem->setCurvePen(pen());
            mode |= QwtLegendItem::ShowLine;
        }
        if (QwtSymbol::NoSymbol != symbol().style())
        {
            legendItem->setSymbol(symbol());
            mode |= QwtLegendItem::ShowSymbol;
        }
        if ( !title().isEmpty() )
        {
            legendItem->setText(title());
            mode |= QwtLegendItem::ShowText;
        }
        else
        {
            legendItem->setText(QwtText());
        }
        legendItem->setIdentifierMode(mode);
    }

    legendItem->setUpdatesEnabled(doUpdate);
    legendItem->update();
}
double QwtPlotCurve::x ( int  i ) const [inline]
Parameters:
iindex
Returns:
x-value at position i

Definition at line 295 of file qwt_plot_curve.h.

References QwtData::x().

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

{ 
    return d_xy->x(i); 
}
double QwtPlotCurve::y ( int  i ) const [inline]
Parameters:
iindex
Returns:
y-value at position i

Definition at line 304 of file qwt_plot_curve.h.

References QwtData::y().

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

{ 
    return d_xy->y(i); 
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines