22 #include <qalgorithms.h> 27 QRectF clipRect = rect;
28 if ( painter->hasClipping() )
30 #if QT_VERSION >= 0x040800 31 const QRectF r = painter->clipBoundingRect();
33 const QRectF r = painter->clipRegion().boundingRect();
53 int w = qCeil( 1.5 * sz.width() );
57 sz.setWidth( qMax( 8, w ) );
69 i1 = qBound( 0, i1, size - 1 );
70 i2 = qBound( 0, i2, size - 1 );
75 return ( i2 - i1 + 1 );
287 setPen( QPen( color, width, style ) );
366 const QRectF &canvasRect,
int from,
int to )
const 368 const size_t numSamples =
dataSize();
370 if ( !painter || numSamples <= 0 )
395 xMap, yMap, canvasRect, from, to );
414 const QRectF &canvasRect,
int from,
int to )
const 426 drawLines( painter, xMap, yMap, canvasRect, from, to );
429 drawSticks( painter, xMap, yMap, canvasRect, from, to );
432 drawSteps( painter, xMap, yMap, canvasRect, from, to );
435 drawDots( painter, xMap, yMap, canvasRect, from, to );
444 drawLines( painter, xMap, yMap, canvasRect, from, to );
446 QPen prev_pen = painter->pen();
447 QPen new_pen = prev_pen;
448 new_pen.setWidth( prev_pen.width() * 3);
450 painter->setPen( new_pen );
451 drawDots( painter, xMap, yMap, canvasRect, from, to );
452 painter->setPen( prev_pen );
479 const QRectF &canvasRect,
int from,
int to )
const 486 const bool doFill = (
d_data->
brush.style() != Qt::NoBrush )
494 const qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
495 clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
498 bool doIntegers =
false;
500 #if QT_VERSION < 0x040800 501 if ( painter->paintEngine()->type() == QPaintEngine::Raster )
512 if ( !doFit && !doFill )
535 xMap, yMap,
data(), from, to );
546 QPolygonF polyline = mapper.
toPolygonF( xMap, yMap,
data(), from, to );
559 if ( painter->pen().style() != Qt::NoPen )
564 QPolygonF filled = polyline;
565 fillCurve( painter, xMap, yMap, canvasRect, filled );
575 fillCurve( painter, xMap, yMap, canvasRect, polyline );
589 const QPainterPath curvePath =
592 painter->drawPath( curvePath );
622 const QRectF &,
int from,
int to )
const 625 painter->setRenderHint( QPainter::Antialiasing,
false );
641 for (
int i = from;
i <= to;
i++ )
644 double xi = xMap.
transform( sample.x() );
645 double yi = yMap.
transform( sample.y() );
652 if ( o == Qt::Horizontal )
675 const QRectF &canvasRect,
int from,
int to )
const 677 const QColor color = painter->pen().color();
679 if ( painter->pen().style() == Qt::NoPen || color.alpha() == 0 )
684 const bool doFill = (
d_data->
brush.style() != Qt::NoBrush )
694 if ( ( color.alpha() == 255 )
695 && !( painter->renderHints() & QPainter::Antialiasing ) )
706 xMap, yMap,
data(), from, to );
709 fillCurve( painter, xMap, yMap, canvasRect, points );
713 const QImage image = mapper.
toImage( xMap, yMap,
715 painter->testRenderHint( QPainter::Antialiasing ),
718 painter->drawImage( canvasRect.toAlignedRect(), image );
724 for (
int i = from;
i <= to;
i++ )
728 double xi = xMap.
transform( sample.x() );
729 double yi = yMap.
transform( sample.y() );
744 const QPolygon points = mapper.
toPoints(
745 xMap, yMap,
data(), from, to );
751 const QPolygonF points = mapper.
toPointsF(
752 xMap, yMap,
data(), from, to );
776 const QRectF &canvasRect,
int from,
int to )
const 780 QPolygonF polygon( 2 * ( to - from ) + 1 );
781 QPointF *points = polygon.data();
785 inverted = !inverted;
790 for ( i = from, ip = 0; i <= to; i++, ip += 2 )
793 double xi = xMap.
transform( sample.x() );
794 double yi = yMap.
transform( sample.y() );
803 const QPointF &p0 = points[ip - 2];
804 QPointF &p = points[ip - 1];
818 points[ip].rx() = xi;
819 points[ip].ry() = yi;
826 const qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
827 clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
830 clipRect, polygon,
false );
840 fillCurve( painter, xMap, yMap, canvasRect, polygon );
924 const QRectF &canvasRect, QPolygonF &polygon )
const 930 if ( polygon.count() <= 2 )
934 if ( !brush.color().isValid() )
945 painter->setPen( Qt::NoPen );
946 painter->setBrush( brush );
964 QPolygonF &polygon )
const 966 if ( polygon.size() < 2 )
978 double refY = yMap.
transform( baseline );
980 refY = qRound( refY );
982 polygon += QPointF( polygon.last().x(), refY );
983 polygon += QPointF( polygon.first().x(), refY );
990 double refX = xMap.
transform( baseline );
992 refX = qRound( refX );
994 polygon += QPointF( refX, polygon.last().y() );
995 polygon += QPointF( refX, polygon.first().y() );
1014 const QRectF &canvasRect,
int from,
int to )
const 1025 const int chunkSize = 500;
1027 for (
int i = from;
i <= to;
i += chunkSize )
1029 const int n = qMin( chunkSize, to -
i + 1 );
1031 const QPolygonF points = mapper.
toPointsF( xMap, yMap,
1034 if ( points.size() > 0 )
1086 const size_t numSamples =
dataSize();
1088 if (
plot() == NULL || numSamples <= 0 )
1097 double dmin = 1.0e10;
1099 for ( uint
i = 0;
i < numSamples;
i++ )
1103 const double cx = xMap.
transform( sample.x() ) - pos.x();
1104 const double cy = yMap.
transform( sample.y() ) - pos.y();
1114 *dist = qSqrt( dmin );
1129 const QSizeF &size )
const 1133 if ( size.isEmpty() )
1140 QPainter painter( &graphic );
1141 painter.setRenderHint( QPainter::Antialiasing,
1149 if ( brush.style() == Qt::NoBrush &&
1154 brush = QBrush(
pen().color() );
1163 if ( brush.style() != Qt::NoBrush )
1165 QRectF r( 0, 0, size.width(), size.height() );
1166 painter.fillRect( r, brush );
1172 if (
pen() != Qt::NoPen )
1175 pn.setCapStyle( Qt::FlatCap );
1177 painter.setPen( pn );
1179 const double y = 0.5 * size.height();
1188 QRectF r( 0, 0, size.width(), size.height() );
1223 #ifndef QWT_NO_COMPAT 1240 const double *xData,
const double *yData,
int size )
1257 const double *xData,
const double *yData,
int size )
1271 const QVector<double> &yData )
1276 #endif // !QWT_NO_COMPAT virtual void legendChanged()
virtual size_t dataSize() const
Qt::Orientation orientation() const
virtual QRect boundingRect() const
QwtPlotCurve::CurveAttributes attributes
void setRawSamples(const double *xData, const double *yData, int size)
Initialize the data by pointing to memory blocks which are not managed by QwtPlotCurve.
void setStyle(CurveStyle style)
static void drawLine(QPainter *, double x1, double y1, double x2, double y2)
Wrapper for QPainter::drawLine()
QPolygonF toPointsF(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtSeriesData< QPointF > *series, int from, int to) const
Translate a series into a QPolygonF.
A plot item, that represents a series of points.
void setBoundingRect(const QRectF &)
QwtPlotCurve(const QString &title=QString())
static int qwtVerifyRange(int size, int &i1, int &i2)
static void drawPoints(QPainter *, const QPolygon &)
Wrapper for QPainter::drawPoints()
virtual void drawLines(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Draw lines.
const QBrush & brush() const
virtual QwtGraphic legendIcon(int index, const QSizeF &) const
int xAxis() const
Return xAxis.
QwtPlotCurve::PaintAttributes paintAttributes
virtual void drawSticks(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
void setData(QwtSeriesData< QPointF > *series)
virtual void fillCurve(QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRectF &canvasRect, QPolygonF &) const
QFlags< CurveAttribute > CurveAttributes
Curve attributes.
A curve fitter using a spline interpolation.
void setPaintAttribute(PaintAttribute, bool on=true)
QwtSeriesData< QPointF > * data()
A class for drawing symbols.
QPolygon toPolygon(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtSeriesData< QPointF > *series, int from, int to) const
Translate a series of points into a QPolygon.
QwtPlot * plot() const
Return attached plot.
TFSIMD_FORCE_INLINE const tfScalar & y() const
QwtCurveFitter * curveFitter
static QPolygonF clippedPolygonF(const QRectF &, const QPolygonF &, bool closePolygon=false)
QwtPlotCurve::LegendAttributes legendAttributes
void setSamples(const double *xData, const double *yData, int size)
void setBaseline(double)
Set the value of the baseline.
void closePolyline(QPainter *, const QwtScaleMap &, const QwtScaleMap &, QPolygonF &) const
Complete a polygon to be a closed polygon including the area between the original polygon and the bas...
void setRenderHint(RenderHint, bool on=true)
void setSymbol(QwtSymbol *)
Assign a symbol.
void setDefaultSize(const QSizeF &)
Set a default size.
The item is represented on the legend.
void setFlag(TransformationFlag, bool on=true)
void init()
Initialize internal members.
virtual int closestPoint(const QPoint &pos, double *dist=NULL) const
QPolygon toPoints(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtSeriesData< QPointF > *series, int from, int to) const
Translate a series of points into a QPolygon.
const QwtSymbol * symbol() const
static void drawPolygon(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolygon()
virtual void drawDots(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
void setCurveFitter(QwtCurveFitter *)
bool testRenderHint(RenderHint) const
Data class containing two pointers to memory blocks of doubles.
virtual void drawCurve(QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Draw the line part (without symbols) of a curve interval.
static void clipPolygonF(const QRectF &, QPolygonF &, bool closePolygon=false)
virtual QPainterPath fitCurvePath(const QPolygonF &polygon) const =0
Round points to integer values.
A class representing a text.
virtual QwtScaleMap canvasMap(int axisId) const
void setZ(double z)
Set the z value.
A paint device for scalable graphics.
int yAxis() const
Return yAxis.
void drawSymbols(QPainter *, const QPolygonF &) const
Draw symbols at the specified points.
virtual void drawSteps(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
const QwtTransform * transformation() const
Get the transformation.
QPointF sample(int index) const
virtual void itemChanged()
virtual void drawSymbols(QPainter *p, const QwtSymbol &, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
uint renderThreadCount() const
TFSIMD_FORCE_INLINE const tfScalar & w() const
static void drawPolyline(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolyline()
QPolygonF toPolygonF(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtSeriesData< QPointF > *series, int from, int to) const
Translate a series of points into a QPolygonF.
QwtPlotCurve::CurveStyle style
QFlags< LegendAttribute > LegendAttributes
Legend attributes.
QFlags< PaintAttribute > PaintAttributes
Paint attributes.
bool testLegendAttribute(LegendAttribute) const
virtual QPolygonF fitCurve(const QPolygonF &polygon) const =0
bool testCurveAttribute(CurveAttribute) const
void setBrush(const QBrush &)
Assign a brush.
virtual T sample(size_t i) const =0
static void qwtUpdateLegendIconSize(QwtPlotCurve *curve)
Base class for plot items representing a series of samples.
void setLegendAttribute(LegendAttribute, bool on=true)
QImage toImage(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtSeriesData< QPointF > *series, int from, int to, const QPen &, bool antialiased, uint numThreads) const
Translate a series into a QImage.
void setItemAttribute(ItemAttribute, bool on=true)
void setLegendIconSize(const QSize &)
double qwtSqr(double x)
Return the square of a number.
double transform(double s) const
static QRectF qwtIntersectedClipRect(const QRectF &rect, QPainter *painter)
QwtCurveFitter * curveFitter() const
Interface for iterating over two QVector<double> objects.
void drawSymbol(QPainter *, const QRectF &) const
Draw the symbol into a rectangle.
static void drawPoint(QPainter *, const QPoint &)
Wrapper for QPainter::drawPoint()
Interface for iterating over an array of points.
Abstract base class for a curve fitter.
bool testPaintAttribute(PaintAttribute) const
static bool roundingAlignment()
static void clipPolygon(const QRect &, QPolygon &, bool closePolygon=false)
virtual ~QwtPlotCurve()
Destructor.
A helper class for translating a series of points.
const QwtText & title() const
No Style. The symbol cannot be drawn.
void setCurveAttribute(CurveAttribute, bool on=true)