Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_scale_map.cpp
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;
81 m_transform = transform;
82 }
83
84 setScaleInterval( m_s1, m_s2 );
85}
86
89{
90 return m_transform;
91}
92
100void QwtScaleMap::setScaleInterval( double s1, double s2 )
101{
102 m_s1 = s1;
103 m_s2 = s2;
104
105 if ( m_transform )
106 {
107 m_s1 = m_transform->bounded( m_s1 );
108 m_s2 = m_transform->bounded( m_s2 );
109 }
110
111 updateFactor();
112}
113
119void QwtScaleMap::setPaintInterval( double p1, double p2 )
120{
121 m_p1 = p1;
122 m_p2 = p2;
123
124 updateFactor();
125}
126
127void QwtScaleMap::updateFactor()
128{
129 m_ts1 = m_s1;
130 double ts2 = m_s2;
131
132 if ( m_transform )
133 {
134 m_ts1 = m_transform->transform( m_ts1 );
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
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
238QDebug 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
A scale map.
QwtScaleMap & operator=(const QwtScaleMap &)
Assignment operator.
double p1() const
double transform(double s) const
double s1() const
double s2() const
const QwtTransform * transformation() const
Get the transformation.
QwtScaleMap()
Constructor.
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
double invTransform(double p) const
double p2() const
void setTransformation(QwtTransform *)
A transformation between coordinate systems.
virtual QwtTransform * copy() const =0
Virtualized copy operation.
virtual double transform(double value) const =0
virtual double bounded(double value) const