qwt_plot_curve.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  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. #ifndef QWT_PLOT_CURVE_H
  10. #define QWT_PLOT_CURVE_H
  11. #include "qwt_global.h"
  12. #include "qwt_plot_seriesitem.h"
  13. #include "qwt_series_data.h"
  14. #include "qwt_text.h"
  15. #include <qpen.h>
  16. #include <qstring.h>
  17. class QPainter;
  18. class QPolygonF;
  19. class QwtScaleMap;
  20. class QwtSymbol;
  21. class QwtCurveFitter;
  22. /*!
  23. \brief A plot item, that represents a series of points
  24. A curve is the representation of a series of points in the x-y plane.
  25. It supports different display styles, interpolation ( f.e. spline )
  26. and symbols.
  27. \par Usage
  28. <dl><dt>a) Assign curve properties</dt>
  29. <dd>When a curve is created, it is configured to draw black solid lines
  30. with in Lines style and no symbols. You can change this by calling
  31. setPen(), setStyle() and setSymbol().</dd>
  32. <dt>b) Connect/Assign data.</dt>
  33. <dd>QwtPlotCurve gets its points using a QwtData object offering
  34. a bridge to the real storage of the points ( like QAbstractItemModel ).
  35. There are several convenience classes derived from QwtData, that also store
  36. the points inside ( like QStandardItemModel ). QwtPlotCurve also offers
  37. a couple of variations of setData(), that build QwtData objects from
  38. arrays internally.</dd>
  39. <dt>c) Attach the curve to a plot</dt>
  40. <dd>See QwtPlotItem::attach()
  41. </dd></dl>
  42. \par Example:
  43. see examples/bode
  44. \sa QwtPointSeriesData, QwtSymbol, QwtScaleMap
  45. */
  46. class QWT_EXPORT QwtPlotCurve: public QwtPlotSeriesItem<QPointF>
  47. {
  48. public:
  49. /*!
  50. Curve styles.
  51. - NoCurve\n
  52. Don't draw a curve. Note: This doesn't affect the symbols.
  53. - Lines\n
  54. Connect the points with straight lines. The lines might
  55. be interpolated depending on the 'Fitted' attribute. Curve
  56. fitting can be configured using setCurveFitter().
  57. - Sticks\n
  58. Draw vertical or horizontal sticks ( depending on the
  59. orientation() ) from a baseline which is defined by setBaseline().
  60. - Steps\n
  61. Connect the points with a step function. The step function
  62. is drawn from the left to the right or vice versa,
  63. depending on the 'Inverted' attribute.
  64. - Dots\n
  65. Draw dots at the locations of the data points. Note:
  66. This is different from a dotted line (see setPen()), and faster
  67. as a curve in NoStyle style and a symbol painting a point.
  68. - UserCurve\n
  69. Styles >= UserCurve are reserved for derived
  70. classes of QwtPlotCurve that overload drawCurve() with
  71. additional application specific curve types.
  72. \sa setStyle(), style()
  73. */
  74. enum CurveStyle
  75. {
  76. NoCurve,
  77. Lines,
  78. Sticks,
  79. Steps,
  80. Dots,
  81. UserCurve = 100
  82. };
  83. /*!
  84. Attribute for drawing the curve
  85. - Fitted ( in combination with the Lines QwtPlotCurve::CurveStyle only )\n
  86. A QwtCurveFitter tries to
  87. interpolate/smooth the curve, before it is painted.
  88. Note that curve fitting requires temorary memory
  89. for calculating coefficients and additional points.
  90. If painting in Fitted mode is slow it might be better
  91. to fit the points, before they are passed to QwtPlotCurve.
  92. - Inverted\n
  93. For Steps only. Draws a step function
  94. from the right to the left.
  95. \sa setCurveAttribute(), testCurveAttribute(), curveFitter()
  96. */
  97. enum CurveAttribute
  98. {
  99. Inverted = 1,
  100. Fitted = 2
  101. };
  102. /*!
  103. Attributes how to represent the curve on the legend
  104. - LegendShowLine
  105. If the curveStyle() is not NoCurve a line is painted with the
  106. curvePen().
  107. - LegendShowSymbol
  108. If the curve has a valid symbol it is painted.
  109. - LegendShowBrush
  110. If the curve has a brush a rectangle filled with this brush
  111. is painted
  112. If none of the flags is activated QwtPlotCurve tries to find
  113. a color representing the curve and paints a rectangle with it.
  114. In the default setting all attributes are off.
  115. \sa setLegendAttribute(), testLegendAttribute(),
  116. drawLegendIdentifier()
  117. */
  118. enum LegendAttribute
  119. {
  120. LegendShowLine = 1,
  121. LegendShowSymbol = 2,
  122. LegendShowBrush = 4
  123. };
  124. /*!
  125. Attributes to modify the drawing algorithm.
  126. - ClipPolygons\n
  127. Clip polygons before painting them. In situations, where points
  128. are far outside the visible area (f.e when zooming deep) this
  129. might be a substantial improvement for the painting performance
  130. ( especially on Windows ).
  131. - CacheSymbols\n
  132. Paint the symbol to a QPixmap and paint the pixmap
  133. instead rendering the symbol for each point. The flag has
  134. no effect, when the curve is not painted to the canvas
  135. ( or its cache )
  136. The default setting enables ClipPolygons
  137. \sa setPaintAttribute(), testPaintAttribute()
  138. */
  139. enum PaintAttribute
  140. {
  141. ClipPolygons = 1,
  142. CacheSymbols = 2
  143. };
  144. explicit QwtPlotCurve( const QString &title = QString::null );
  145. explicit QwtPlotCurve( const QwtText &title );
  146. virtual ~QwtPlotCurve();
  147. virtual int rtti() const;
  148. void setPaintAttribute( PaintAttribute, bool on = true );
  149. bool testPaintAttribute( PaintAttribute ) const;
  150. void setLegendAttribute( LegendAttribute, bool on = true );
  151. bool testLegendAttribute( LegendAttribute ) const;
  152. #ifndef QWT_NO_COMPAT
  153. void setRawSamples( const double *xData, const double *yData, int size );
  154. void setSamples( const double *xData, const double *yData, int size );
  155. void setSamples( const QVector<double> &xData, const QVector<double> &yData );
  156. #endif
  157. void setSamples( const QVector<QPointF> & );
  158. int closestPoint( const QPoint &pos, double *dist = NULL ) const;
  159. double minXValue() const;
  160. double maxXValue() const;
  161. double minYValue() const;
  162. double maxYValue() const;
  163. void setCurveAttribute( CurveAttribute, bool on = true );
  164. bool testCurveAttribute( CurveAttribute ) const;
  165. void setPen( const QPen & );
  166. const QPen &pen() const;
  167. void setBrush( const QBrush & );
  168. const QBrush &brush() const;
  169. void setBaseline( double ref );
  170. double baseline() const;
  171. void setStyle( CurveStyle style );
  172. CurveStyle style() const;
  173. void setSymbol( const QwtSymbol *s );
  174. const QwtSymbol *symbol() const;
  175. void setCurveFitter( QwtCurveFitter * );
  176. QwtCurveFitter *curveFitter() const;
  177. virtual void drawSeries( QPainter *,
  178. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  179. const QRectF &canvasRect, int from, int to ) const;
  180. virtual void updateLegend( QwtLegend * ) const;
  181. virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const;
  182. protected:
  183. void init();
  184. virtual void drawCurve( QPainter *p, int style,
  185. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  186. const QRectF &canvasRect, int from, int to ) const;
  187. virtual void drawSymbols( QPainter *p, const QwtSymbol &,
  188. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  189. const QRectF &canvasRect, int from, int to ) const;
  190. void drawLines( QPainter *p,
  191. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  192. const QRectF &canvasRect, int from, int to ) const;
  193. void drawSticks( QPainter *p,
  194. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  195. const QRectF &canvasRect, int from, int to ) const;
  196. void drawDots( QPainter *p,
  197. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  198. const QRectF &canvasRect, int from, int to ) const;
  199. void drawSteps( QPainter *p,
  200. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  201. const QRectF &canvasRect, int from, int to ) const;
  202. virtual void fillCurve( QPainter *,
  203. const QwtScaleMap &, const QwtScaleMap &, QPolygonF & ) const;
  204. void closePolyline( QPainter *,
  205. const QwtScaleMap &, const QwtScaleMap &, QPolygonF & ) const;
  206. private:
  207. class PrivateData;
  208. PrivateData *d_data;
  209. };
  210. //! boundingRect().left()
  211. inline double QwtPlotCurve::minXValue() const
  212. {
  213. return boundingRect().left();
  214. }
  215. //! boundingRect().right()
  216. inline double QwtPlotCurve::maxXValue() const
  217. {
  218. return boundingRect().right();
  219. }
  220. //! boundingRect().top()
  221. inline double QwtPlotCurve::minYValue() const
  222. {
  223. return boundingRect().top();
  224. }
  225. //! boundingRect().bottom()
  226. inline double QwtPlotCurve::maxYValue() const
  227. {
  228. return boundingRect().bottom();
  229. }
  230. #endif