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


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17