qwt_plot_item.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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_ITEM_H
  10. #define QWT_PLOT_ITEM_H
  11. #include "qwt_global.h"
  12. #include "qwt_text.h"
  13. #include "qwt_legend_data.h"
  14. #include "qwt_graphic.h"
  15. #include <qrect.h>
  16. #include <qlist.h>
  17. #include <qmetatype.h>
  18. class QPainter;
  19. class QwtScaleMap;
  20. class QwtScaleDiv;
  21. class QwtPlot;
  22. /*!
  23. \brief Base class for items on the plot canvas
  24. A plot item is "something", that can be painted on the plot canvas,
  25. or only affects the scales of the plot widget. They can be categorized as:
  26. - Representator\n
  27. A "Representator" is an item that represents some sort of data
  28. on the plot canvas. The different representator classes are organized
  29. according to the characteristics of the data:
  30. - QwtPlotMarker
  31. Represents a point or a horizontal/vertical coordinate
  32. - QwtPlotCurve
  33. Represents a series of points
  34. - QwtPlotSpectrogram ( QwtPlotRasterItem )
  35. Represents raster data
  36. - ...
  37. - Decorators\n
  38. A "Decorator" is an item, that displays additional information, that
  39. is not related to any data:
  40. - QwtPlotGrid
  41. - QwtPlotScaleItem
  42. - QwtPlotSvgItem
  43. - ...
  44. Depending on the QwtPlotItem::ItemAttribute flags, an item is included
  45. into autoscaling or has an entry on the legend.
  46. Before misusing the existing item classes it might be better to
  47. implement a new type of plot item
  48. ( don't implement a watermark as spectrogram ).
  49. Deriving a new type of QwtPlotItem primarily means to implement
  50. the YourPlotItem::draw() method.
  51. \sa The cpuplot example shows the implementation of additional plot items.
  52. */
  53. class QWT_EXPORT QwtPlotItem
  54. {
  55. public:
  56. /*!
  57. \brief Runtime type information
  58. RttiValues is used to cast plot items, without
  59. having to enable runtime type information of the compiler.
  60. */
  61. enum RttiValues
  62. {
  63. //! Unspecific value, that can be used, when it doesn't matter
  64. Rtti_PlotItem = 0,
  65. //! For QwtPlotGrid
  66. Rtti_PlotGrid,
  67. //! For QwtPlotScaleItem
  68. Rtti_PlotScale,
  69. //! For QwtPlotLegendItem
  70. Rtti_PlotLegend,
  71. //! For QwtPlotMarker
  72. Rtti_PlotMarker,
  73. //! For QwtPlotCurve
  74. Rtti_PlotCurve,
  75. //! For QwtPlotSpectroCurve
  76. Rtti_PlotSpectroCurve,
  77. //! For QwtPlotIntervalCurve
  78. Rtti_PlotIntervalCurve,
  79. //! For QwtPlotHistogram
  80. Rtti_PlotHistogram,
  81. //! For QwtPlotSpectrogram
  82. Rtti_PlotSpectrogram,
  83. //! For QwtPlotSvgItem
  84. Rtti_PlotSVG,
  85. //! For QwtPlotTradingCurve
  86. Rtti_PlotTradingCurve,
  87. //! For QwtPlotBarChart
  88. Rtti_PlotBarChart,
  89. //! For QwtPlotMultiBarChart
  90. Rtti_PlotMultiBarChart,
  91. //! For QwtPlotShapeItem
  92. Rtti_PlotShape,
  93. //! For QwtPlotTextLabel
  94. Rtti_PlotTextLabel,
  95. //! For QwtPlotZoneItem
  96. Rtti_PlotZone,
  97. /*!
  98. Values >= Rtti_PlotUserItem are reserved for plot items
  99. not implemented in the Qwt library.
  100. */
  101. Rtti_PlotUserItem = 1000
  102. };
  103. /*!
  104. \brief Plot Item Attributes
  105. Various aspects of a plot widget depend on the attributes of
  106. the attached plot items. If and how a single plot item
  107. participates in these updates depends on its attributes.
  108. \sa setItemAttribute(), testItemAttribute(), ItemInterest
  109. */
  110. enum ItemAttribute
  111. {
  112. //! The item is represented on the legend.
  113. Legend = 0x01,
  114. /*!
  115. The boundingRect() of the item is included in the
  116. autoscaling calculation as long as its width or height
  117. is >= 0.0.
  118. */
  119. AutoScale = 0x02,
  120. /*!
  121. The item needs extra space to display something outside
  122. its bounding rectangle.
  123. \sa getCanvasMarginHint()
  124. */
  125. Margins = 0x04
  126. };
  127. //! Plot Item Attributes
  128. typedef QFlags<ItemAttribute> ItemAttributes;
  129. /*!
  130. \brief Plot Item Interests
  131. Plot items might depend on the situation of the corresponding
  132. plot widget. By enabling an interest the plot item will be
  133. notified, when the corresponding attribute of the plot widgets
  134. has changed.
  135. \sa setItemAttribute(), testItemAttribute(), ItemInterest
  136. */
  137. enum ItemInterest
  138. {
  139. /*!
  140. The item is interested in updates of the scales
  141. \sa updateScaleDiv()
  142. */
  143. ScaleInterest = 0x01,
  144. /*!
  145. The item is interested in updates of the legend ( of other items )
  146. This flag is intended for items, that want to implement a legend
  147. for displaying entries of other plot item.
  148. \note If the plot item wants to be represented on a legend
  149. enable QwtPlotItem::Legend instead.
  150. \sa updateLegend()
  151. */
  152. LegendInterest = 0x02
  153. };
  154. //! Plot Item Interests
  155. typedef QFlags<ItemInterest> ItemInterests;
  156. //! Render hints
  157. enum RenderHint
  158. {
  159. //! Enable antialiasing
  160. RenderAntialiased = 0x1
  161. };
  162. //! Render hints
  163. typedef QFlags<RenderHint> RenderHints;
  164. explicit QwtPlotItem( const QwtText &title = QwtText() );
  165. virtual ~QwtPlotItem();
  166. void attach( QwtPlot *plot );
  167. void detach();
  168. QwtPlot *plot() const;
  169. void setTitle( const QString &title );
  170. void setTitle( const QwtText &title );
  171. const QwtText &title() const;
  172. virtual int rtti() const;
  173. void setItemAttribute( ItemAttribute, bool on = true );
  174. bool testItemAttribute( ItemAttribute ) const;
  175. void setItemInterest( ItemInterest, bool on = true );
  176. bool testItemInterest( ItemInterest ) const;
  177. void setRenderHint( RenderHint, bool on = true );
  178. bool testRenderHint( RenderHint ) const;
  179. void setRenderThreadCount( uint numThreads );
  180. uint renderThreadCount() const;
  181. void setLegendIconSize( const QSize & );
  182. QSize legendIconSize() const;
  183. double z() const;
  184. void setZ( double z );
  185. void show();
  186. void hide();
  187. virtual void setVisible( bool );
  188. bool isVisible () const;
  189. void setAxes( int xAxis, int yAxis );
  190. void setXAxis( int axis );
  191. int xAxis() const;
  192. void setYAxis( int axis );
  193. int yAxis() const;
  194. virtual void itemChanged();
  195. virtual void legendChanged();
  196. /*!
  197. \brief Draw the item
  198. \param painter Painter
  199. \param xMap Maps x-values into pixel coordinates.
  200. \param yMap Maps y-values into pixel coordinates.
  201. \param canvasRect Contents rect of the canvas in painter coordinates
  202. */
  203. virtual void draw( QPainter *painter,
  204. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  205. const QRectF &canvasRect ) const = 0;
  206. virtual QRectF boundingRect() const;
  207. virtual void getCanvasMarginHint(
  208. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  209. const QRectF &canvasRect,
  210. double &left, double &top, double &right, double &bottom) const;
  211. virtual void updateScaleDiv(
  212. const QwtScaleDiv&, const QwtScaleDiv& );
  213. virtual void updateLegend( const QwtPlotItem *,
  214. const QList<QwtLegendData> & );
  215. QRectF scaleRect( const QwtScaleMap &, const QwtScaleMap & ) const;
  216. QRectF paintRect( const QwtScaleMap &, const QwtScaleMap & ) const;
  217. virtual QList<QwtLegendData> legendData() const;
  218. virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
  219. protected:
  220. QwtGraphic defaultIcon( const QBrush &, const QSizeF & ) const;
  221. private:
  222. // Disabled copy constructor and operator=
  223. QwtPlotItem( const QwtPlotItem & );
  224. QwtPlotItem &operator=( const QwtPlotItem & );
  225. class PrivateData;
  226. PrivateData *d_data;
  227. };
  228. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::ItemAttributes )
  229. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::ItemInterests )
  230. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::RenderHints )
  231. Q_DECLARE_METATYPE( QwtPlotItem * )
  232. #endif