Qwt User's Guide 6.0.2

- Main Page
- Related Pages
- Classes

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 {
35 Linear,
36
38 Log10,
39
41 Other
42 };
43
44 QwtScaleTransformation( Type type );
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:
57 QwtScaleTransformation();
58 QwtScaleTransformation &operator=( const QwtScaleTransformation );
59
60 const Type d_type;
61 };
62
64 inline QwtScaleTransformation::Type QwtScaleTransformation::type() const
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
107 static QRectF transform( const QwtScaleMap &,
108 const QwtScaleMap &, const QRectF & );
109 static QRectF invTransform( const QwtScaleMap &,
110 const QwtScaleMap &, const QRectF & );
111
112 static QPointF transform( const QwtScaleMap &,
113 const QwtScaleMap &, const QPointF & );
114 static QPointF invTransform( const QwtScaleMap &,
115 const QwtScaleMap &, const QPointF & );
116
117 bool isInverting() const;
118
119 private:
120 void newFactor();
121
122 double d_s1, d_s2; // scale interval boundaries
123 double d_p1, d_p2; // paint device interval boundaries
124
125 double d_cnv; // conversion factor
126
127 QwtScaleTransformation *d_transformation;
128 };
129
133 inline double QwtScaleMap::s1() const
134 {
135 return d_s1;
136 }
137
141 inline double QwtScaleMap::s2() const
142 {
143 return d_s2;
144 }
145
149 inline double QwtScaleMap::p1() const
150 {
151 return d_p1;
152 }
153
157 inline double QwtScaleMap::p2() const
158 {
159 return d_p2;
160 }
161
165 inline double QwtScaleMap::pDist() const
166 {
167 return qAbs( d_p2 - d_p1 );
168 }
169
173 inline double QwtScaleMap::sDist() const
174 {
175 return qAbs( d_s2 - d_s1 );
176 }
177
184 inline double QwtScaleMap::transform( double s ) const
185 {
186 // try to inline code from QwtScaleTransformation
187
188 if ( d_transformation->type() == QwtScaleTransformation::Linear )
189 return d_p1 + ( s - d_s1 ) * d_cnv;
190
191 if ( d_transformation->type() == QwtScaleTransformation::Log10 )
192 return d_p1 + log( s / d_s1 ) * d_cnv;
193
194 return d_transformation->xForm( s, d_s1, d_s2, d_p1, d_p2 );
195 }
196
204 inline double QwtScaleMap::invTransform( double p ) const
205 {
206 return d_transformation->invXForm( p, d_p1, d_p2, d_s1, d_s2 );
207 }
208
210 inline bool QwtScaleMap::isInverting() const
211 {
212 return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) );
213 }
214
215 #ifndef QT_NO_DEBUG_STREAM
216 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );
217 #endif
218
219 #endif