qwt_scale_map.cpp
Go to the documentation of this file.
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 #include "qwt_scale_map.h"
11 #include "qwt_math.h"
12 
13 #include <qrect.h>
14 #include <qdebug.h>
15 
22  d_s1( 0.0 ),
23  d_s2( 1.0 ),
24  d_p1( 0.0 ),
25  d_p2( 1.0 ),
26  d_cnv( 1.0 ),
27  d_ts1( 0.0 ),
28  d_transform( NULL )
29 {
30 }
31 
34  d_s1( other.d_s1 ),
35  d_s2( other.d_s2 ),
36  d_p1( other.d_p1 ),
37  d_p2( other.d_p2 ),
38  d_cnv( other.d_cnv ),
39  d_ts1( other.d_ts1 ),
40  d_transform( NULL )
41 {
42  if ( other.d_transform )
43  d_transform = other.d_transform->copy();
44 }
45 
50 {
51  delete d_transform;
52 }
53 
56 {
57  d_s1 = other.d_s1;
58  d_s2 = other.d_s2;
59  d_p1 = other.d_p1;
60  d_p2 = other.d_p2;
61  d_cnv = other.d_cnv;
62  d_ts1 = other.d_ts1;
63 
64  delete d_transform;
65  d_transform = NULL;
66 
67  if ( other.d_transform )
68  d_transform = other.d_transform->copy();
69 
70  return *this;
71 }
72 
77 {
78  if ( transform != d_transform )
79  {
80  delete d_transform;
82  }
83 
85 }
86 
89 {
90  return d_transform;
91 }
92 
100 void QwtScaleMap::setScaleInterval( double s1, double s2 )
101 {
102  d_s1 = s1;
103  d_s2 = s2;
104 
105  if ( d_transform )
106  {
109  }
110 
111  updateFactor();
112 }
113 
119 void QwtScaleMap::setPaintInterval( double p1, double p2 )
120 {
121  d_p1 = p1;
122  d_p2 = p2;
123 
124  updateFactor();
125 }
126 
128 {
129  d_ts1 = d_s1;
130  double ts2 = d_s2;
131 
132  if ( d_transform )
133  {
135  ts2 = d_transform->transform( ts2 );
136  }
137 
138  d_cnv = 1.0;
139  if ( d_ts1 != ts2 )
140  d_cnv = ( d_p2 - d_p1 ) / ( ts2 - d_ts1 );
141 }
142 
154  const QwtScaleMap &yMap, const QRectF &rect )
155 {
156  double x1 = xMap.transform( rect.left() );
157  double x2 = xMap.transform( rect.right() );
158  double y1 = yMap.transform( rect.top() );
159  double y2 = yMap.transform( rect.bottom() );
160 
161  if ( x2 < x1 )
162  qSwap( x1, x2 );
163  if ( y2 < y1 )
164  qSwap( y1, y2 );
165 
166  if ( qwtFuzzyCompare( x1, 0.0, x2 - x1 ) == 0 )
167  x1 = 0.0;
168  if ( qwtFuzzyCompare( x2, 0.0, x2 - x1 ) == 0 )
169  x2 = 0.0;
170  if ( qwtFuzzyCompare( y1, 0.0, y2 - y1 ) == 0 )
171  y1 = 0.0;
172  if ( qwtFuzzyCompare( y2, 0.0, y2 - y1 ) == 0 )
173  y2 = 0.0;
174 
175  return QRectF( x1, y1, x2 - x1 + 1, y2 - y1 + 1 );
176 }
177 
188  const QwtScaleMap &yMap, const QPointF &pos )
189 {
190  return QPointF(
191  xMap.invTransform( pos.x() ),
192  yMap.invTransform( pos.y() )
193  );
194 }
195 
206 QPointF QwtScaleMap::transform( const QwtScaleMap &xMap,
207  const QwtScaleMap &yMap, const QPointF &pos )
208 {
209  return QPointF(
210  xMap.transform( pos.x() ),
211  yMap.transform( pos.y() )
212  );
213 }
214 
225  const QwtScaleMap &yMap, const QRectF &rect )
226 {
227  const double x1 = xMap.invTransform( rect.left() );
228  const double x2 = xMap.invTransform( rect.right() - 1 );
229  const double y1 = yMap.invTransform( rect.top() );
230  const double y2 = yMap.invTransform( rect.bottom() - 1 );
231 
232  const QRectF r( x1, y1, x2 - x1, y2 - y1 );
233  return r.normalized();
234 }
235 
236 #ifndef QT_NO_DEBUG_STREAM
237 
238 QDebug operator<<( QDebug debug, const QwtScaleMap &map )
239 {
240  debug.nospace() << "QwtScaleMap("
241  << map.transformation()
242  << ", s:" << map.s1() << "->" << map.s2()
243  << ", p:" << map.p1() << "->" << map.p2()
244  << ")";
245 
246  return debug.space();
247 }
248 
249 #endif
double p1() const
Definition: qwt_scale_map.h:99
double p2() const
void updateFactor()
int qwtFuzzyCompare(double value1, double value2, double intervalSize)
Compare 2 values, relative to an interval.
Definition: qwt_math.h:166
double s1() const
Definition: qwt_scale_map.h:83
QwtTransform * d_transform
Definition: qwt_scale_map.h:77
double d_cnv
Definition: qwt_scale_map.h:74
virtual QwtTransform * copy() const =0
Virtualized copy operation.
QDebug operator<<(QDebug debug, const QwtScaleMap &map)
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
virtual double bounded(double value) const
double s2() const
Definition: qwt_scale_map.h:91
QwtScaleMap & operator=(const QwtScaleMap &)
Assignment operator.
void setTransformation(QwtTransform *)
A transformation between coordinate systems.
Definition: qwt_transform.h:35
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
const QwtTransform * transformation() const
Get the transformation.
A scale map.
Definition: qwt_scale_map.h:26
double invTransform(double p) const
double d_ts1
Definition: qwt_scale_map.h:75
double transform(double s) const
QwtScaleMap()
Constructor.
virtual double transform(double value) const =0


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10