qwt_plot_item.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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_legend_itemmanager.h"
  13. #include "qwt_text.h"
  14. #include <qrect.h>
  15. class QString;
  16. class QPainter;
  17. class QWidget;
  18. class QwtPlot;
  19. class QwtLegend;
  20. class QwtScaleMap;
  21. class QwtScaleDiv;
  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 legnd.
  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: public QwtLegendItemManager
  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. Rtti_PlotItem = 0,
  64. Rtti_PlotGrid,
  65. Rtti_PlotScale,
  66. Rtti_PlotMarker,
  67. Rtti_PlotCurve,
  68. Rtti_PlotSpectroCurve,
  69. Rtti_PlotIntervalCurve,
  70. Rtti_PlotHistogram,
  71. Rtti_PlotSpectrogram,
  72. Rtti_PlotSVG,
  73. Rtti_PlotUserItem = 1000
  74. };
  75. /*!
  76. Plot Item Attributes
  77. - Legend\n
  78. The item is represented on the legend.
  79. - AutoScale \n
  80. The boundingRect() of the item is included in the
  81. autoscaling calculation.
  82. \sa setItemAttribute(), testItemAttribute()
  83. */
  84. enum ItemAttribute
  85. {
  86. Legend = 1,
  87. AutoScale = 2
  88. };
  89. //! Render hints
  90. enum RenderHint
  91. {
  92. RenderAntialiased = 1
  93. };
  94. explicit QwtPlotItem( const QwtText &title = QwtText() );
  95. virtual ~QwtPlotItem();
  96. void attach( QwtPlot *plot );
  97. /*!
  98. \brief This method detaches a QwtPlotItem from any QwtPlot it has been
  99. associated with.
  100. detach() is equivalent to calling attach( NULL )
  101. \sa attach( QwtPlot* plot )
  102. */
  103. void detach()
  104. {
  105. attach( NULL );
  106. }
  107. QwtPlot *plot() const;
  108. void setTitle( const QString &title );
  109. void setTitle( const QwtText &title );
  110. const QwtText &title() const;
  111. virtual int rtti() const;
  112. void setItemAttribute( ItemAttribute, bool on = true );
  113. bool testItemAttribute( ItemAttribute ) const;
  114. void setRenderHint( RenderHint, bool on = true );
  115. bool testRenderHint( RenderHint ) const;
  116. double z() const;
  117. void setZ( double z );
  118. void show();
  119. void hide();
  120. virtual void setVisible( bool );
  121. bool isVisible () const;
  122. void setAxes( int xAxis, int yAxis );
  123. void setXAxis( int axis );
  124. int xAxis() const;
  125. void setYAxis( int axis );
  126. int yAxis() const;
  127. virtual void itemChanged();
  128. /*!
  129. \brief Draw the item
  130. \param painter Painter
  131. \param xMap Maps x-values into pixel coordinates.
  132. \param yMap Maps y-values into pixel coordinates.
  133. \param canvasRect Contents rect of the canvas in painter coordinates
  134. */
  135. virtual void draw( QPainter *painter,
  136. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  137. const QRectF &canvasRect ) const = 0;
  138. virtual QRectF boundingRect() const;
  139. virtual void updateLegend( QwtLegend * ) const;
  140. virtual void updateScaleDiv(
  141. const QwtScaleDiv&, const QwtScaleDiv& );
  142. virtual QWidget *legendItem() const;
  143. QRectF scaleRect( const QwtScaleMap &, const QwtScaleMap & ) const;
  144. QRectF paintRect( const QwtScaleMap &, const QwtScaleMap & ) const;
  145. private:
  146. // Disabled copy constructor and operator=
  147. QwtPlotItem( const QwtPlotItem & );
  148. QwtPlotItem &operator=( const QwtPlotItem & );
  149. class PrivateData;
  150. PrivateData *d_data;
  151. };
  152. #endif