qwt_polar_plot.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  2. * QwtPolar Widget Library
  3. * Copyright (C) 2008 Uwe Rathmann
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the Qwt License, Version 1.0
  7. *****************************************************************************/
  8. #ifndef QWT_POLAR_PLOT_H
  9. #define QWT_POLAR_PLOT_H 1
  10. #include "qwt_polar_global.h"
  11. #include "qwt_polar.h"
  12. #include "qwt_polar_itemdict.h"
  13. #include <qwt_interval.h>
  14. #include <qwt_scale_map.h>
  15. #include <qwt_point_polar.h>
  16. #include <qframe.h>
  17. class QwtRoundScaleDraw;
  18. class QwtScaleEngine;
  19. class QwtScaleDiv;
  20. class QwtTextLabel;
  21. class QwtPolarCanvas;
  22. class QwtPolarLayout;
  23. class QwtAbstractLegend;
  24. /*!
  25. \brief A plotting widget, displaying a polar coordinate system
  26. An unlimited number of plot items can be displayed on
  27. its canvas. Plot items might be curves (QwtPolarCurve), markers
  28. (QwtPolarMarker), the grid (QwtPolarGrid), or anything else derived
  29. from QwtPolarItem.
  30. The coordinate system is defined by a radial and a azimuth scale.
  31. The scales at the axes can be explicitely set (QwtScaleDiv), or
  32. are calculated from the plot items, using algorithms (QwtScaleEngine) which
  33. can be configured separately for each axis. Autoscaling is supported
  34. for the radial scale.
  35. In opposite to QwtPlot the scales might be different from the
  36. view, that is displayed on the canvas. The view can be changed by
  37. zooming - f.e. by using QwtPolarPanner or QwtPolarMaginfier.
  38. */
  39. class QWT_POLAR_EXPORT QwtPolarPlot: public QFrame, public QwtPolarItemDict
  40. {
  41. Q_OBJECT
  42. Q_PROPERTY( QBrush plotBackground READ plotBackground WRITE setPlotBackground )
  43. Q_PROPERTY( double azimuthOrigin READ azimuthOrigin WRITE setAzimuthOrigin )
  44. public:
  45. /*!
  46. Position of the legend, relative to the canvas.
  47. \sa insertLegend()
  48. */
  49. enum LegendPosition
  50. {
  51. //! The legend will be left from the canvas.
  52. LeftLegend,
  53. //! The legend will be right from the canvas.
  54. RightLegend,
  55. //! The legend will be below the canvas.
  56. BottomLegend,
  57. //! The legend will be between canvas and title.
  58. TopLegend,
  59. /*!
  60. External means that only the content of the legend
  61. will be handled by QwtPlot, but not its geometry.
  62. This might be interesting if an application wants to
  63. have a legend in an external window ( or on the canvas ).
  64. \note The legend is not painted by QwtPolarRenderer
  65. */
  66. ExternalLegend
  67. };
  68. explicit QwtPolarPlot( QWidget *parent = NULL );
  69. QwtPolarPlot( const QwtText &title, QWidget *parent = NULL );
  70. virtual ~QwtPolarPlot();
  71. void setTitle( const QString & );
  72. void setTitle( const QwtText & );
  73. QwtText title() const;
  74. QwtTextLabel *titleLabel();
  75. const QwtTextLabel *titleLabel() const;
  76. void setAutoReplot( bool tf = true );
  77. bool autoReplot() const;
  78. void setAutoScale( int scaleId );
  79. bool hasAutoScale( int scaleId ) const;
  80. void setScaleMaxMinor( int scaleId, int maxMinor );
  81. int scaleMaxMinor( int scaleId ) const;
  82. int scaleMaxMajor( int scaleId ) const;
  83. void setScaleMaxMajor( int scaleId, int maxMajor );
  84. QwtScaleEngine *scaleEngine( int scaleId );
  85. const QwtScaleEngine *scaleEngine( int scaleId ) const;
  86. void setScaleEngine( int scaleId, QwtScaleEngine * );
  87. void setScale( int scaleId, double min, double max, double step = 0 );
  88. void setScaleDiv( int scaleId, const QwtScaleDiv & );
  89. const QwtScaleDiv *scaleDiv( int scaleId ) const;
  90. QwtScaleDiv *scaleDiv( int scaleId );
  91. QwtScaleMap scaleMap( int scaleId, double radius ) const;
  92. QwtScaleMap scaleMap( int scaleId ) const;
  93. void updateScale( int scaleId );
  94. double azimuthOrigin() const;
  95. void zoom( const QwtPointPolar&, double factor );
  96. void unzoom();
  97. QwtPointPolar zoomPos() const;
  98. double zoomFactor() const;
  99. // Canvas
  100. QwtPolarCanvas *canvas();
  101. const QwtPolarCanvas *canvas() const;
  102. void setPlotBackground ( const QBrush &c );
  103. const QBrush& plotBackground() const;
  104. virtual void drawCanvas( QPainter *, const QRectF & ) const;
  105. // Legend
  106. void insertLegend( QwtAbstractLegend *,
  107. LegendPosition = RightLegend, double ratio = -1.0 );
  108. QwtAbstractLegend *legend();
  109. const QwtAbstractLegend *legend() const;
  110. void updateLegend();
  111. void updateLegend( const QwtPolarItem * );
  112. // Layout
  113. QwtPolarLayout *plotLayout();
  114. const QwtPolarLayout *plotLayout() const;
  115. QwtInterval visibleInterval() const;
  116. QRectF plotRect() const;
  117. QRectF plotRect( const QRectF & ) const;
  118. int plotMarginHint() const;
  119. virtual QVariant itemToInfo( QwtPolarItem * ) const;
  120. virtual QwtPolarItem *infoToItem( const QVariant & ) const;
  121. Q_SIGNALS:
  122. /*!
  123. A signal indicating, that an item has been attached/detached
  124. \param plotItem Plot item
  125. \param on Attached/Detached
  126. */
  127. void itemAttached( QwtPolarItem *plotItem, bool on );
  128. /*!
  129. A signal with the attributes how to update
  130. the legend entries for a plot item.
  131. \param itemInfo Info about a plot, build from itemToInfo()
  132. \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend()
  133. */
  134. void legendDataChanged( const QVariant &itemInfo,
  135. const QList<QwtLegendData> &data );
  136. /*!
  137. A signal that is emitted, whenever the layout of the plot
  138. has been recalculated.
  139. */
  140. void layoutChanged();
  141. public Q_SLOTS:
  142. virtual void replot();
  143. void autoRefresh();
  144. void setAzimuthOrigin( double );
  145. protected:
  146. virtual bool event( QEvent * );
  147. virtual void resizeEvent( QResizeEvent * );
  148. virtual void updateLayout();
  149. virtual void drawItems( QPainter *painter,
  150. const QwtScaleMap &radialMap, const QwtScaleMap &azimuthMap,
  151. const QPointF &pole, double radius,
  152. const QRectF &canvasRect ) const;
  153. private:
  154. friend class QwtPolarItem;
  155. void attachItem( QwtPolarItem *, bool );
  156. void initPlot( const QwtText & );
  157. class ScaleData;
  158. class PrivateData;
  159. PrivateData *d_data;
  160. };
  161. #endif