VAT  3.0
Video Analysis Tool
qwt_scale_map.h
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 
10 #ifndef QWT_SCALE_MAP_H
11 #define QWT_SCALE_MAP_H
12 
13 #include "qwt_global.h"
14 #include "qwt_math.h"
15 #ifndef QT_NO_DEBUG_STREAM
16 #include <qdebug.h>
17 #endif
18 
19 class QRectF;
20 
28 class QWT_EXPORT QwtScaleTransformation
29 {
30 public:
32  enum Type
33  {
36 
39 
41  Other
42  };
43 
45  virtual ~QwtScaleTransformation();
46 
47  virtual double xForm( double s, double s1, double s2,
48  double p1, double p2 ) const;
49  virtual double invXForm( double p, double p1, double p2,
50  double s1, double s2 ) const;
51 
52  Type type() const;
53 
54  virtual QwtScaleTransformation *copy() const;
55 
56 private:
59 
60  const Type d_type;
61 };
62 
65 {
66  return d_type;
67 }
68 
76 class QWT_EXPORT QwtScaleMap
77 {
78 public:
79  QwtScaleMap();
80  QwtScaleMap( const QwtScaleMap& );
81 
82  ~QwtScaleMap();
83 
84  QwtScaleMap &operator=( const QwtScaleMap & );
85 
86  void setTransformation( QwtScaleTransformation * );
87  const QwtScaleTransformation *transformation() const;
88 
89  void setPaintInterval( double p1, double p2 );
90  void setScaleInterval( double s1, double s2 );
91 
92  double transform( double s ) const;
93  double invTransform( double p ) const;
94 
95  double p1() const;
96  double p2() const;
97 
98  double s1() const;
99  double s2() const;
100 
101  double pDist() const;
102  double sDist() const;
103 
104  //QT_STATIC_CONST double LogMin;
105  //QT_STATIC_CONST double LogMax;
106  static const double LogMin;
107  static const double LogMax;
108 
109  static QRectF transform( const QwtScaleMap &,
110  const QwtScaleMap &, const QRectF & );
111  static QRectF invTransform( const QwtScaleMap &,
112  const QwtScaleMap &, const QRectF & );
113 
114  static QPointF transform( const QwtScaleMap &,
115  const QwtScaleMap &, const QPointF & );
116  static QPointF invTransform( const QwtScaleMap &,
117  const QwtScaleMap &, const QPointF & );
118 
119  bool isInverting() const;
120 
121 private:
122  void newFactor();
123 
124  double d_s1, d_s2; // scale interval boundaries
125  double d_p1, d_p2; // paint device interval boundaries
126 
127  double d_cnv; // conversion factor
128 
129  QwtScaleTransformation *d_transformation;
130 };
131 
135 inline double QwtScaleMap::s1() const
136 {
137  return d_s1;
138 }
139 
143 inline double QwtScaleMap::s2() const
144 {
145  return d_s2;
146 }
147 
151 inline double QwtScaleMap::p1() const
152 {
153  return d_p1;
154 }
155 
159 inline double QwtScaleMap::p2() const
160 {
161  return d_p2;
162 }
163 
167 inline double QwtScaleMap::pDist() const
168 {
169  return qAbs( d_p2 - d_p1 );
170 }
171 
175 inline double QwtScaleMap::sDist() const
176 {
177  return qAbs( d_s2 - d_s1 );
178 }
179 
186 inline double QwtScaleMap::transform( double s ) const
187 {
188  // try to inline code from QwtScaleTransformation
189 
190  if ( d_transformation->type() == QwtScaleTransformation::Linear )
191  return d_p1 + ( s - d_s1 ) * d_cnv;
192 
193  if ( d_transformation->type() == QwtScaleTransformation::Log10 )
194  return d_p1 + log( s / d_s1 ) * d_cnv;
195 
196  return d_transformation->xForm( s, d_s1, d_s2, d_p1, d_p2 );
197 }
198 
206 inline double QwtScaleMap::invTransform( double p ) const
207 {
208  return d_transformation->invXForm( p, d_p1, d_p2, d_s1, d_s2 );
209 }
210 
212 inline bool QwtScaleMap::isInverting() const
213 {
214  return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) );
215 }
216 
217 #ifndef QT_NO_DEBUG_STREAM
218 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );
219 #endif
220 
221 #endif
double s2() const
Definition: qwt_scale_map.h:143
double pDist() const
Definition: qwt_scale_map.h:167
A scale map.
Definition: qwt_scale_map.h:76
double s1() const
Definition: qwt_scale_map.h:135
bool isInverting() const
Definition: qwt_scale_map.h:212
Type type() const
Definition: qwt_scale_map.h:64
Type
Transformation type.
Definition: qwt_scale_map.h:32
static const double LogMin
Smallest allowed value for logarithmic scales: 1.0e-150.
Definition: qwt_scale_map.h:106
double p1() const
Definition: qwt_scale_map.h:151
Transformation between a linear and a logarithmic ( base 10 ) scale.
Definition: qwt_scale_map.h:38
static const double LogMax
Largest allowed value for logarithmic scales: 1.0e150.
Definition: qwt_scale_map.h:107
double p2() const
Definition: qwt_scale_map.h:159
double invTransform(double p) const
Definition: qwt_scale_map.h:206
double transform(double s) const
Definition: qwt_scale_map.h:186
A transformation between coordinate systems.
Definition: qwt_scale_map.h:28
double sDist() const
Definition: qwt_scale_map.h:175
Transformation between 2 linear scales.
Definition: qwt_scale_map.h:35