Qwt User's Guide: qwt_plot_curve.cpp Source File

Qwt User's Guide 6.2.0

qwt_plot_curve.cpp
1 /******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10 #include "qwt_plot_curve.h"
11 #include "qwt_point_data.h"
12 #include "qwt_math.h"
13 #include "qwt_clipper.h"
14 #include "qwt_painter.h"
15 #include "qwt_scale_map.h"
16 #include "qwt_plot.h"
17 #include "qwt_spline_curve_fitter.h"
18 #include "qwt_symbol.h"
19 #include "qwt_point_mapper.h"
20 #include "qwt_text.h"
21 #include "qwt_graphic.h"
22
23 #include <qpainter.h>
24 #include <qpainterpath.h>
25
26 static inline QRectF qwtIntersectedClipRect( const QRectF& rect, QPainter* painter )
27 {
28 QRectF clipRect = rect;
29 if ( painter->hasClipping() )
30 clipRect &= painter->clipBoundingRect();
31
32 return clipRect;
33 }
34
35 static void qwtUpdateLegendIconSize( QwtPlotCurve* curve )
36 {
37 if ( curve->symbol() &&
38 curve->testLegendAttribute( QwtPlotCurve::LegendShowSymbol ) )
39 {
40 QSize sz = curve->symbol()->boundingRect().size();
41 sz += QSize( 2, 2 ); // margin
42
43 if ( curve->testLegendAttribute( QwtPlotCurve::LegendShowLine ) )
44 {
45 // Avoid, that the line is completely covered by the symbol
46
47 int w = qwtCeil( 1.5 * sz.width() );
48 if ( w % 2 )
49 w++;
50
51 sz.setWidth( qMax( 8, w ) );
52 }
53
54 curve->setLegendIconSize( sz );
55 }
56 }
57
58 static int qwtVerifyRange( int size, int& i1, int& i2 )
59 {
60 if ( size < 1 )
61 return 0;
62
63 i1 = qBound( 0, i1, size - 1 );
64 i2 = qBound( 0, i2, size - 1 );
65
66 if ( i1 > i2 )
67 qSwap( i1, i2 );
68
69 return ( i2 - i1 + 1 );
70 }
71
72 class QwtPlotCurve::PrivateData
73 {
74 public:
75 PrivateData()
76 : style( QwtPlotCurve::Lines )
77 , baseline( 0.0 )
78 , symbol( NULL )
79 , pen( Qt::black )
80 , paintAttributes( QwtPlotCurve::ClipPolygons | QwtPlotCurve::FilterPoints )
81 {
82 curveFitter = new QwtSplineCurveFitter;
83 }
84
85 ~PrivateData()
86 {
87 delete symbol;
88 delete curveFitter;
89 }
90
91 QwtPlotCurve::CurveStyle style;
92 double baseline;
93
94 const QwtSymbol* symbol;
95 QwtCurveFitter* curveFitter;
96
97 QPen pen;
98 QBrush brush;
99
100 QwtPlotCurve::CurveAttributes attributes;
101 QwtPlotCurve::PaintAttributes paintAttributes;
102
103 QwtPlotCurve::LegendAttributes legendAttributes;
104 };
105
110 QwtPlotCurve::QwtPlotCurve( const QwtText& title )
111 : QwtPlotSeriesItem( title )
112 {
113 init();
114 }
115
120 QwtPlotCurve::QwtPlotCurve( const QString& title )
121 : QwtPlotSeriesItem( QwtText( title ) )
122 {
123 init();
124 }
125
127 QwtPlotCurve::~QwtPlotCurve()
128 {
129 delete m_data;
130 }
131
133 void QwtPlotCurve::init()
134 {
135 setItemAttribute( QwtPlotItem::Legend );
136 setItemAttribute( QwtPlotItem::AutoScale );
137
138 m_data = new PrivateData;
139 setData( new QwtPointSeriesData() );
140
141 setZ( 20.0 );
142 }
143
145 int QwtPlotCurve::rtti() const
146 {
147 return QwtPlotItem::Rtti_PlotCurve;
148 }
149
157 void QwtPlotCurve::setPaintAttribute( PaintAttribute attribute, bool on )
158 {
159 if ( on )
160 m_data->paintAttributes |= attribute;
161 else
162 m_data->paintAttributes &= ~attribute;
163 }
164
169 bool QwtPlotCurve::testPaintAttribute( PaintAttribute attribute ) const
170 {
171 return ( m_data->paintAttributes & attribute );
172 }
173
181 void QwtPlotCurve::setLegendAttribute( LegendAttribute attribute, bool on )
182 {
183 if ( on != testLegendAttribute( attribute ) )
184 {
185 if ( on )
186 m_data->legendAttributes |= attribute;
187 else
188 m_data->legendAttributes &= ~attribute;
189
190 qwtUpdateLegendIconSize( this );
191 legendChanged();
192 }
193 }
194
199 bool QwtPlotCurve::testLegendAttribute( LegendAttribute attribute ) const
200 {
201 return ( m_data->legendAttributes & attribute );
202 }
203
210 void QwtPlotCurve::setLegendAttributes( LegendAttributes attributes )
211 {
212 if ( attributes != m_data->legendAttributes )
213 {
214 m_data->legendAttributes = attributes;
215
216 qwtUpdateLegendIconSize( this );
217 legendChanged();
218 }
219 }
220
225 QwtPlotCurve::LegendAttributes QwtPlotCurve::legendAttributes() const
226 {
227 return m_data->legendAttributes;
228 }
229
236 void QwtPlotCurve::setStyle( CurveStyle style )
237 {
238 if ( style != m_data->style )
239 {
240 m_data->style = style;
241
242 legendChanged();
243 itemChanged();
244 }
245 }
246
251 QwtPlotCurve::CurveStyle QwtPlotCurve::style() const
252 {
253 return m_data->style;
254 }
255
266 void QwtPlotCurve::setSymbol( QwtSymbol* symbol )
267 {
268 if ( symbol != m_data->symbol )
269 {
270 delete m_data->symbol;
271 m_data->symbol = symbol;
272
273 qwtUpdateLegendIconSize( this );
274
275 legendChanged();
276 itemChanged();
277 }
278 }
279
284 const QwtSymbol* QwtPlotCurve::symbol() const
285 {
286 return m_data->symbol;
287 }
288
302 void QwtPlotCurve::setPen( const QColor& color, qreal width, Qt::PenStyle style )
303 {
304 setPen( QPen( color, width, style ) );
305 }
306
313 void QwtPlotCurve::setPen( const QPen& pen )
314 {
315 if ( pen != m_data->pen )
316 {
317 m_data->pen = pen;
318
319 legendChanged();
320 itemChanged();
321 }
322 }
323
328 const QPen& QwtPlotCurve::pen() const
329 {
330 return m_data->pen;
331 }
332
348 void QwtPlotCurve::setBrush( const QBrush& brush )
349 {
350 if ( brush != m_data->brush )
351 {
352 m_data->brush = brush;
353
354 legendChanged();
355 itemChanged();
356 }
357 }
358
363 const QBrush& QwtPlotCurve::brush() const
364 {
365 return m_data->brush;
366 }
367
381 void QwtPlotCurve::drawSeries( QPainter* painter,
382 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
383 const QRectF& canvasRect, int from, int to ) const
384 {
385 const size_t numSamples = dataSize();
386
387 if ( !painter || numSamples <= 0 )
388 return;
389
390 if ( to < 0 )
391 to = numSamples - 1;
392
393 if ( qwtVerifyRange( numSamples, from, to ) > 0 )
394 {
395 painter->save();
396 painter->setPen( m_data->pen );
397
398 /*
399 Qt 4.0.0 is slow when drawing lines, but it's even
400 slower when the painter has a brush. So we don't
401 set the brush before we really need it.
402 */
403
404 drawCurve( painter, m_data->style, xMap, yMap, canvasRect, from, to );
405 painter->restore();
406
407 if ( m_data->symbol &&
408 ( m_data->symbol->style() != QwtSymbol::NoSymbol ) )
409 {
410 painter->save();
411 drawSymbols( painter, *m_data->symbol,
412 xMap, yMap, canvasRect, from, to );
413 painter->restore();
414 }
415 }
416 }
417
429 void QwtPlotCurve::drawCurve( QPainter* painter, int style,
430 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
431 const QRectF& canvasRect, int from, int to ) const
432 {
433 switch ( style )
434 {
435 case Lines:
436 if ( testCurveAttribute( Fitted ) )
437 {
438 // we always need the complete
439 // curve for fitting
440 from = 0;
441 to = dataSize() - 1;
442 }
443 drawLines( painter, xMap, yMap, canvasRect, from, to );
444 break;
445 case Sticks:
446 drawSticks( painter, xMap, yMap, canvasRect, from, to );
447 break;
448 case Steps:
449 drawSteps( painter, xMap, yMap, canvasRect, from, to );
450 break;
451 case Dots:
452 drawDots( painter, xMap, yMap, canvasRect, from, to );
453 break;
454 case NoCurve:
455 default:
456 break;
457 }
458 }
459
476 void QwtPlotCurve::drawLines( QPainter* painter,
477 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
478 const QRectF& canvasRect, int from, int to ) const
479 {
480 if ( from > to )
481 return;
482
483 const bool doFit = ( m_data->attributes & Fitted ) && m_data->curveFitter;
484 const bool doAlign = !doFit && QwtPainter::roundingAlignment( painter );
485 const bool doFill = ( m_data->brush.style() != Qt::NoBrush )
486 && ( m_data->brush.color().alpha() > 0 );
487
488 QRectF clipRect;
489 if ( m_data->paintAttributes & ClipPolygons )
490 {
491 clipRect = qwtIntersectedClipRect( canvasRect, painter );
492
493 const qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
494 clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
495 }
496
497 QwtPointMapper mapper;
498
499 if ( doAlign )
500 {
501 mapper.setFlag( QwtPointMapper::RoundPoints, true );
502 mapper.setFlag( QwtPointMapper::WeedOutIntermediatePoints,
503 testPaintAttribute( FilterPointsAggressive ) );
504 }
505
506 mapper.setFlag( QwtPointMapper::WeedOutPoints,
507 testPaintAttribute( FilterPoints ) ||
508 testPaintAttribute( FilterPointsAggressive ) );
509
510 mapper.setBoundingRect( canvasRect );
511
512 QPolygonF polyline = mapper.toPolygonF( xMap, yMap, data(), from, to );
513
514 if ( doFill )
515 {
516 if ( doFit )
517 {
518 // it might be better to extend and draw the curvePath, but for
519 // the moment we keep an implementation, where we translate the
520 // path back to a polyline.
521
522 polyline = m_data->curveFitter->fitCurve( polyline );
523 }
524
525 if ( painter->pen().style() != Qt::NoPen )
526 {
527 // here we are wasting memory for the filled copy,
528 // do polygon clipping twice etc .. TODO
529
530 QPolygonF filled = polyline;
531 fillCurve( painter, xMap, yMap, canvasRect, filled );
532 filled.clear();
533
534 if ( m_data->paintAttributes & ClipPolygons )
535 QwtClipper::clipPolygonF( clipRect, polyline, false );
536
537 QwtPainter::drawPolyline( painter, polyline );
538 }
539 else
540 {
541 fillCurve( painter, xMap, yMap, canvasRect, polyline );
542 }
543 }
544 else
545 {
546 if ( testPaintAttribute( ClipPolygons ) )
547 {
548 QwtClipper::clipPolygonF( clipRect, polyline, false );
549 }
550
551 if ( doFit )
552 {
553 if ( m_data->curveFitter->mode() == QwtCurveFitter::Path )
554 {
555 const QPainterPath curvePath =
556 m_data->curveFitter->fitCurvePath( polyline );
557
558 painter->drawPath( curvePath );
559 }
560 else
561 {
562 polyline = m_data->curveFitter->fitCurve( polyline );
563 QwtPainter::drawPolyline( painter, polyline );
564 }
565 }
566 else
567 {
568 QwtPainter::drawPolyline( painter, polyline );
569 }
570 }
571 }
572
585 void QwtPlotCurve::drawSticks( QPainter* painter,
586 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
587 const QRectF& canvasRect, int from, int to ) const
588 {
589 Q_UNUSED( canvasRect )
590
591 painter->save();
592 painter->setRenderHint( QPainter::Antialiasing, false );
593
594 const bool doAlign = QwtPainter::roundingAlignment( painter );
595
596 double x0 = xMap.transform( m_data->baseline );
597 double y0 = yMap.transform( m_data->baseline );
598 if ( doAlign )
599 {
600 x0 = qRound( x0 );
601 y0 = qRound( y0 );
602 }
603
604 const Qt::Orientation o = orientation();
605
606 const QwtSeriesData< QPointF >* series = data();
607
608 for ( int i = from; i <= to; i++ )
609 {
610 const QPointF sample = series->sample( i );
611 double xi = xMap.transform( sample.x() );
612 double yi = yMap.transform( sample.y() );
613 if ( doAlign )
614 {
615 xi = qRound( xi );
616 yi = qRound( yi );
617 }
618
619 if ( o == Qt::Horizontal )
620 QwtPainter::drawLine( painter, x0, yi, xi, yi );
621 else
622 QwtPainter::drawLine( painter, xi, y0, xi, yi );
623 }
624
625 painter->restore();
626 }
627
640 void QwtPlotCurve::drawDots( QPainter* painter,
641 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
642 const QRectF& canvasRect, int from, int to ) const
643 {
644 const QColor color = painter->pen().color();
645
646 if ( painter->pen().style() == Qt::NoPen || color.alpha() == 0 )
647 {
648 return;
649 }
650
651 const bool doFill = ( m_data->brush.style() != Qt::NoBrush )
652 && ( m_data->brush.color().alpha() > 0 );
653 const bool doAlign = QwtPainter::roundingAlignment( painter );
654
655 QwtPointMapper mapper;
656 mapper.setBoundingRect( canvasRect );
657 mapper.setFlag( QwtPointMapper::RoundPoints, doAlign );
658
659 if ( m_data->paintAttributes & FilterPoints )
660 {
661 if ( ( color.alpha() == 255 )
662 && !( painter->renderHints() & QPainter::Antialiasing ) )
663 {
664 mapper.setFlag( QwtPointMapper::WeedOutPoints, true );
665 }
666 }
667
668 if ( doFill )
669 {
670 mapper.setFlag( QwtPointMapper::WeedOutPoints, false );
671
672 QPolygonF points = mapper.toPolygonF(
673 xMap, yMap, data(), from, to );
674
675 QwtPainter::drawPoints( painter, points );
676 fillCurve( painter, xMap, yMap, canvasRect, points );
677 }
678 else if ( m_data->paintAttributes & ImageBuffer )
679 {
680 const QImage image = mapper.toImage( xMap, yMap,
681 data(), from, to, m_data->pen,
682 painter->testRenderHint( QPainter::Antialiasing ),
683 renderThreadCount() );
684
685 painter->drawImage( canvasRect.toAlignedRect(), image );
686 }
687 else if ( m_data->paintAttributes & MinimizeMemory )
688 {
689 const QwtSeriesData< QPointF >* series = data();
690
691 for ( int i = from; i <= to; i++ )
692 {
693 const QPointF sample = series->sample( i );
694
695 double xi = xMap.transform( sample.x() );
696 double yi = yMap.transform( sample.y() );
697
698 if ( doAlign )
699 {
700 xi = qRound( xi );
701 yi = qRound( yi );
702 }
703
704 QwtPainter::drawPoint( painter, QPointF( xi, yi ) );
705 }
706 }
707 else
708 {
709 if ( doAlign )
710 {
711 const QPolygon points = mapper.toPoints(
712 xMap, yMap, data(), from, to );
713
714 QwtPainter::drawPoints( painter, points );
715 }
716 else
717 {
718 const QPolygonF points = mapper.toPointsF(
719 xMap, yMap, data(), from, to );
720
721 QwtPainter::drawPoints( painter, points );
722 }
723 }
724 }
725
741 void QwtPlotCurve::drawSteps( QPainter* painter,
742 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
743 const QRectF& canvasRect, int from, int to ) const
744 {
745 const bool doAlign = QwtPainter::roundingAlignment( painter );
746
747 QPolygonF polygon( 2 * ( to - from ) + 1 );
748 QPointF* points = polygon.data();
749
750 bool inverted = orientation() == Qt::Vertical;
751 if ( m_data->attributes & Inverted )
752 inverted = !inverted;
753
754 const QwtSeriesData< QPointF >* series = data();
755
756 int i, ip;
757 for ( i = from, ip = 0; i <= to; i++, ip += 2 )
758 {
759 const QPointF sample = series->sample( i );
760 double xi = xMap.transform( sample.x() );
761 double yi = yMap.transform( sample.y() );
762 if ( doAlign )
763 {
764 xi = qRound( xi );
765 yi = qRound( yi );
766 }
767
768 if ( ip > 0 )
769 {
770 const QPointF& p0 = points[ip - 2];
771 QPointF& p = points[ip - 1];
772
773 if ( inverted )
774 {
775 p.rx() = p0.x();
776 p.ry() = yi;
777 }
778 else
779 {
780 p.rx() = xi;
781 p.ry() = p0.y();
782 }
783 }
784
785 points[ip].rx() = xi;
786 points[ip].ry() = yi;
787 }
788
789 if ( m_data->paintAttributes & ClipPolygons )
790 {
791 QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter );
792
793 const qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
794 clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
795
796 const QPolygonF clipped = QwtClipper::clippedPolygonF(
797 clipRect, polygon, false );
798
799 QwtPainter::drawPolyline( painter, clipped );
800 }
801 else
802 {
803 QwtPainter::drawPolyline( painter, polygon );
804 }
805
806 if ( m_data->brush.style() != Qt::NoBrush )
807 fillCurve( painter, xMap, yMap, canvasRect, polygon );
808 }
809
810
819 void QwtPlotCurve::setCurveAttribute( CurveAttribute attribute, bool on )
820 {
821 if ( bool( m_data->attributes & attribute ) == on )
822 return;
823
824 if ( on )
825 m_data->attributes |= attribute;
826 else
827 m_data->attributes &= ~attribute;
828
829 itemChanged();
830 }
831
836 bool QwtPlotCurve::testCurveAttribute( CurveAttribute attribute ) const
837 {
838 return m_data->attributes & attribute;
839 }
840
858 void QwtPlotCurve::setCurveFitter( QwtCurveFitter* curveFitter )
859 {
860 delete m_data->curveFitter;
861 m_data->curveFitter = curveFitter;
862
863 itemChanged();
864 }
865
872 QwtCurveFitter* QwtPlotCurve::curveFitter() const
873 {
874 return m_data->curveFitter;
875 }
876
889 void QwtPlotCurve::fillCurve( QPainter* painter,
890 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
891 const QRectF& canvasRect, QPolygonF& polygon ) const
892 {
893 if ( m_data->brush.style() == Qt::NoBrush )
894 return;
895
896 closePolyline( painter, xMap, yMap, polygon );
897 if ( polygon.count() <= 2 ) // a line can't be filled
898 return;
899
900 QBrush brush = m_data->brush;
901 if ( !brush.color().isValid() )
902 brush.setColor( m_data->pen.color() );
903
904 if ( m_data->paintAttributes & ClipPolygons )
905 {
906 const QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter );
907 QwtClipper::clipPolygonF( clipRect, polygon, true );
908 }
909
910 painter->save();
911
912 painter->setPen( Qt::NoPen );
913 painter->setBrush( brush );
914
915 QwtPainter::drawPolygon( painter, polygon );
916
917 painter->restore();
918 }
919
929 void QwtPlotCurve::closePolyline( QPainter* painter,
930 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
931 QPolygonF& polygon ) const
932 {
933 if ( polygon.size() < 2 )
934 return;
935
936 const bool doAlign = QwtPainter::roundingAlignment( painter );
937
938 double baseline = m_data->baseline;
939
940 if ( orientation() == Qt::Vertical )
941 {
942 if ( yMap.transformation() )
943 baseline = yMap.transformation()->bounded( baseline );
944
945 double refY = yMap.transform( baseline );
946 if ( doAlign )
947 refY = qRound( refY );
948
949 polygon += QPointF( polygon.last().x(), refY );
950 polygon += QPointF( polygon.first().x(), refY );
951 }
952 else
953 {
954 if ( xMap.transformation() )
955 baseline = xMap.transformation()->bounded( baseline );
956
957 double refX = xMap.transform( baseline );
958 if ( doAlign )
959 refX = qRound( refX );
960
961 polygon += QPointF( refX, polygon.last().y() );
962 polygon += QPointF( refX, polygon.first().y() );
963 }
964 }
965
979 void QwtPlotCurve::drawSymbols( QPainter* painter, const QwtSymbol& symbol,
980 const QwtScaleMap& xMap, const QwtScaleMap& yMap,
981 const QRectF& canvasRect, int from, int to ) const
982 {
983 QwtPointMapper mapper;
984 mapper.setFlag( QwtPointMapper::RoundPoints,
985 QwtPainter::roundingAlignment( painter ) );
986 mapper.setFlag( QwtPointMapper::WeedOutPoints,
987 testPaintAttribute( QwtPlotCurve::FilterPoints ) );
988
989 const QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter );
990 mapper.setBoundingRect( clipRect );
991
992 const int chunkSize = 500;
993
994 for ( int i = from; i <= to; i += chunkSize )
995 {
996 const int n = qMin( chunkSize, to - i + 1 );
997
998 const QPolygonF points = mapper.toPointsF( xMap, yMap,
999 data(), i, i + n - 1 );
1000
1001 if ( points.size() > 0 )
1002 symbol.drawSymbols( painter, points );
1003 }
1004 }
1005
1022 void QwtPlotCurve::setBaseline( double value )
1023 {
1024 if ( m_data->baseline != value )
1025 {
1026 m_data->baseline = value;
1027 itemChanged();
1028 }
1029 }
1030
1035 double QwtPlotCurve::baseline() const
1036 {
1037 return m_data->baseline;
1038 }
1039
1051 int QwtPlotCurve::closestPoint( const QPointF& pos, double* dist ) const
1052 {
1053 const size_t numSamples = dataSize();
1054
1055 if ( plot() == NULL || numSamples <= 0 )
1056 return -1;
1057
1058 const QwtSeriesData< QPointF >* series = data();
1059
1060 const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
1061 const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
1062
1063 int index = -1;
1064 double dmin = 1.0e10;
1065
1066 for ( uint i = 0; i < numSamples; i++ )
1067 {
1068 const QPointF sample = series->sample( i );
1069
1070 const double cx = xMap.transform( sample.x() ) - pos.x();
1071 const double cy = yMap.transform( sample.y() ) - pos.y();
1072
1073 const double f = qwtSqr( cx ) + qwtSqr( cy );
1074 if ( f < dmin )
1075 {
1076 index = i;
1077 dmin = f;
1078 }
1079 }
1080 if ( dist )
1081 *dist = std::sqrt( dmin );
1082
1083 return index;
1084 }
1085
1095 QwtGraphic QwtPlotCurve::legendIcon( int index, const QSizeF& size ) const
1096 {
1097 Q_UNUSED( index );
1098
1099 if ( size.isEmpty() )
1100 return QwtGraphic();
1101
1102 QwtGraphic graphic;
1103 graphic.setDefaultSize( size );
1104 graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true );
1105
1106 QPainter painter( &graphic );
1107 painter.setRenderHint( QPainter::Antialiasing,
1108 testRenderHint( QwtPlotItem::RenderAntialiased ) );
1109
1110 if ( m_data->legendAttributes == 0 ||
1111 m_data->legendAttributes & QwtPlotCurve::LegendShowBrush )
1112 {
1113 QBrush brush = m_data->brush;
1114
1115 if ( brush.style() == Qt::NoBrush &&
1116 m_data->legendAttributes == 0 )
1117 {
1118 if ( style() != QwtPlotCurve::NoCurve )
1119 {
1120 brush = QBrush( pen().color() );
1121 }
1122 else if ( m_data->symbol &&
1123 ( m_data->symbol->style() != QwtSymbol::NoSymbol ) )
1124 {
1125 brush = QBrush( m_data->symbol->pen().color() );
1126 }
1127 }
1128
1129 if ( brush.style() != Qt::NoBrush )
1130 {
1131 QRectF r( 0, 0, size.width(), size.height() );
1132 painter.fillRect( r, brush );
1133 }
1134 }
1135
1136 if ( m_data->legendAttributes & QwtPlotCurve::LegendShowLine )
1137 {
1138 if ( pen() != Qt::NoPen )
1139 {
1140 QPen pn = pen();
1141 pn.setCapStyle( Qt::FlatCap );
1142
1143 painter.setPen( pn );
1144
1145 const double y = 0.5 * size.height();
1146 QwtPainter::drawLine( &painter, 0.0, y, size.width(), y );
1147 }
1148 }
1149
1150 if ( m_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
1151 {
1152 if ( m_data->symbol )
1153 {
1154 QRectF r( 0, 0, size.width(), size.height() );
1155 m_data->symbol->drawSymbol( &painter, r );
1156 }
1157 }
1158
1159 return graphic;
1160 }
1161
1172 void QwtPlotCurve::setSamples( QwtSeriesData< QPointF >* data )
1173 {
1174 setData( data );
1175 }
1176
1184 void QwtPlotCurve::setSamples( const QVector< QPointF >& samples )
1185 {
1186 setData( new QwtPointSeriesData( samples ) );
1187 }
1188
1203 void QwtPlotCurve::setRawSamples(
1204 const double* xData, const double* yData, int size )
1205 {
1206 setData( new QwtCPointerData< double >( xData, yData, size ) );
1207 }
1208
1223 void QwtPlotCurve::setRawSamples(
1224 const float* xData, const float* yData, int size )
1225 {
1226 setData( new QwtCPointerData< float >( xData, yData, size ) );
1227 }
1228
1245 void QwtPlotCurve::setRawSamples( const double* yData, int size )
1246 {
1247 setData( new QwtCPointerValueData< double >( yData, size ) );
1248 }
1249
1266 void QwtPlotCurve::setRawSamples( const float* yData, int size )
1267 {
1268 setData( new QwtCPointerValueData< float >( yData, size ) );
1269 }
1270
1282 void QwtPlotCurve::setSamples(
1283 const double* xData, const double* yData, int size )
1284 {
1285 setData( new QwtPointArrayData< double >( xData, yData, size ) );
1286 }
1287
1299 void QwtPlotCurve::setSamples(
1300 const float* xData, const float* yData, int size )
1301 {
1302 setData( new QwtPointArrayData< float >( xData, yData, size ) );
1303 }
1304
1313 void QwtPlotCurve::setSamples( const QVector< double >& xData,
1314 const QVector< double >& yData )
1315 {
1316 setData( new QwtPointArrayData< double >( xData, yData ) );
1317 }
1318
1327 void QwtPlotCurve::setSamples( const QVector< float >& xData,
1328 const QVector< float >& yData )
1329 {
1330 setData( new QwtPointArrayData< float >( xData, yData ) );
1331 }
1332
1344 void QwtPlotCurve::setSamples( const double* yData, int size )
1345 {
1346 setData( new QwtValuePointData< double >( yData, size ) );
1347 }
1348
1360 void QwtPlotCurve::setSamples( const float* yData, int size )
1361 {
1362 setData( new QwtValuePointData< float >( yData, size ) );
1363 }
1364
1375 void QwtPlotCurve::setSamples( const QVector< double >& yData )
1376 {
1377 setData( new QwtValuePointData< double >( yData ) );
1378 }
1379
1390 void QwtPlotCurve::setSamples( const QVector< float >& yData )
1391 {
1392 setData( new QwtValuePointData< float >( yData ) );
1393 }
QVector
Definition: qwt_clipper.h:23
QwtCPointerData
Data class containing two pointers to memory blocks of T.
Definition: qwt_point_data.h:44
QwtCPointerValueData
Data class containing a pointer to memory of y coordinates.
Definition: qwt_point_data.h:90
QwtCurveFitter
Abstract base class for a curve fitter.
Definition: qwt_curve_fitter.h:22
QwtCurveFitter::Path
@ Path
Definition: qwt_curve_fitter.h:48
QwtGraphic
A paint device for scalable graphics.
Definition: qwt_graphic.h:76
QwtGraphic::RenderPensUnscaled
@ RenderPensUnscaled
Definition: qwt_graphic.h:96
QwtGraphic::setRenderHint
void setRenderHint(RenderHint, bool on=true)
Definition: qwt_graphic.cpp:443
QwtGraphic::setDefaultSize
void setDefaultSize(const QSizeF &)
Set a default size.
Definition: qwt_graphic.cpp:553
QwtPainter::drawPoints
static void drawPoints(QPainter *, const QPolygon &)
Wrapper for QPainter::drawPoints()
Definition: qwt_painter.h:142
QwtPainter::drawPolygon
static void drawPolygon(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolygon()
Definition: qwt_painter.cpp:561
QwtPainter::drawPolyline
static void drawPolyline(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolyline()
Definition: qwt_painter.cpp:578
QwtPainter::effectivePenWidth
static qreal effectivePenWidth(const QPen &)
Definition: qwt_painter.h:201
QwtPainter::drawPoint
static void drawPoint(QPainter *, const QPoint &)
Wrapper for QPainter::drawPoint()
Definition: qwt_painter.cpp:691
QwtPainter::roundingAlignment
static bool roundingAlignment()
Definition: qwt_painter.h:183
QwtPainter::drawLine
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
Definition: qwt_painter.h:154
QwtPlotCurve
A plot item, that represents a series of points.
Definition: qwt_plot_curve.h:59
QwtPlotCurve::setLegendAttribute
void setLegendAttribute(LegendAttribute, bool on=true)
Definition: qwt_plot_curve.cpp:181
QwtPlotCurve::drawSeries
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const override
Definition: qwt_plot_curve.cpp:381
QwtPlotCurve::setLegendAttributes
void setLegendAttributes(LegendAttributes)
Definition: qwt_plot_curve.cpp:210
QwtPlotCurve::CurveStyle
CurveStyle
Definition: qwt_plot_curve.h:66
QwtPlotCurve::NoCurve
@ NoCurve
Definition: qwt_plot_curve.h:70
QwtPlotCurve::Steps
@ Steps
Definition: qwt_plot_curve.h:90
QwtPlotCurve::Sticks
@ Sticks
Definition: qwt_plot_curve.h:83
QwtPlotCurve::Lines
@ Lines
Definition: qwt_plot_curve.h:77
QwtPlotCurve::Dots
@ Dots
Definition: qwt_plot_curve.h:98
QwtPlotCurve::closePolyline
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...
Definition: qwt_plot_curve.cpp:929
QwtPlotCurve::legendAttributes
LegendAttributes legendAttributes() const
Definition: qwt_plot_curve.cpp:225
QwtPlotCurve::drawCurve
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.
Definition: qwt_plot_curve.cpp:429
QwtPlotCurve::LegendAttributes
QFlags< LegendAttribute > LegendAttributes
Definition: qwt_plot_curve.h:168
QwtPlotCurve::fillCurve
virtual void fillCurve(QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRectF &canvasRect, QPolygonF &) const
Definition: qwt_plot_curve.cpp:889
QwtPlotCurve::setStyle
void setStyle(CurveStyle style)
Definition: qwt_plot_curve.cpp:236
QwtPlotCurve::CurveAttribute
CurveAttribute
Definition: qwt_plot_curve.h:113
QwtPlotCurve::Fitted
@ Fitted
Definition: qwt_plot_curve.h:130
QwtPlotCurve::Inverted
@ Inverted
Definition: qwt_plot_curve.h:118
QwtPlotCurve::style
CurveStyle style() const
Definition: qwt_plot_curve.cpp:251
QwtPlotCurve::setSymbol
void setSymbol(QwtSymbol *)
Assign a symbol.
Definition: qwt_plot_curve.cpp:266
QwtPlotCurve::closestPoint
virtual int closestPoint(const QPointF &pos, double *dist=NULL) const
Definition: qwt_plot_curve.cpp:1051
QwtPlotCurve::drawDots
virtual void drawDots(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Definition: qwt_plot_curve.cpp:640
QwtPlotCurve::QwtPlotCurve
QwtPlotCurve(const QString &title=QString())
Definition: qwt_plot_curve.cpp:120
QwtPlotCurve::drawSticks
virtual void drawSticks(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Definition: qwt_plot_curve.cpp:585
QwtPlotCurve::drawSymbols
virtual void drawSymbols(QPainter *, const QwtSymbol &, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Definition: qwt_plot_curve.cpp:979
QwtPlotCurve::testLegendAttribute
bool testLegendAttribute(LegendAttribute) const
Definition: qwt_plot_curve.cpp:199
QwtPlotCurve::testCurveAttribute
bool testCurveAttribute(CurveAttribute) const
Definition: qwt_plot_curve.cpp:836
QwtPlotCurve::setCurveAttribute
void setCurveAttribute(CurveAttribute, bool on=true)
Definition: qwt_plot_curve.cpp:819
QwtPlotCurve::LegendAttribute
LegendAttribute
Definition: qwt_plot_curve.h:143
QwtPlotCurve::LegendShowBrush
@ LegendShowBrush
Definition: qwt_plot_curve.h:165
QwtPlotCurve::LegendShowSymbol
@ LegendShowSymbol
Definition: qwt_plot_curve.h:159
QwtPlotCurve::LegendShowLine
@ LegendShowLine
Definition: qwt_plot_curve.h:154
QwtPlotCurve::init
void init()
Initialize internal members.
Definition: qwt_plot_curve.cpp:133
QwtPlotCurve::setPaintAttribute
void setPaintAttribute(PaintAttribute, bool on=true)
Definition: qwt_plot_curve.cpp:157
QwtPlotCurve::PaintAttribute
PaintAttribute
Definition: qwt_plot_curve.h:177
QwtPlotCurve::MinimizeMemory
@ MinimizeMemory
Definition: qwt_plot_curve.h:198
QwtPlotCurve::ClipPolygons
@ ClipPolygons
Definition: qwt_plot_curve.h:183
QwtPlotCurve::FilterPointsAggressive
@ FilterPointsAggressive
Definition: qwt_plot_curve.h:231
QwtPlotCurve::ImageBuffer
@ ImageBuffer
Definition: qwt_plot_curve.h:207
QwtPlotCurve::FilterPoints
@ FilterPoints
Definition: qwt_plot_curve.h:191
QwtPlotCurve::testPaintAttribute
bool testPaintAttribute(PaintAttribute) const
Definition: qwt_plot_curve.cpp:169
QwtPlotCurve::legendIcon
virtual QwtGraphic legendIcon(int index, const QSizeF &) const override
Definition: qwt_plot_curve.cpp:1095
QwtPlotCurve::drawLines
virtual void drawLines(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Draw lines.
Definition: qwt_plot_curve.cpp:476
QwtPlotCurve::~QwtPlotCurve
virtual ~QwtPlotCurve()
Destructor.
Definition: qwt_plot_curve.cpp:127
QwtPlotCurve::setSamples
void setSamples(const double *xData, const double *yData, int size)
Definition: qwt_plot_curve.cpp:1282
QwtPlotCurve::pen
const QPen & pen() const
Definition: qwt_plot_curve.cpp:328
QwtPlotCurve::setCurveFitter
void setCurveFitter(QwtCurveFitter *)
Definition: qwt_plot_curve.cpp:858
QwtPlotCurve::brush
const QBrush & brush() const
Definition: qwt_plot_curve.cpp:363
QwtPlotCurve::setBaseline
void setBaseline(double)
Set the value of the baseline.
Definition: qwt_plot_curve.cpp:1022
QwtPlotCurve::setBrush
void setBrush(const QBrush &)
Assign a brush.
Definition: qwt_plot_curve.cpp:348
QwtPlotCurve::symbol
const QwtSymbol * symbol() const
Definition: qwt_plot_curve.cpp:284
QwtPlotCurve::PaintAttributes
QFlags< PaintAttribute > PaintAttributes
Definition: qwt_plot_curve.h:234
QwtPlotCurve::setPen
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
Definition: qwt_plot_curve.cpp:302
QwtPlotCurve::curveFitter
QwtCurveFitter * curveFitter() const
Definition: qwt_plot_curve.cpp:872
QwtPlotCurve::CurveAttributes
QFlags< CurveAttribute > CurveAttributes
Definition: qwt_plot_curve.h:133
QwtPlotCurve::baseline
double baseline() const
Definition: qwt_plot_curve.cpp:1035
QwtPlotCurve::drawSteps
virtual void drawSteps(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Definition: qwt_plot_curve.cpp:741
QwtPlotCurve::rtti
virtual int rtti() const override
Definition: qwt_plot_curve.cpp:145
QwtPlotCurve::setRawSamples
void setRawSamples(const double *xData, const double *yData, int size)
Initialize the data by pointing to memory blocks which are not managed by QwtPlotCurve.
Definition: qwt_plot_curve.cpp:1203
QwtPlot::canvasMap
virtual QwtScaleMap canvasMap(QwtAxisId) const
Definition: qwt_plot.cpp:800
QwtPlotItem::yAxis
QwtAxisId yAxis() const
Return yAxis.
Definition: qwt_plot_item.cpp:559
QwtPlotItem::setLegendIconSize
void setLegendIconSize(const QSize &)
Definition: qwt_plot_item.cpp:373
QwtPlotItem::legendChanged
virtual void legendChanged()
Definition: qwt_plot_item.cpp:491
QwtPlotItem::setZ
void setZ(double z)
Set the z value.
Definition: qwt_plot_item.cpp:165
QwtPlotItem::setItemAttribute
void setItemAttribute(ItemAttribute, bool on=true)
Definition: qwt_plot_item.cpp:228
QwtPlotItem::plot
QwtPlot * plot() const
Return attached plot.
Definition: qwt_plot_item.cpp:142
QwtPlotItem::xAxis
QwtAxisId xAxis() const
Return xAxis.
Definition: qwt_plot_item.cpp:553
QwtPlotItem::Rtti_PlotCurve
@ Rtti_PlotCurve
For QwtPlotCurve.
Definition: qwt_plot_item.h:93
QwtPlotItem::RenderAntialiased
@ RenderAntialiased
Enable antialiasing.
Definition: qwt_plot_item.h:206
QwtPlotItem::testRenderHint
bool testRenderHint(RenderHint) const
Definition: qwt_plot_item.cpp:332
QwtPlotItem::itemChanged
virtual void itemChanged()
Definition: qwt_plot_item.cpp:481
QwtPlotItem::Legend
@ Legend
The item is represented on the legend.
Definition: qwt_plot_item.h:150
QwtPlotItem::AutoScale
@ AutoScale
Definition: qwt_plot_item.h:157
QwtPlotItem::renderThreadCount
uint renderThreadCount() const
Definition: qwt_plot_item.cpp:360
QwtPlotSeriesItem
Base class for plot items representing a series of samples.
Definition: qwt_plot_seriesitem.h:26
QwtPlotSeriesItem::orientation
Qt::Orientation orientation() const
Definition: qwt_plot_seriesitem.cpp:77
QwtPointArrayData
Interface for iterating over two QVector<T> objects.
Definition: qwt_point_data.h:23
QwtPointMapper
A helper class for translating a series of points.
Definition: qwt_point_mapper.h:33
QwtPointMapper::setBoundingRect
void setBoundingRect(const QRectF &)
Definition: qwt_point_mapper.cpp:612
QwtPointMapper::toPolygonF
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.
Definition: qwt_point_mapper.cpp:647
QwtPointMapper::toImage
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.
Definition: qwt_point_mapper.cpp:883
QwtPointMapper::toPointsF
QPolygonF toPointsF(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtSeriesData< QPointF > *series, int from, int to) const
Translate a series into a QPolygonF.
Definition: qwt_point_mapper.cpp:759
QwtPointMapper::setFlag
void setFlag(TransformationFlag, bool on=true)
Definition: qwt_point_mapper.cpp:586
QwtPointMapper::RoundPoints
@ RoundPoints
Round points to integer values.
Definition: qwt_point_mapper.h:42
QwtPointMapper::WeedOutPoints
@ WeedOutPoints
Definition: qwt_point_mapper.h:48
QwtPointMapper::WeedOutIntermediatePoints
@ WeedOutIntermediatePoints
Definition: qwt_point_mapper.h:68
QwtPointMapper::toPoints
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.
Definition: qwt_point_mapper.cpp:833
QwtPointSeriesData
Interface for iterating over an array of points.
Definition: qwt_series_data.h:210
QwtScaleMap
A scale map.
Definition: qwt_scale_map.h:27
QwtScaleMap::transform
double transform(double s) const
Definition: qwt_scale_map.h:137
QwtScaleMap::transformation
const QwtTransform * transformation() const
Get the transformation.
Definition: qwt_scale_map.cpp:88
QwtSeriesData< QPointF >
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtSeriesStore< QPointF >::sample
QPointF sample(int index) const
Definition: qwt_series_store.h:158
QwtSeriesStore< QPointF >::dataSize
virtual size_t dataSize() const override
Definition: qwt_series_store.h:175
QwtSeriesStore< QPointF >::data
QwtSeriesData< QPointF > * data()
Definition: qwt_series_store.h:146
QwtSeriesStore< QPointF >::setData
void setData(QwtSeriesData< QPointF > *series)
Definition: qwt_series_store.h:164
QwtSplineCurveFitter
A curve fitter using a spline interpolation.
Definition: qwt_spline_curve_fitter.h:26
QwtSymbol
A class for drawing symbols.
Definition: qwt_symbol.h:32
QwtSymbol::boundingRect
virtual QRect boundingRect() const
Definition: qwt_symbol.cpp:1637
QwtSymbol::drawSymbols
void drawSymbols(QPainter *, const QPolygonF &) const
Draw symbols at the specified points.
Definition: qwt_symbol.h:251
QwtSymbol::NoSymbol
@ NoSymbol
No Style. The symbol cannot be drawn.
Definition: qwt_symbol.h:41
QwtText
A class representing a text.
Definition: qwt_text.h:52
QwtTransform::bounded
virtual double bounded(double value) const
Definition: qwt_transform.cpp:33
QwtValuePointData
Interface for iterating over a QVector<T>.
Definition: qwt_point_data.h:68
QwtClipper::clippedPolygonF
QWT_EXPORT QPolygonF clippedPolygonF(const QRectF &, const QPolygonF &, bool closePolygon=false)
Definition: qwt_clipper.cpp:455
QwtClipper::clipPolygonF
QWT_EXPORT void clipPolygonF(const QRectF &, QPolygonF &, bool closePolygon=false)
Definition: qwt_clipper.cpp:404