Qwt User's Guide  6.1.3
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_transform.h"
15 #include <qrect.h>
16 
17 #ifndef QT_NO_DEBUG_STREAM
18 #include <qdebug.h>
19 #endif
20 
21 class QRectF;
22 
30 class QWT_EXPORT QwtScaleMap
31 {
32 public:
33  QwtScaleMap();
34  QwtScaleMap( const QwtScaleMap& );
35 
36  ~QwtScaleMap();
37 
38  QwtScaleMap &operator=( const QwtScaleMap & );
39 
40  void setTransformation( QwtTransform * );
41  const QwtTransform *transformation() const;
42 
43  void setPaintInterval( double p1, double p2 );
44  void setScaleInterval( double s1, double s2 );
45 
46  double transform( double s ) const;
47  double invTransform( double p ) const;
48 
49  double p1() const;
50  double p2() const;
51 
52  double s1() const;
53  double s2() const;
54 
55  double pDist() const;
56  double sDist() const;
57 
58  static QRectF transform( const QwtScaleMap &,
59  const QwtScaleMap &, const QRectF & );
60  static QRectF invTransform( const QwtScaleMap &,
61  const QwtScaleMap &, const QRectF & );
62 
63  static QPointF transform( const QwtScaleMap &,
64  const QwtScaleMap &, const QPointF & );
65  static QPointF invTransform( const QwtScaleMap &,
66  const QwtScaleMap &, const QPointF & );
67 
68  bool isInverting() const;
69 
70 private:
71  void updateFactor();
72 
73  double d_s1, d_s2; // scale interval boundaries
74  double d_p1, d_p2; // paint device interval boundaries
75 
76  double d_cnv; // conversion factor
77  double d_ts1;
78 
79  QwtTransform *d_transform;
80 };
81 
85 inline double QwtScaleMap::s1() const
86 {
87  return d_s1;
88 }
89 
93 inline double QwtScaleMap::s2() const
94 {
95  return d_s2;
96 }
97 
101 inline double QwtScaleMap::p1() const
102 {
103  return d_p1;
104 }
105 
109 inline double QwtScaleMap::p2() const
110 {
111  return d_p2;
112 }
113 
117 inline double QwtScaleMap::pDist() const
118 {
119  return qAbs( d_p2 - d_p1 );
120 }
121 
125 inline double QwtScaleMap::sDist() const
126 {
127  return qAbs( d_s2 - d_s1 );
128 }
129 
139 inline double QwtScaleMap::transform( double s ) const
140 {
141  if ( d_transform )
142  s = d_transform->transform( s );
143 
144  return d_p1 + ( s - d_ts1 ) * d_cnv;
145 }
146 
156 inline double QwtScaleMap::invTransform( double p ) const
157 {
158  double s = d_ts1 + ( p - d_p1 ) / d_cnv;
159  if ( d_transform )
160  s = d_transform->invTransform( s );
161 
162  return s;
163 }
164 
166 inline bool QwtScaleMap::isInverting() const
167 {
168  return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) );
169 }
170 
171 #ifndef QT_NO_DEBUG_STREAM
172 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );
173 #endif
174 
175 #endif
A transformation between coordinate systems.
Definition: qwt_transform.h:35
double s2() const
Definition: qwt_scale_map.h:93
double pDist() const
Definition: qwt_scale_map.h:117
A scale map.
Definition: qwt_scale_map.h:30
double s1() const
Definition: qwt_scale_map.h:85
bool isInverting() const
Definition: qwt_scale_map.h:166
double p1() const
Definition: qwt_scale_map.h:101
double p2() const
Definition: qwt_scale_map.h:109
double invTransform(double p) const
Definition: qwt_scale_map.h:156
double transform(double s) const
Definition: qwt_scale_map.h:139
double sDist() const
Definition: qwt_scale_map.h:125