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() &&
39  {
40  QSize sz = curve->symbol()->boundingRect().size();
41  sz += QSize( 2, 2 ); // margin
42 
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()
77  , baseline( 0.0 )
78  , symbol( NULL )
79  , pen( Qt::black )
80  , paintAttributes( QwtPlotCurve::ClipPolygons | QwtPlotCurve::FilterPoints )
81  {
83  }
84 
85  ~PrivateData()
86  {
87  delete symbol;
88  delete curveFitter;
89  }
90 
92  double baseline;
93 
94  const QwtSymbol* symbol;
96 
97  QPen pen;
98  QBrush brush;
99 
101  QwtPlotCurve::PaintAttributes paintAttributes;
102 
104 };
105 
111  : QwtPlotSeriesItem( title )
112 {
113  init();
114 }
115 
120 QwtPlotCurve::QwtPlotCurve( const QString& title )
121  : QwtPlotSeriesItem( QwtText( title ) )
122 {
123  init();
124 }
125 
128 {
129  delete m_data;
130 }
131 
134 {
137 
138  m_data = new PrivateData;
139  setData( new QwtPointSeriesData() );
140 
141  setZ( 20.0 );
142 }
143 
146 {
148 }
149 
158 {
159  if ( on )
160  m_data->paintAttributes |= attribute;
161  else
162  m_data->paintAttributes &= ~attribute;
163 }
164 
170 {
171  return ( m_data->paintAttributes & attribute );
172 }
173 
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 
200 {
201  return ( m_data->legendAttributes & attribute );
202 }
203 
211 {
212  if ( attributes != m_data->legendAttributes )
213  {
214  m_data->legendAttributes = attributes;
215 
216  qwtUpdateLegendIconSize( this );
217  legendChanged();
218  }
219 }
220 
226 {
227  return m_data->legendAttributes;
228 }
229 
237 {
238  if ( style != m_data->style )
239  {
240  m_data->style = style;
241 
242  legendChanged();
243  itemChanged();
244  }
245 }
246 
252 {
253  return m_data->style;
254 }
255 
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 
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 );
504  }
505 
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  {
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 
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 
837 {
838  return m_data->attributes & attribute;
839 }
840 
859 {
860  delete m_data->curveFitter;
861  m_data->curveFitter = curveFitter;
862 
863  itemChanged();
864 }
865 
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() )
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() )
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;
985  QwtPainter::roundingAlignment( painter ) );
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 
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 );
1105 
1106  QPainter painter( &graphic );
1107  painter.setRenderHint( QPainter::Antialiasing,
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 
1173 {
1174  setData( data );
1175 }
1176 
1185 {
1186  setData( new QwtPointSeriesData( samples ) );
1187 }
1188 
1204  const double* xData, const double* yData, int size )
1205 {
1206  setData( new QwtCPointerData< double >( xData, yData, size ) );
1207 }
1208 
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 
1283  const double* xData, const double* yData, int size )
1284 {
1285  setData( new QwtPointArrayData< double >( xData, yData, size ) );
1286 }
1287 
1300  const float* xData, const float* yData, int size )
1301 {
1302  setData( new QwtPointArrayData< float >( xData, yData, size ) );
1303 }
1304 
1314  const QVector< double >& yData )
1315 {
1316  setData( new QwtPointArrayData< double >( xData, yData ) );
1317 }
1318 
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 
1376 {
1377  setData( new QwtValuePointData< double >( yData ) );
1378 }
1379 
1391 {
1392  setData( new QwtValuePointData< float >( yData ) );
1393 }
Data class containing two pointers to memory blocks of T.
Data class containing a pointer to memory of y coordinates.
Abstract base class for a curve fitter.
A paint device for scalable graphics.
Definition: qwt_graphic.h:76
@ RenderPensUnscaled
Definition: qwt_graphic.h:96
void setRenderHint(RenderHint, bool on=true)
void setDefaultSize(const QSizeF &)
Set a default size.
static void drawPoints(QPainter *, const QPolygon &)
Wrapper for QPainter::drawPoints()
Definition: qwt_painter.h:142
static void drawPolygon(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolygon()
static void drawPolyline(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolyline()
static qreal effectivePenWidth(const QPen &)
Definition: qwt_painter.h:201
static void drawPoint(QPainter *, const QPoint &)
Wrapper for QPainter::drawPoint()
static bool roundingAlignment()
Definition: qwt_painter.h:183
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
Definition: qwt_painter.h:154
A plot item, that represents a series of points.
void setLegendAttribute(LegendAttribute, bool on=true)
virtual void drawSeries(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const override
void setLegendAttributes(LegendAttributes)
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...
LegendAttributes legendAttributes() 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.
QFlags< LegendAttribute > LegendAttributes
virtual void fillCurve(QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRectF &canvasRect, QPolygonF &) const
void setStyle(CurveStyle style)
CurveStyle style() const
void setSymbol(QwtSymbol *)
Assign a symbol.
virtual int closestPoint(const QPointF &pos, double *dist=NULL) const
virtual void drawDots(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
QwtPlotCurve(const QString &title=QString())
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
bool testLegendAttribute(LegendAttribute) const
bool testCurveAttribute(CurveAttribute) const
void setCurveAttribute(CurveAttribute, bool on=true)
void init()
Initialize internal members.
void setPaintAttribute(PaintAttribute, bool on=true)
bool testPaintAttribute(PaintAttribute) const
virtual QwtGraphic legendIcon(int index, const QSizeF &) const override
virtual void drawLines(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
Draw lines.
virtual ~QwtPlotCurve()
Destructor.
void setSamples(const double *xData, const double *yData, int size)
const QPen & pen() const
void setCurveFitter(QwtCurveFitter *)
const QBrush & brush() const
void setBaseline(double)
Set the value of the baseline.
void setBrush(const QBrush &)
Assign a brush.
const QwtSymbol * symbol() const
QFlags< PaintAttribute > PaintAttributes
void setPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
QwtCurveFitter * curveFitter() const
QFlags< CurveAttribute > CurveAttributes
double baseline() const
virtual void drawSteps(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
virtual int rtti() const override
void setRawSamples(const double *xData, const double *yData, int size)
Initialize the data by pointing to memory blocks which are not managed by QwtPlotCurve.
virtual QwtScaleMap canvasMap(QwtAxisId) const
Definition: qwt_plot.cpp:800
QwtAxisId yAxis() const
Return yAxis.
void setLegendIconSize(const QSize &)
virtual void legendChanged()
void setZ(double z)
Set the z value.
void setItemAttribute(ItemAttribute, bool on=true)
QwtPlot * plot() const
Return attached plot.
QwtAxisId xAxis() const
Return xAxis.
@ Rtti_PlotCurve
For QwtPlotCurve.
Definition: qwt_plot_item.h:93
@ RenderAntialiased
Enable antialiasing.
bool testRenderHint(RenderHint) const
virtual void itemChanged()
@ Legend
The item is represented on the legend.
uint renderThreadCount() const
Base class for plot items representing a series of samples.
Qt::Orientation orientation() const
Interface for iterating over two QVector<T> objects.
A helper class for translating a series of points.
void setBoundingRect(const QRectF &)
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.
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.
QPolygonF toPointsF(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtSeriesData< QPointF > *series, int from, int to) const
Translate a series into a QPolygonF.
void setFlag(TransformationFlag, bool on=true)
@ RoundPoints
Round points to integer values.
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.
Interface for iterating over an array of points.
A scale map.
Definition: qwt_scale_map.h:27
double transform(double s) const
const QwtTransform * transformation() const
Get the transformation.
virtual T sample(size_t i) const =0
QPointF sample(int index) const
virtual size_t dataSize() const override
QwtSeriesData< QPointF > * data()
void setData(QwtSeriesData< QPointF > *series)
A curve fitter using a spline interpolation.
A class for drawing symbols.
Definition: qwt_symbol.h:32
virtual QRect boundingRect() const
void drawSymbols(QPainter *, const QPolygonF &) const
Draw symbols at the specified points.
Definition: qwt_symbol.h:251
@ NoSymbol
No Style. The symbol cannot be drawn.
Definition: qwt_symbol.h:41
A class representing a text.
Definition: qwt_text.h:52
virtual double bounded(double value) const
Interface for iterating over a QVector<T>.
QWT_EXPORT QPolygonF clippedPolygonF(const QRectF &, const QPolygonF &, bool closePolygon=false)
QWT_EXPORT void clipPolygonF(const QRectF &, QPolygonF &, bool closePolygon=false)