A plot item, that represents a series of points. More...
#include <qwt_plot_curve.h>
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 |
QwtData & | data () |
const QwtData & | data () 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 QwtSymbol & | symbol () const |
Return the current symbol. | |
void | setCurveFitter (QwtCurveFitter *) |
QwtCurveFitter * | curveFitter () 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. |
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.
Definition at line 54 of file qwt_plot_curve.h.
Attribute for drawing the curve
Definition at line 134 of file qwt_plot_curve.h.
Curve styles.
Definition at line 106 of file qwt_plot_curve.h.
Curve type.
The baseline is used for aligning the sticks, or filling the curve with a brush.
Definition at line 73 of file qwt_plot_curve.h.
Attributes to modify the drawing algorithm.
The default is, that no paint attributes are enabled.
Definition at line 158 of file qwt_plot_curve.h.
{ PaintFiltered = 1, ClipPolygons = 2 };
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
title | Title 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
title | Title of the curve |
Definition at line 245 of file qwt_plot_curve.cpp.
References init().
: QwtPlotItem(QwtText(title)) { init(); }
QwtPlotCurve::~QwtPlotCurve | ( | ) | [virtual] |
double QwtPlotCurve::baseline | ( | ) | const |
Return the value of the baseline
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.
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.
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.
xMap | X map |
yMap | Y map |
pa | Polygon 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
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 |
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.
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
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] |
const QwtData & QwtPlotCurve::data | ( | ) | const [inline] |
int QwtPlotCurve::dataSize | ( | ) | const |
Return the size of the data arrays
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.
painter | Painter |
xMap | Maps x-values into pixel coordinates. |
yMap | Maps y-values into pixel coordinates. |
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.
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. |
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.
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. |
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.
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 |
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
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 |
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.
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 |
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.
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 |
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
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 |
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.
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 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
painter | Painter |
xMap | x map |
yMap | y map |
pa | Polygon |
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.
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] |
Reimplemented from QwtPlotItem.
Definition at line 273 of file qwt_plot_curve.cpp.
References QwtPlotItem::Rtti_PlotCurve.
{ return 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().
reference | baseline |
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).
brush | New brush |
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
attribute | Curve attribute |
on | On/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.
curveFitter | Curve 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
curveType | Yfx or Xfy |
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).
data | Data |
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 )
xData | x data |
yData | y data |
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.
data | Data |
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.
xData | Pointer to x values |
yData | Pointer to y values |
size | Size of xData and yData |
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
attribute | Paint attribute |
on | On/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.
pen | New pen |
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.
xData | pointer to x data |
yData | pointer to y data |
size | size of x and y |
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
style | Curve 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.
symbol | 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
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.
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 |
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.
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] |
i | index |
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] |
i | index |
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); }