qwt_scale_map.cpp
Go to the documentation of this file.
1 /******************************************************************************
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  : m_s1( 0.0 )
23  , m_s2( 1.0 )
24  , m_p1( 0.0 )
25  , m_p2( 1.0 )
26  , m_cnv( 1.0 )
27  , m_ts1( 0.0 )
28  , m_transform( NULL )
29 {
30 }
31 
34  : m_s1( other.m_s1 )
35  , m_s2( other.m_s2 )
36  , m_p1( other.m_p1 )
37  , m_p2( other.m_p2 )
38  , m_cnv( other.m_cnv )
39  , m_ts1( other.m_ts1 )
40  , m_transform( NULL )
41 {
42  if ( other.m_transform )
43  m_transform = other.m_transform->copy();
44 }
45 
50 {
51  delete m_transform;
52 }
53 
56 {
57  m_s1 = other.m_s1;
58  m_s2 = other.m_s2;
59  m_p1 = other.m_p1;
60  m_p2 = other.m_p2;
61  m_cnv = other.m_cnv;
62  m_ts1 = other.m_ts1;
63 
64  delete m_transform;
65  m_transform = NULL;
66 
67  if ( other.m_transform )
68  m_transform = other.m_transform->copy();
69 
70  return *this;
71 }
72 
77 {
78  if ( transform != m_transform )
79  {
80  delete m_transform;
82  }
83 
85 }
86 
89 {
90  return m_transform;
91 }
92 
100 void QwtScaleMap::setScaleInterval( double s1, double s2 )
101 {
102  m_s1 = s1;
103  m_s2 = s2;
104 
105  if ( m_transform )
106  {
109  }
110 
111  updateFactor();
112 }
113 
119 void QwtScaleMap::setPaintInterval( double p1, double p2 )
120 {
121  m_p1 = p1;
122  m_p2 = p2;
123 
124  updateFactor();
125 }
126 
128 {
129  m_ts1 = m_s1;
130  double ts2 = m_s2;
131 
132  if ( m_transform )
133  {
135  ts2 = m_transform->transform( ts2 );
136  }
137 
138  m_cnv = 1.0;
139  if ( m_ts1 != ts2 )
140  m_cnv = ( m_p2 - m_p1 ) / ( ts2 - m_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
QwtTransform::copy
virtual QwtTransform * copy() const =0
Virtualized copy operation.
QwtScaleMap::m_cnv
double m_cnv
Definition: qwt_scale_map.h:74
QwtScaleMap::invTransform
double invTransform(double p) const
Definition: qwt_scale_map.h:154
QwtTransform::transform
virtual double transform(double value) const =0
QwtTransform
A transformation between coordinate systems.
Definition: qwt_transform.h:35
qwtFuzzyCompare
int qwtFuzzyCompare(double value1, double value2, double intervalSize)
Compare 2 values, relative to an interval.
Definition: qwt_math.h:170
QwtScaleMap::s2
double s2() const
Definition: qwt_scale_map.h:91
QwtScaleMap::s1
double s1() const
Definition: qwt_scale_map.h:83
qwt_math.h
QwtScaleMap::p1
double p1() const
Definition: qwt_scale_map.h:99
QwtScaleMap::operator=
QwtScaleMap & operator=(const QwtScaleMap &)
Assignment operator.
Definition: qwt_scale_map.cpp:55
QwtScaleMap::setTransformation
void setTransformation(QwtTransform *)
Definition: qwt_scale_map.cpp:76
QwtScaleMap::m_transform
QwtTransform * m_transform
Definition: qwt_scale_map.h:77
qwt_scale_map.h
range_format::map
@ map
QwtScaleMap::m_ts1
double m_ts1
Definition: qwt_scale_map.h:75
operator<<
QDebug operator<<(QDebug debug, const QwtScaleMap &map)
Definition: qwt_scale_map.cpp:238
QwtScaleMap::setPaintInterval
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
Definition: qwt_scale_map.cpp:119
QwtScaleMap::m_s1
double m_s1
Definition: qwt_scale_map.h:71
QwtScaleMap::QwtScaleMap
QwtScaleMap()
Constructor.
Definition: qwt_scale_map.cpp:21
QwtScaleMap::transform
double transform(double s) const
Definition: qwt_scale_map.h:137
QwtScaleMap
A scale map.
Definition: qwt_scale_map.h:26
debug
#define debug()
Definition: mqtt_client.cpp:14
QwtTransform::bounded
virtual double bounded(double value) const
Definition: qwt_transform.cpp:33
QwtScaleMap::p2
double p2() const
Definition: qwt_scale_map.h:107
QwtScaleMap::m_s2
double m_s2
Definition: qwt_scale_map.h:71
QwtScaleMap::setScaleInterval
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
Definition: qwt_scale_map.cpp:100
QwtScaleMap::~QwtScaleMap
~QwtScaleMap()
Definition: qwt_scale_map.cpp:49
QwtScaleMap::updateFactor
void updateFactor()
Definition: qwt_scale_map.cpp:127
QwtScaleMap::m_p1
double m_p1
Definition: qwt_scale_map.h:72
QwtScaleMap::m_p2
double m_p2
Definition: qwt_scale_map.h:72
QwtScaleMap::transformation
const QwtTransform * transformation() const
Get the transformation.
Definition: qwt_scale_map.cpp:88


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46