qwt_scale_map.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_MAP_H
  10. #define QWT_SCALE_MAP_H
  11. #include "qwt_global.h"
  12. #include "qwt_transform.h"
  13. #include <qrect.h>
  14. #ifndef QT_NO_DEBUG_STREAM
  15. #include <qdebug.h>
  16. #endif
  17. class QRectF;
  18. /*!
  19. \brief A scale map
  20. QwtScaleMap offers transformations from the coordinate system
  21. of a scale into the linear coordinate system of a paint device
  22. and vice versa.
  23. */
  24. class QWT_EXPORT QwtScaleMap
  25. {
  26. public:
  27. QwtScaleMap();
  28. QwtScaleMap( const QwtScaleMap& );
  29. ~QwtScaleMap();
  30. QwtScaleMap &operator=( const QwtScaleMap & );
  31. void setTransformation( QwtTransform * );
  32. const QwtTransform *transformation() const;
  33. void setPaintInterval( double p1, double p2 );
  34. void setScaleInterval( double s1, double s2 );
  35. double transform( double s ) const;
  36. double invTransform( double p ) const;
  37. double p1() const;
  38. double p2() const;
  39. double s1() const;
  40. double s2() const;
  41. double pDist() const;
  42. double sDist() const;
  43. static QRectF transform( const QwtScaleMap &,
  44. const QwtScaleMap &, const QRectF & );
  45. static QRectF invTransform( const QwtScaleMap &,
  46. const QwtScaleMap &, const QRectF & );
  47. static QPointF transform( const QwtScaleMap &,
  48. const QwtScaleMap &, const QPointF & );
  49. static QPointF invTransform( const QwtScaleMap &,
  50. const QwtScaleMap &, const QPointF & );
  51. bool isInverting() const;
  52. private:
  53. void updateFactor();
  54. double d_s1, d_s2; // scale interval boundaries
  55. double d_p1, d_p2; // paint device interval boundaries
  56. double d_cnv; // conversion factor
  57. double d_ts1;
  58. QwtTransform *d_transform;
  59. };
  60. /*!
  61. \return First border of the scale interval
  62. */
  63. inline double QwtScaleMap::s1() const
  64. {
  65. return d_s1;
  66. }
  67. /*!
  68. \return Second border of the scale interval
  69. */
  70. inline double QwtScaleMap::s2() const
  71. {
  72. return d_s2;
  73. }
  74. /*!
  75. \return First border of the paint interval
  76. */
  77. inline double QwtScaleMap::p1() const
  78. {
  79. return d_p1;
  80. }
  81. /*!
  82. \return Second border of the paint interval
  83. */
  84. inline double QwtScaleMap::p2() const
  85. {
  86. return d_p2;
  87. }
  88. /*!
  89. \return qwtAbs(p2() - p1())
  90. */
  91. inline double QwtScaleMap::pDist() const
  92. {
  93. return qAbs( d_p2 - d_p1 );
  94. }
  95. /*!
  96. \return qwtAbs(s2() - s1())
  97. */
  98. inline double QwtScaleMap::sDist() const
  99. {
  100. return qAbs( d_s2 - d_s1 );
  101. }
  102. /*!
  103. Transform a point related to the scale interval into an point
  104. related to the interval of the paint device
  105. \param s Value relative to the coordinates of the scale
  106. \return Transformed value
  107. \sa invTransform()
  108. */
  109. inline double QwtScaleMap::transform( double s ) const
  110. {
  111. if ( d_transform )
  112. s = d_transform->transform( s );
  113. return d_p1 + ( s - d_ts1 ) * d_cnv;
  114. }
  115. /*!
  116. Transform an paint device value into a value in the
  117. interval of the scale.
  118. \param p Value relative to the coordinates of the paint device
  119. \return Transformed value
  120. \sa transform()
  121. */
  122. inline double QwtScaleMap::invTransform( double p ) const
  123. {
  124. double s = d_ts1 + ( p - d_p1 ) / d_cnv;
  125. if ( d_transform )
  126. s = d_transform->invTransform( s );
  127. return s;
  128. }
  129. //! \return True, when ( p1() < p2() ) != ( s1() < s2() )
  130. inline bool QwtScaleMap::isInverting() const
  131. {
  132. return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) );
  133. }
  134. #ifndef QT_NO_DEBUG_STREAM
  135. QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );
  136. #endif
  137. #endif