Qwt User's Guide: qwt_scale_map.h Source File

Qwt User's Guide 5.2.3

- 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
19 class QWT_EXPORT QwtScaleTransformation
20 {
21 public:
22 enum Type
23 {
24 Linear,
25 Log10,
26
27 Other
28 };
29
30 QwtScaleTransformation(Type type);
31 virtual ~QwtScaleTransformation();
32
33 virtual double xForm(double x, double s1, double s2,
34 double p1, double p2) const;
35 virtual double invXForm(double x, double p1, double p2,
36 double s1, double s2) const;
37
38 Type type() const;
39
40 virtual QwtScaleTransformation *copy() const;
41
42 private:
43 QwtScaleTransformation();
44 QwtScaleTransformation &operator=( const QwtScaleTransformation);
45
46 const Type d_type;
47 };
48
50 inline QwtScaleTransformation::Type QwtScaleTransformation::type() const
51 {
52 return d_type;
53 }
54
61 class QWT_EXPORT QwtScaleMap
62 {
63 public:
64 QwtScaleMap();
65 QwtScaleMap(const QwtScaleMap&);
66
67 ~QwtScaleMap();
68
69 QwtScaleMap &operator=(const QwtScaleMap &);
70
71 void setTransformation(QwtScaleTransformation * );
72 const QwtScaleTransformation *transformation() const;
73
74 void setPaintInterval(int p1, int p2);
75 void setPaintXInterval(double p1, double p2);
76 void setScaleInterval(double s1, double s2);
77
78 int transform(double x) const;
79 double invTransform(double i) const;
80
81 double xTransform(double x) const;
82
83 double p1() const;
84 double p2() const;
85
86 double s1() const;
87 double s2() const;
88
89 double pDist() const;
90 double sDist() const;
91
92 QT_STATIC_CONST double LogMin;
93 QT_STATIC_CONST double LogMax;
94
95 private:
96 void newFactor();
97
98 double d_s1, d_s2; // scale interval boundaries
99 double d_p1, d_p2; // paint device interval boundaries
100
101 double d_cnv; // conversion factor
102
103 QwtScaleTransformation *d_transformation;
104 };
105
109 inline double QwtScaleMap::s1() const
110 {
111 return d_s1;
112 }
113
117 inline double QwtScaleMap::s2() const
118 {
119 return d_s2;
120 }
121
125 inline double QwtScaleMap::p1() const
126 {
127 return d_p1;
128 }
129
133 inline double QwtScaleMap::p2() const
134 {
135 return d_p2;
136 }
137
141 inline double QwtScaleMap::pDist() const
142 {
143 return qwtAbs(d_p2 - d_p1);
144 }
145
149 inline double QwtScaleMap::sDist() const
150 {
151 return qwtAbs(d_s2 - d_s1);
152 }
153
160 inline double QwtScaleMap::xTransform(double s) const
161 {
162 // try to inline code from QwtScaleTransformation
163
164 if ( d_transformation->type() == QwtScaleTransformation::Linear )
165 return d_p1 + (s - d_s1) * d_cnv;
166
167 if ( d_transformation->type() == QwtScaleTransformation::Log10 )
168 return d_p1 + log(s / d_s1) * d_cnv;
169
170 return d_transformation->xForm(s, d_s1, d_s2, d_p1, d_p2 );
171 }
172
180 inline double QwtScaleMap::invTransform(double p) const
181 {
182 return d_transformation->invXForm(p, d_p1, d_p2, d_s1, d_s2 );
183 }
184
193 inline int QwtScaleMap::transform(double s) const
194 {
195 return qRound(xTransform(s));
196 }
197
198 #endif