qwt_plot.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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_H
  10. #define QWT_PLOT_H
  11. #include "qwt_global.h"
  12. #include "qwt_text.h"
  13. #include "qwt_plot_dict.h"
  14. #include "qwt_scale_map.h"
  15. #include <qframe.h>
  16. class QwtPlotLayout;
  17. class QwtLegend;
  18. class QwtScaleWidget;
  19. class QwtScaleEngine;
  20. class QwtScaleDiv;
  21. class QwtScaleDraw;
  22. class QwtTextLabel;
  23. class QwtPlotCanvas;
  24. /*!
  25. \brief A 2-D plotting widget
  26. QwtPlot is a widget for plotting two-dimensional graphs.
  27. An unlimited number of plot items can be displayed on
  28. its canvas. Plot items might be curves (QwtPlotCurve), markers
  29. (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived
  30. from QwtPlotItem.
  31. A plot can have up to four axes, with each plot item attached to an x- and
  32. a y axis. The scales at the axes can be explicitely set (QwtScaleDiv), or
  33. are calculated from the plot items, using algorithms (QwtScaleEngine) which
  34. can be configured separately for each axis.
  35. \image html plot.png
  36. \par Example
  37. The following example shows (schematically) the most simple
  38. way to use QwtPlot. By default, only the left and bottom axes are
  39. visible and their scales are computed automatically.
  40. \verbatim
  41. #include <qwt_plot.h>
  42. #include <qwt_plot_curve.h>
  43. QwtPlot *myPlot = new QwtPlot("Two Curves", parent);
  44. // add curves
  45. QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
  46. QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
  47. // copy the data into the curves
  48. curve1->setData(...);
  49. curve2->setData(...);
  50. curve1->attach(myPlot);
  51. curve2->attach(myPlot);
  52. // finally, refresh the plot
  53. myPlot->replot();
  54. \endverbatim
  55. */
  56. class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict
  57. {
  58. Q_OBJECT
  59. Q_PROPERTY( QString propertiesDocument
  60. READ grabProperties WRITE applyProperties )
  61. public:
  62. /*!
  63. Axis index
  64. - yLeft\n
  65. - yRight\n
  66. - xBottom\n
  67. - xTop\n
  68. */
  69. enum Axis
  70. {
  71. yLeft,
  72. yRight,
  73. xBottom,
  74. xTop,
  75. axisCnt
  76. };
  77. /*!
  78. Position of the legend, relative to the canvas.
  79. - LeftLegend\n
  80. The legend will be left from the yLeft axis.
  81. - RightLegend\n
  82. The legend will be right from the yLeft axis.
  83. - BottomLegend\n
  84. The legend will be right below the xBottom axis.
  85. - TopLegend\n
  86. The legend will be between xTop axis and the title.
  87. - ExternalLegend\n
  88. External means that only the content of the legend
  89. will be handled by QwtPlot, but not its geometry.
  90. This might be interesting if an application wants to
  91. have a legend in an external window ( or on the canvas ).
  92. \note In case of ExternalLegend, the legend is not
  93. handled by QwtPlotRenderer
  94. \sa insertLegend()
  95. */
  96. enum LegendPosition
  97. {
  98. LeftLegend,
  99. RightLegend,
  100. BottomLegend,
  101. TopLegend,
  102. ExternalLegend
  103. };
  104. explicit QwtPlot( QWidget * = NULL );
  105. explicit QwtPlot( const QwtText &title, QWidget *p = NULL );
  106. virtual ~QwtPlot();
  107. void applyProperties( const QString & );
  108. QString grabProperties() const;
  109. void setAutoReplot( bool tf = true );
  110. bool autoReplot() const;
  111. // Layout
  112. QwtPlotLayout *plotLayout();
  113. const QwtPlotLayout *plotLayout() const;
  114. void setMargin( int margin );
  115. int margin() const;
  116. // Title
  117. void setTitle( const QString & );
  118. void setTitle( const QwtText &t );
  119. QwtText title() const;
  120. QwtTextLabel *titleLabel();
  121. const QwtTextLabel *titleLabel() const;
  122. // Canvas
  123. QwtPlotCanvas *canvas();
  124. const QwtPlotCanvas *canvas() const;
  125. void setCanvasBackground ( const QColor &c );
  126. const QColor& canvasBackground() const;
  127. void setCanvasLineWidth( int w );
  128. int canvasLineWidth() const;
  129. virtual QwtScaleMap canvasMap( int axisId ) const;
  130. double invTransform( int axisId, int pos ) const;
  131. double transform( int axisId, double value ) const;
  132. // Axes
  133. QwtScaleEngine *axisScaleEngine( int axisId );
  134. const QwtScaleEngine *axisScaleEngine( int axisId ) const;
  135. void setAxisScaleEngine( int axisId, QwtScaleEngine * );
  136. void setAxisAutoScale( int axisId );
  137. bool axisAutoScale( int axisId ) const;
  138. void enableAxis( int axisId, bool tf = true );
  139. bool axisEnabled( int axisId ) const;
  140. void setAxisFont( int axisId, const QFont &f );
  141. QFont axisFont( int axisId ) const;
  142. void setAxisScale( int axisId, double min, double max, double step = 0 );
  143. void setAxisScaleDiv( int axisId, const QwtScaleDiv & );
  144. void setAxisScaleDraw( int axisId, QwtScaleDraw * );
  145. double axisStepSize( int axisId ) const;
  146. const QwtScaleDiv *axisScaleDiv( int axisId ) const;
  147. QwtScaleDiv *axisScaleDiv( int axisId );
  148. const QwtScaleDraw *axisScaleDraw( int axisId ) const;
  149. QwtScaleDraw *axisScaleDraw( int axisId );
  150. const QwtScaleWidget *axisWidget( int axisId ) const;
  151. QwtScaleWidget *axisWidget( int axisId );
  152. void setAxisLabelAlignment( int axisId, Qt::Alignment );
  153. void setAxisLabelRotation( int axisId, double rotation );
  154. void setAxisTitle( int axisId, const QString & );
  155. void setAxisTitle( int axisId, const QwtText & );
  156. QwtText axisTitle( int axisId ) const;
  157. void setAxisMaxMinor( int axisId, int maxMinor );
  158. int axisMaxMinor( int axisId ) const;
  159. void setAxisMaxMajor( int axisId, int maxMajor );
  160. int axisMaxMajor( int axisId ) const;
  161. // Legend
  162. void insertLegend( QwtLegend *, LegendPosition = QwtPlot::RightLegend,
  163. double ratio = -1.0 );
  164. QwtLegend *legend();
  165. const QwtLegend *legend() const;
  166. // Misc
  167. virtual void polish();
  168. virtual QSize sizeHint() const;
  169. virtual QSize minimumSizeHint() const;
  170. virtual void updateLayout();
  171. virtual void drawCanvas( QPainter * );
  172. void updateAxes();
  173. virtual bool event( QEvent * );
  174. virtual void drawItems( QPainter *, const QRectF &,
  175. const QwtScaleMap maps[axisCnt] ) const;
  176. Q_SIGNALS:
  177. /*!
  178. A signal which is emitted when the user has clicked on
  179. a legend item, which is in QwtLegend::ClickableItem mode.
  180. \param plotItem Corresponding plot item of the
  181. selected legend item
  182. \note clicks are disabled as default
  183. \sa QwtLegend::setItemMode(), QwtLegend::itemMode()
  184. */
  185. void legendClicked( QwtPlotItem *plotItem );
  186. /*!
  187. A signal which is emitted when the user has clicked on
  188. a legend item, which is in QwtLegend::CheckableItem mode
  189. \param plotItem Corresponding plot item of the
  190. selected legend item
  191. \param on True when the legen item is checked
  192. \note clicks are disabled as default
  193. \sa QwtLegend::setItemMode(), QwtLegend::itemMode()
  194. */
  195. void legendChecked( QwtPlotItem *plotItem, bool on );
  196. public Q_SLOTS:
  197. virtual void replot();
  198. void autoRefresh();
  199. protected Q_SLOTS:
  200. virtual void legendItemClicked();
  201. virtual void legendItemChecked( bool );
  202. protected:
  203. static bool axisValid( int axisId );
  204. virtual void updateTabOrder();
  205. virtual void resizeEvent( QResizeEvent *e );
  206. private:
  207. void initAxesData();
  208. void deleteAxesData();
  209. void updateScaleDiv();
  210. void initPlot( const QwtText &title );
  211. class AxisData;
  212. AxisData *d_axisData[axisCnt];
  213. class PrivateData;
  214. PrivateData *d_data;
  215. };
  216. #endif