24 #include <qpainterpath.h> 28 QRectF clipRect = rect;
29 if ( painter->hasClipping() )
30 clipRect &= painter->clipBoundingRect();
47 int w =
qwtCeil( 1.5 * sz.width() );
51 sz.setWidth( qMax( 8, w ) );
63 i1 = qBound( 0, i1, size - 1 );
64 i2 = qBound( 0, i2, size - 1 );
69 return ( i2 - i1 + 1 );
304 setPen( QPen( color, width, style ) );
383 const QRectF& canvasRect,
int from,
int to )
const 385 const size_t numSamples =
dataSize();
387 if ( !painter || numSamples <= 0 )
412 xMap, yMap, canvasRect, from, to );
431 const QRectF& canvasRect,
int from,
int to )
const 443 drawLines( painter, xMap, yMap, canvasRect, from, to );
446 drawSticks( painter, xMap, yMap, canvasRect, from, to );
449 drawSteps( painter, xMap, yMap, canvasRect, from, to );
452 drawDots( painter, xMap, yMap, canvasRect, from, to );
459 drawLines(painter, xMap, yMap, canvasRect, from, to);
461 QPen prev_pen = painter->pen();
462 QPen new_pen = prev_pen;
463 new_pen.setWidth(prev_pen.width() * 3);
465 painter->setPen(new_pen);
466 drawDots(painter, xMap, yMap, canvasRect, from, to);
467 painter->setPen(prev_pen);
494 const QRectF& canvasRect,
int from,
int to )
const 501 const bool doFill = (
m_data->
brush.style() != Qt::NoBrush )
510 clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
528 QPolygonF polyline = mapper.
toPolygonF( xMap, yMap,
data(), from, to );
541 if ( painter->pen().style() != Qt::NoPen )
546 QPolygonF filled = polyline;
547 fillCurve( painter, xMap, yMap, canvasRect, filled );
557 fillCurve( painter, xMap, yMap, canvasRect, polyline );
571 const QPainterPath curvePath =
574 painter->drawPath( curvePath );
603 const QRectF& canvasRect,
int from,
int to )
const 605 Q_UNUSED( canvasRect )
608 painter->setRenderHint( QPainter::Antialiasing,
false );
624 for (
int i = from; i <= to; i++ )
627 double xi = xMap.
transform( sample.x() );
628 double yi = yMap.
transform( sample.y() );
635 if ( o == Qt::Horizontal )
658 const QRectF& canvasRect,
int from,
int to )
const 660 const QColor
color = painter->pen().color();
662 if ( painter->pen().style() == Qt::NoPen || color.alpha() == 0 )
667 const bool doFill = (
m_data->
brush.style() != Qt::NoBrush )
677 if ( ( color.alpha() == 255 )
678 && !( painter->renderHints() & QPainter::Antialiasing ) )
689 xMap, yMap,
data(), from, to );
692 fillCurve( painter, xMap, yMap, canvasRect, points );
696 const QImage image = mapper.
toImage( xMap, yMap,
698 painter->testRenderHint( QPainter::Antialiasing ),
701 painter->drawImage( canvasRect.toAlignedRect(), image );
707 for (
int i = from; i <= to; i++ )
711 double xi = xMap.
transform( sample.x() );
712 double yi = yMap.
transform( sample.y() );
727 const QPolygon points = mapper.
toPoints(
728 xMap, yMap,
data(), from, to );
734 const QPolygonF points = mapper.
toPointsF(
735 xMap, yMap,
data(), from, to );
759 const QRectF& canvasRect,
int from,
int to )
const 763 QPolygonF polygon( 2 * ( to - from ) + 1 );
764 QPointF* points = polygon.data();
768 inverted = !inverted;
773 for ( i = from, ip = 0; i <= to; i++, ip += 2 )
776 double xi = xMap.
transform( sample.x() );
777 double yi = yMap.
transform( sample.y() );
786 const QPointF& p0 = points[ip - 2];
787 QPointF& p = points[ip - 1];
801 points[
ip].rx() = xi;
802 points[
ip].ry() = yi;
810 clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
813 clipRect, polygon,
false );
823 fillCurve( painter, xMap, yMap, canvasRect, polygon );
907 const QRectF& canvasRect, QPolygonF& polygon )
const 913 if ( polygon.count() <= 2 )
917 if ( !brush.color().isValid() )
928 painter->setPen( Qt::NoPen );
929 painter->setBrush( brush );
947 QPolygonF& polygon )
const 949 if ( polygon.size() < 2 )
961 double refY = yMap.
transform( baseline );
963 refY = qRound( refY );
965 polygon += QPointF( polygon.last().x(), refY );
966 polygon += QPointF( polygon.first().x(), refY );
973 double refX = xMap.
transform( baseline );
975 refX = qRound( refX );
977 polygon += QPointF( refX, polygon.last().y() );
978 polygon += QPointF( refX, polygon.first().y() );
997 const QRectF& canvasRect,
int from,
int to )
const 1008 const int chunkSize = 500;
1010 for (
int i = from; i <= to; i += chunkSize )
1012 const int n = qMin( chunkSize, to - i + 1 );
1014 const QPolygonF points = mapper.
toPointsF( xMap, yMap,
1015 data(), i, i + n - 1 );
1017 if ( points.size() > 0 )
1069 const size_t numSamples =
dataSize();
1071 if (
plot() == NULL || numSamples <= 0 )
1080 double dmin = 1.0e10;
1082 for ( uint i = 0; i < numSamples; i++ )
1086 const double cx = xMap.
transform( sample.x() ) - pos.x();
1087 const double cy = yMap.
transform( sample.y() ) - pos.y();
1097 *dist = std::sqrt( dmin );
1115 if ( size.isEmpty() )
1122 QPainter painter( &graphic );
1123 painter.setRenderHint( QPainter::Antialiasing,
1131 if ( brush.style() == Qt::NoBrush &&
1145 if ( brush.style() != Qt::NoBrush )
1147 QRectF r( 0, 0, size.width(), size.height() );
1148 painter.fillRect( r, brush );
1154 if (
pen() != Qt::NoPen )
1157 pn.setCapStyle( Qt::FlatCap );
1159 painter.setPen( pn );
1161 const double y = 0.5 * size.height();
1170 QRectF r( 0, 0, size.width(), size.height() );
1220 const double* xData,
const double* yData,
int size )
1240 const float* xData,
const float* yData,
int size )
1299 const double* xData,
const double* yData,
int size )
1316 const float* xData,
const float* yData,
int size )
virtual void legendChanged()
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.
uint renderThreadCount() const
void setStyle(CurveStyle style)
A plot item, that represents a series of points.
void setBoundingRect(const QRectF &)
const QwtText & title() const
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
QwtPlotCurve(const QString &title=QString())
static int qwtVerifyRange(int size, int &i1, int &i2)
static void drawPoints(QPainter *, const QPolygon &)
Wrapper for QPainter::drawPoints()
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...
QwtPlotCurve::PaintAttributes paintAttributes
Interface for iterating over a QVector<T>.
void setData(QwtSeriesData< QPointF > *series)
QPointF sample(int index) const
virtual void drawDots(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
bool testCurveAttribute(CurveAttribute) const
A curve fitter using a spline interpolation.
virtual int rtti() const QWT_OVERRIDE
Qt::Orientation orientation() const
void setPaintAttribute(PaintAttribute, bool on=true)
QwtSeriesData< QPointF > * data()
double transform(double s) const
A class for drawing symbols.
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.
QwtCurveFitter * curveFitter
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::LegendAttributes legendAttributes
void setSamples(const double *xData, const double *yData, int size)
void setBaseline(double)
Set the value of the baseline.
void setRenderHint(RenderHint, bool on=true)
static qreal effectivePenWidth(const QPen &)
void setSymbol(QwtSymbol *)
Assign a symbol.
void setDefaultSize(const QSizeF &)
Set a default size.
const QwtTransform * transformation() const
Get the transformation.
The item is represented on the legend.
void setFlag(TransformationFlag, bool on=true)
QwtAxisId xAxis() const
Return xAxis.
void init()
Initialize internal members.
QwtPlot * plot() const
Return attached plot.
const QBrush & brush() const
static void drawPolygon(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolygon()
virtual QwtGraphic legendIcon(int index, const QSizeF &) const QWT_OVERRIDE
void setCurveFitter(QwtCurveFitter *)
virtual int closestPoint(const QPoint &pos, double *dist=NULL) const
Data class containing two pointers to memory blocks of T.
virtual void drawSteps(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
LegendAttributes legendAttributes() const
virtual QPainterPath fitCurvePath(const QPolygonF &polygon) const =0
Round points to integer values.
void setLegendAttributes(LegendAttributes)
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.
A class representing a text.
void setZ(double z)
Set the z value.
Data class containing a pointer to memory of y coordinates.
A paint device for scalable graphics.
void drawSymbols(QPainter *, const QPolygonF &) const
Draw symbols at the specified points.
virtual QRect boundingRect() const
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
virtual void itemChanged()
const QwtSymbol * symbol() const
bool testLegendAttribute(LegendAttribute) const
virtual void drawCurve(QPainter *, 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 drawPolyline(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolyline()
virtual void drawLines(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Draw lines.
bool testRenderHint(RenderHint) const
QwtPlotCurve::CurveStyle style
virtual QPolygonF fitCurve(const QPolygonF &polygon) const =0
QWT_EXPORT void clipPolygonF(const QRectF &, QPolygonF &, bool closePolygon=false)
void setBrush(const QBrush &)
Assign a brush.
virtual T sample(size_t i) const =0
static void qwtUpdateLegendIconSize(QwtPlotCurve *curve)
virtual QwtScaleMap canvasMap(QwtAxisId) const
span_constexpr std::size_t size(span< T, Extent > const &spn)
virtual size_t dataSize() const QWT_OVERRIDE
Base class for plot items representing a series of samples.
void drawSymbol(QPainter *, const QRectF &) const
Draw the symbol into a rectangle.
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const QWT_OVERRIDE
void setLegendAttribute(LegendAttribute, bool on=true)
void setItemAttribute(ItemAttribute, bool on=true)
void setLegendIconSize(const QSize &)
double qwtSqr(double x)
Return the square of a number.
virtual void drawSticks(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
virtual void drawSymbols(QPainter *, const QwtSymbol &, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
static QRectF qwtIntersectedClipRect(const QRectF &rect, QPainter *painter)
QwtCurveFitter * curveFitter() const
QWT_EXPORT QPolygonF clippedPolygonF(const QRectF &, const QPolygonF &, bool closePolygon=false)
QPolygonF toPointsF(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtSeriesData< QPointF > *series, int from, int to) const
Translate a series into a QPolygonF.
QwtAxisId yAxis() const
Return yAxis.
Interface for iterating over two QVector<T> objects.
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()
virtual ~QwtPlotCurve()
Destructor.
virtual void fillCurve(QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRectF &canvasRect, QPolygonF &) const
A helper class for translating a series of points.
No Style. The symbol cannot be drawn.
void setCurveAttribute(CurveAttribute, bool on=true)