qwt_scale_engine.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_SCALE_ENGINE_H
  10. #define QWT_SCALE_ENGINE_H
  11. #include "qwt_global.h"
  12. #include "qwt_scale_div.h"
  13. #include "qwt_interval.h"
  14. class QwtScaleTransformation;
  15. /*!
  16. \brief Arithmetic including a tolerance
  17. */
  18. class QWT_EXPORT QwtScaleArithmetic
  19. {
  20. public:
  21. static double ceilEps( double value, double intervalSize );
  22. static double floorEps( double value, double intervalSize );
  23. static double divideEps( double interval, double steps );
  24. static double ceil125( double x );
  25. static double floor125( double x );
  26. };
  27. /*!
  28. \brief Base class for scale engines.
  29. A scale engine trys to find "reasonable" ranges and step sizes
  30. for scales.
  31. The layout of the scale can be varied with setAttribute().
  32. Qwt offers implementations for logarithmic (log10)
  33. and linear scales. Contributions for other types of scale engines
  34. (date/time, log2 ... ) are welcome.
  35. */
  36. class QWT_EXPORT QwtScaleEngine
  37. {
  38. public:
  39. /*!
  40. - IncludeReference\n
  41. Build a scale which includes the reference() value.
  42. - Symmetric\n
  43. Build a scale which is symmetric to the reference() value.
  44. - Floating\n
  45. The endpoints of the scale are supposed to be equal the
  46. outmost included values plus the specified margins (see setMargins()). If this attribute is *not* set, the endpoints of the scale will
  47. be integer multiples of the step size.
  48. - Inverted\n
  49. Turn the scale upside down.
  50. \sa setAttribute(), testAttribute(), reference(),
  51. lowerMargin(), upperMargin()
  52. */
  53. enum Attribute
  54. {
  55. NoAttribute = 0,
  56. IncludeReference = 1,
  57. Symmetric = 2,
  58. Floating = 4,
  59. Inverted = 8
  60. };
  61. explicit QwtScaleEngine();
  62. virtual ~QwtScaleEngine();
  63. void setAttribute( Attribute, bool on = true );
  64. bool testAttribute( Attribute ) const;
  65. void setAttributes( int );
  66. int attributes() const;
  67. void setReference( double reference );
  68. double reference() const;
  69. void setMargins( double lower, double upper );
  70. double lowerMargin() const;
  71. double upperMargin() const;
  72. /*!
  73. Align and divide an interval
  74. \param maxNumSteps Max. number of steps
  75. \param x1 First limit of the interval (In/Out)
  76. \param x2 Second limit of the interval (In/Out)
  77. \param stepSize Step size (Return value)
  78. */
  79. virtual void autoScale( int maxNumSteps,
  80. double &x1, double &x2, double &stepSize ) const = 0;
  81. /*!
  82. \brief Calculate a scale division
  83. \param x1 First interval limit
  84. \param x2 Second interval limit
  85. \param maxMajSteps Maximum for the number of major steps
  86. \param maxMinSteps Maximum number of minor steps
  87. \param stepSize Step size. If stepSize == 0.0, the scaleEngine
  88. calculates one.
  89. */
  90. virtual QwtScaleDiv divideScale( double x1, double x2,
  91. int maxMajSteps, int maxMinSteps,
  92. double stepSize = 0.0 ) const = 0;
  93. //! \return a transformation
  94. virtual QwtScaleTransformation *transformation() const = 0;
  95. protected:
  96. bool contains( const QwtInterval &, double val ) const;
  97. QList<double> strip( const QList<double>&, const QwtInterval & ) const;
  98. double divideInterval( double interval, int numSteps ) const;
  99. QwtInterval buildInterval( double v ) const;
  100. private:
  101. class PrivateData;
  102. PrivateData *d_data;
  103. };
  104. /*!
  105. \brief A scale engine for linear scales
  106. The step size will fit into the pattern
  107. \f$\left\{ 1,2,5\right\} \cdot 10^{n}\f$, where n is an integer.
  108. */
  109. class QWT_EXPORT QwtLinearScaleEngine: public QwtScaleEngine
  110. {
  111. public:
  112. virtual void autoScale( int maxSteps,
  113. double &x1, double &x2, double &stepSize ) const;
  114. virtual QwtScaleDiv divideScale( double x1, double x2,
  115. int numMajorSteps, int numMinorSteps,
  116. double stepSize = 0.0 ) const;
  117. virtual QwtScaleTransformation *transformation() const;
  118. protected:
  119. QwtInterval align( const QwtInterval&, double stepSize ) const;
  120. void buildTicks(
  121. const QwtInterval &, double stepSize, int maxMinSteps,
  122. QList<double> ticks[QwtScaleDiv::NTickTypes] ) const;
  123. QList<double> buildMajorTicks(
  124. const QwtInterval &interval, double stepSize ) const;
  125. void buildMinorTicks(
  126. const QList<double>& majorTicks,
  127. int maxMinMark, double step,
  128. QList<double> &, QList<double> & ) const;
  129. };
  130. /*!
  131. \brief A scale engine for logarithmic (base 10) scales
  132. The step size is measured in *decades*
  133. and the major step size will be adjusted to fit the pattern
  134. \f$\left\{ 1,2,3,5\right\} \cdot 10^{n}\f$, where n is a natural number
  135. including zero.
  136. \warning the step size as well as the margins are measured in *decades*.
  137. */
  138. class QWT_EXPORT QwtLog10ScaleEngine: public QwtScaleEngine
  139. {
  140. public:
  141. virtual void autoScale( int maxSteps,
  142. double &x1, double &x2, double &stepSize ) const;
  143. virtual QwtScaleDiv divideScale( double x1, double x2,
  144. int numMajorSteps, int numMinorSteps,
  145. double stepSize = 0.0 ) const;
  146. virtual QwtScaleTransformation *transformation() const;
  147. protected:
  148. QwtInterval log10( const QwtInterval& ) const;
  149. QwtInterval pow10( const QwtInterval& ) const;
  150. QwtInterval align( const QwtInterval&, double stepSize ) const;
  151. void buildTicks(
  152. const QwtInterval &, double stepSize, int maxMinSteps,
  153. QList<double> ticks[QwtScaleDiv::NTickTypes] ) const;
  154. QList<double> buildMajorTicks(
  155. const QwtInterval &interval, double stepSize ) const;
  156. QList<double> buildMinorTicks(
  157. const QList<double>& majorTicks,
  158. int maxMinMark, double step ) const;
  159. };
  160. #endif