source: ntrip/branches/BNC_2.11.0/qwt/qwt_scale_map.h@ 10161

Last change on this file since 10161 was 4271, checked in by mervart, 12 years ago
File size: 5.0 KB
Line 
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
19class QRectF;
20
21/*!
22 \brief A transformation between coordinate systems
23
24 QwtScaleTransformation offers transformations from the coordinate system
25 of a scale into the linear coordinate system of a paint device
26 and vice versa.
27*/
28class QWT_EXPORT QwtScaleTransformation
29{
30public:
31 //! Transformation type
32 enum Type
33 {
34 //! Transformation between 2 linear scales
35 Linear,
36
37 //! Transformation between a linear and a logarithmic ( base 10 ) scale
38 Log10,
39
40 //! Any other type of transformation
41 Other
42 };
43
44 QwtScaleTransformation( Type type );
45 virtual ~QwtScaleTransformation();
46
47 virtual double xForm( double x, double s1, double s2,
48 double p1, double p2 ) const;
49 virtual double invXForm( double x, double p1, double p2,
50 double s1, double s2 ) const;
51
52 Type type() const;
53
54 virtual QwtScaleTransformation *copy() const;
55
56private:
57 QwtScaleTransformation();
58 QwtScaleTransformation &operator=( const QwtScaleTransformation );
59
60 const Type d_type;
61};
62
63//! \return Transformation type
64inline QwtScaleTransformation::Type QwtScaleTransformation::type() const
65{
66 return d_type;
67}
68
69/*!
70 \brief A scale map
71
72 QwtScaleMap offers transformations from the coordinate system
73 of a scale into the linear coordinate system of a paint device
74 and vice versa.
75*/
76class QWT_EXPORT QwtScaleMap
77{
78public:
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
119private:
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
130/*!
131 \return First border of the scale interval
132*/
133inline double QwtScaleMap::s1() const
134{
135 return d_s1;
136}
137
138/*!
139 \return Second border of the scale interval
140*/
141inline double QwtScaleMap::s2() const
142{
143 return d_s2;
144}
145
146/*!
147 \return First border of the paint interval
148*/
149inline double QwtScaleMap::p1() const
150{
151 return d_p1;
152}
153
154/*!
155 \return Second border of the paint interval
156*/
157inline double QwtScaleMap::p2() const
158{
159 return d_p2;
160}
161
162/*!
163 \return qwtAbs(p2() - p1())
164*/
165inline double QwtScaleMap::pDist() const
166{
167 return qAbs( d_p2 - d_p1 );
168}
169
170/*!
171 \return qwtAbs(s2() - s1())
172*/
173inline double QwtScaleMap::sDist() const
174{
175 return qAbs( d_s2 - d_s1 );
176}
177
178/*!
179 Transform a point related to the scale interval into an point
180 related to the interval of the paint device
181
182 \param s Value relative to the coordinates of the scale
183*/
184inline 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
197/*!
198 Transform an paint device value into a value in the
199 interval of the scale.
200
201 \param p Value relative to the coordinates of the paint device
202 \sa transform()
203*/
204inline double QwtScaleMap::invTransform( double p ) const
205{
206 return d_transformation->invXForm( p, d_p1, d_p2, d_s1, d_s2 );
207}
208
209//! \return True, when ( p1() < p2() ) != ( s1() < s2() )
210inline bool QwtScaleMap::isInverting() const
211{
212 return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) );
213}
214
215#ifndef QT_NO_DEBUG_STREAM
216QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );
217#endif
218
219#endif
Note: See TracBrowser for help on using the repository browser.