qwt_scale_map.h 3.69 KB
Newer Older
pixhawk's avatar
pixhawk committed
1
2
3
4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6
7
8
9
10
11
12
13
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_SCALE_MAP_H
#define QWT_SCALE_MAP_H

#include "qwt_global.h"
Bryant's avatar
Bryant committed
14
15
#include "qwt_transform.h"
#include <qrect.h>
pixhawk's avatar
pixhawk committed
16

Bryant's avatar
Bryant committed
17
18
19
#ifndef QT_NO_DEBUG_STREAM
#include <qdebug.h>
#endif
pixhawk's avatar
pixhawk committed
20

Bryant's avatar
Bryant committed
21
class QRectF;
pixhawk's avatar
pixhawk committed
22
23
24
25

/*!
   \brief A scale map

Bryant's avatar
Bryant committed
26
27
28
   QwtScaleMap offers transformations from the coordinate system
   of a scale into the linear coordinate system of a paint device 
   and vice versa.
pixhawk's avatar
pixhawk committed
29
30
31
32
33
*/
class QWT_EXPORT QwtScaleMap
{
public:
    QwtScaleMap();
Bryant's avatar
Bryant committed
34
    QwtScaleMap( const QwtScaleMap& );
pixhawk's avatar
pixhawk committed
35
36
37

    ~QwtScaleMap();

Bryant's avatar
Bryant committed
38
39
40
41
    QwtScaleMap &operator=( const QwtScaleMap & );

    void setTransformation( QwtTransform * );
    const QwtTransform *transformation() const;
pixhawk's avatar
pixhawk committed
42

Bryant's avatar
Bryant committed
43
44
    void setPaintInterval( double p1, double p2 );
    void setScaleInterval( double s1, double s2 );
pixhawk's avatar
pixhawk committed
45

Bryant's avatar
Bryant committed
46
47
    double transform( double s ) const;
    double invTransform( double p ) const;
pixhawk's avatar
pixhawk committed
48

Bryant's avatar
Bryant committed
49
50
    double p1() const;
    double p2() const;
pixhawk's avatar
pixhawk committed
51

Bryant's avatar
Bryant committed
52
53
    double s1() const;
    double s2() const;
pixhawk's avatar
pixhawk committed
54

Bryant's avatar
Bryant committed
55
56
    double pDist() const;
    double sDist() const;
pixhawk's avatar
pixhawk committed
57

Bryant's avatar
Bryant committed
58
59
60
61
    static QRectF transform( const QwtScaleMap &,
        const QwtScaleMap &, const QRectF & );
    static QRectF invTransform( const QwtScaleMap &,
        const QwtScaleMap &, const QRectF & );
pixhawk's avatar
pixhawk committed
62

Bryant's avatar
Bryant committed
63
64
65
66
    static QPointF transform( const QwtScaleMap &,
        const QwtScaleMap &, const QPointF & );
    static QPointF invTransform( const QwtScaleMap &,
        const QwtScaleMap &, const QPointF & );
pixhawk's avatar
pixhawk committed
67

Bryant's avatar
Bryant committed
68
    bool isInverting() const;
pixhawk's avatar
pixhawk committed
69
70

private:
Bryant's avatar
Bryant committed
71
    void updateFactor();
pixhawk's avatar
pixhawk committed
72
73
74
75
76

    double d_s1, d_s2;     // scale interval boundaries
    double d_p1, d_p2;     // paint device interval boundaries

    double d_cnv;       // conversion factor
Bryant's avatar
Bryant committed
77
    double d_ts1;
pixhawk's avatar
pixhawk committed
78

Bryant's avatar
Bryant committed
79
    QwtTransform *d_transform;
pixhawk's avatar
pixhawk committed
80
81
82
83
84
};

/*!
    \return First border of the scale interval
*/
85
inline double QwtScaleMap::s1() const
pixhawk's avatar
pixhawk committed
86
87
88
89
90
91
92
{
    return d_s1;
}

/*!
    \return Second border of the scale interval
*/
93
inline double QwtScaleMap::s2() const
pixhawk's avatar
pixhawk committed
94
95
96
97
98
99
100
{
    return d_s2;
}

/*!
    \return First border of the paint interval
*/
101
inline double QwtScaleMap::p1() const
pixhawk's avatar
pixhawk committed
102
103
104
105
106
107
108
{
    return d_p1;
}

/*!
    \return Second border of the paint interval
*/
109
inline double QwtScaleMap::p2() const
pixhawk's avatar
pixhawk committed
110
111
112
113
{
    return d_p2;
}

Bryant's avatar
Bryant committed
114
115
116
/*!
    \return qwtAbs(p2() - p1())
*/
pixhawk's avatar
pixhawk committed
117
118
inline double QwtScaleMap::pDist() const
{
Bryant's avatar
Bryant committed
119
    return qAbs( d_p2 - d_p1 );
pixhawk's avatar
pixhawk committed
120
121
}

Bryant's avatar
Bryant committed
122
123
124
/*!
    \return qwtAbs(s2() - s1())
*/
pixhawk's avatar
pixhawk committed
125
126
inline double QwtScaleMap::sDist() const
{
Bryant's avatar
Bryant committed
127
    return qAbs( d_s2 - d_s1 );
pixhawk's avatar
pixhawk committed
128
129
130
}

/*!
131
  Transform a point related to the scale interval into an point
pixhawk's avatar
pixhawk committed
132
133
  related to the interval of the paint device

Bryant's avatar
Bryant committed
134
135
  \param s Value relative to the coordinates of the scale
  \return Transformed value
pixhawk's avatar
pixhawk committed
136

Bryant's avatar
Bryant committed
137
138
139
140
141
142
  \sa invTransform()
*/
inline double QwtScaleMap::transform( double s ) const
{
    if ( d_transform )
        s = d_transform->transform( s );
pixhawk's avatar
pixhawk committed
143

Bryant's avatar
Bryant committed
144
    return d_p1 + ( s - d_ts1 ) * d_cnv;
pixhawk's avatar
pixhawk committed
145
146
147
}

/*!
Bryant's avatar
Bryant committed
148
149
150
151
152
153
154
  Transform an paint device value into a value in the
  interval of the scale.

  \param p Value relative to the coordinates of the paint device
  \return Transformed value

  \sa transform()
pixhawk's avatar
pixhawk committed
155
*/
Bryant's avatar
Bryant committed
156
inline double QwtScaleMap::invTransform( double p ) const
pixhawk's avatar
pixhawk committed
157
{
Bryant's avatar
Bryant committed
158
159
160
    double s = d_ts1 + ( p - d_p1 ) / d_cnv;
    if ( d_transform )
        s = d_transform->invTransform( s );
pixhawk's avatar
pixhawk committed
161

Bryant's avatar
Bryant committed
162
163
    return s;
}
pixhawk's avatar
pixhawk committed
164

Bryant's avatar
Bryant committed
165
166
//! \return True, when ( p1() < p2() ) != ( s1() < s2() )
inline bool QwtScaleMap::isInverting() const
pixhawk's avatar
pixhawk committed
167
{
Bryant's avatar
Bryant committed
168
    return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) );
pixhawk's avatar
pixhawk committed
169
170
}

Bryant's avatar
Bryant committed
171
172
173
174
#ifndef QT_NO_DEBUG_STREAM
QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );
#endif

pixhawk's avatar
pixhawk committed
175
#endif