qwt_polar_grid.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_GRID_H
  9. #define QWT_POLAR_GRID_H
  10. #include "qwt_polar_global.h"
  11. #include "qwt_polar.h"
  12. #include "qwt_polar_item.h"
  13. #include "qwt_polar_plot.h"
  14. class QPainter;
  15. class QPen;
  16. class QwtScaleMap;
  17. class QwtScaleDiv;
  18. class QwtRoundScaleDraw;
  19. class QwtScaleDraw;
  20. /*!
  21. \brief An item which draws scales and grid lines on a polar plot.
  22. The QwtPolarGrid class can be used to draw a coordinate grid.
  23. A coordinate grid consists of major and minor gridlines.
  24. The locations of the gridlines are determined by the azimuth and radial
  25. scale divisions.
  26. QwtPolarGrid is also responsible for drawing the axis representing the
  27. scales. It is possible to display 4 radial and one azimuth axis.
  28. Whenever the scale divisions of the plot widget changes the grid
  29. is synchronized by updateScaleDiv().
  30. \sa QwtPolarPlot, QwtPolar::Axis
  31. */
  32. class QWT_POLAR_EXPORT QwtPolarGrid: public QwtPolarItem
  33. {
  34. public:
  35. /*!
  36. Mysterious flags trying to avoid conflicts, when painting the
  37. scales and grid lines.
  38. The default setting enables all flags.
  39. \sa setDisplayFlag(), testDisplayFlag()
  40. */
  41. enum DisplayFlag
  42. {
  43. /*!
  44. Try to avoid situations, where the label of the origin is
  45. painted over another axis.
  46. */
  47. SmartOriginLabel = 1,
  48. /*!
  49. Often the outermost tick of the radial scale is close to the
  50. canvas border. With HideMaxRadiusLabel enabled it is not painted.
  51. */
  52. HideMaxRadiusLabel = 2,
  53. /*!
  54. The tick labels of the radial scales might be hard to read, when
  55. they are painted on top of the radial grid lines ( or on top
  56. of a curve/spectrogram ). When ClipAxisBackground the bounding rect
  57. of each label is added to the clip region.
  58. */
  59. ClipAxisBackground = 4,
  60. /*!
  61. Don't paint the backbone of the radial axes, when they are very close
  62. to a line of the azimuth grid.
  63. */
  64. SmartScaleDraw = 8,
  65. /*!
  66. All grid lines are clipped against the plot area before being painted.
  67. When the plot is zoomed in this will have an significant impact
  68. on the performance of the painting cde.
  69. */
  70. ClipGridLines = 16
  71. };
  72. //! Display flags
  73. typedef QFlags<DisplayFlag> DisplayFlags;
  74. /*!
  75. \brief Grid attributes
  76. \sa setGridAttributes(), testGridAttributes()
  77. */
  78. enum GridAttribute
  79. {
  80. /*!
  81. When AutoScaling is enabled, the radial axes will be adjusted
  82. to the interval, that is currently visible on the canvas plot.
  83. */
  84. AutoScaling = 0x01
  85. };
  86. //! Grid attributes
  87. typedef QFlags<GridAttribute> GridAttributes;
  88. explicit QwtPolarGrid();
  89. virtual ~QwtPolarGrid();
  90. virtual int rtti() const;
  91. void setDisplayFlag( DisplayFlag, bool on = true );
  92. bool testDisplayFlag( DisplayFlag ) const;
  93. void setGridAttribute( GridAttribute, bool on = true );
  94. bool testGridAttribute( GridAttribute ) const;
  95. void showGrid( int scaleId, bool show = true );
  96. bool isGridVisible( int scaleId ) const;
  97. void showMinorGrid( int scaleId, bool show = true );
  98. bool isMinorGridVisible( int scaleId ) const;
  99. void showAxis( int axisId, bool show = true );
  100. bool isAxisVisible( int axisId ) const;
  101. void setPen( const QPen &p );
  102. void setFont( const QFont & );
  103. void setMajorGridPen( const QPen &p );
  104. void setMajorGridPen( int scaleId, const QPen &p );
  105. QPen majorGridPen( int scaleId ) const;
  106. void setMinorGridPen( const QPen &p );
  107. void setMinorGridPen( int scaleId, const QPen &p );
  108. QPen minorGridPen( int scaleId ) const;
  109. void setAxisPen( int axisId, const QPen &p );
  110. QPen axisPen( int axisId ) const;
  111. void setAxisFont( int axisId, const QFont &p );
  112. QFont axisFont( int axisId ) const;
  113. void setScaleDraw( int axisId, QwtScaleDraw * );
  114. const QwtScaleDraw *scaleDraw( int axisId ) const;
  115. QwtScaleDraw *scaleDraw( int axisId );
  116. void setAzimuthScaleDraw( QwtRoundScaleDraw * );
  117. const QwtRoundScaleDraw *azimuthScaleDraw() const;
  118. QwtRoundScaleDraw *azimuthScaleDraw();
  119. virtual void draw( QPainter *p,
  120. const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
  121. const QPointF &pole, double radius,
  122. const QRectF &rect ) const;
  123. virtual void updateScaleDiv( const QwtScaleDiv &azimuthMap,
  124. const QwtScaleDiv &radialMap, const QwtInterval & );
  125. virtual int marginHint() const;
  126. protected:
  127. void drawRays( QPainter *, const QRectF &,
  128. const QPointF &pole, double radius,
  129. const QwtScaleMap &azimuthMap, const QList<double> & ) const;
  130. void drawCircles( QPainter *, const QRectF &,
  131. const QPointF &pole, const QwtScaleMap &radialMap,
  132. const QList<double> & ) const;
  133. void drawAxis( QPainter *, int axisId ) const;
  134. private:
  135. void updateScaleDraws(
  136. const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
  137. const QPointF &pole, const double radius ) const;
  138. private:
  139. class GridData;
  140. class AxisData;
  141. class PrivateData;
  142. PrivateData *d_data;
  143. };
  144. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPolarGrid::DisplayFlags )
  145. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPolarGrid::GridAttributes )
  146. #endif