[4271] | 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 | #ifndef QWT_SCALE_MAP_H
|
---|
| 11 | #define QWT_SCALE_MAP_H
|
---|
| 12 |
|
---|
| 13 | #include "qwt_global.h"
|
---|
[8127] | 14 | #include "qwt_transform.h"
|
---|
| 15 | #include <qrect.h>
|
---|
| 16 |
|
---|
[4271] | 17 | #ifndef QT_NO_DEBUG_STREAM
|
---|
| 18 | #include <qdebug.h>
|
---|
| 19 | #endif
|
---|
| 20 |
|
---|
| 21 | class QRectF;
|
---|
| 22 |
|
---|
| 23 | /*!
|
---|
| 24 | \brief A scale map
|
---|
| 25 |
|
---|
| 26 | QwtScaleMap offers transformations from the coordinate system
|
---|
| 27 | of a scale into the linear coordinate system of a paint device
|
---|
| 28 | and vice versa.
|
---|
| 29 | */
|
---|
| 30 | class QWT_EXPORT QwtScaleMap
|
---|
| 31 | {
|
---|
| 32 | public:
|
---|
| 33 | QwtScaleMap();
|
---|
| 34 | QwtScaleMap( const QwtScaleMap& );
|
---|
| 35 |
|
---|
| 36 | ~QwtScaleMap();
|
---|
| 37 |
|
---|
| 38 | QwtScaleMap &operator=( const QwtScaleMap & );
|
---|
| 39 |
|
---|
[8127] | 40 | void setTransformation( QwtTransform * );
|
---|
| 41 | const QwtTransform *transformation() const;
|
---|
[4271] | 42 |
|
---|
| 43 | void setPaintInterval( double p1, double p2 );
|
---|
| 44 | void setScaleInterval( double s1, double s2 );
|
---|
| 45 |
|
---|
| 46 | double transform( double s ) const;
|
---|
| 47 | double invTransform( double p ) const;
|
---|
| 48 |
|
---|
| 49 | double p1() const;
|
---|
| 50 | double p2() const;
|
---|
| 51 |
|
---|
| 52 | double s1() const;
|
---|
| 53 | double s2() const;
|
---|
| 54 |
|
---|
| 55 | double pDist() const;
|
---|
| 56 | double sDist() const;
|
---|
| 57 |
|
---|
| 58 | static QRectF transform( const QwtScaleMap &,
|
---|
| 59 | const QwtScaleMap &, const QRectF & );
|
---|
| 60 | static QRectF invTransform( const QwtScaleMap &,
|
---|
| 61 | const QwtScaleMap &, const QRectF & );
|
---|
| 62 |
|
---|
| 63 | static QPointF transform( const QwtScaleMap &,
|
---|
| 64 | const QwtScaleMap &, const QPointF & );
|
---|
| 65 | static QPointF invTransform( const QwtScaleMap &,
|
---|
| 66 | const QwtScaleMap &, const QPointF & );
|
---|
| 67 |
|
---|
| 68 | bool isInverting() const;
|
---|
| 69 |
|
---|
| 70 | private:
|
---|
[8127] | 71 | void updateFactor();
|
---|
[4271] | 72 |
|
---|
| 73 | double d_s1, d_s2; // scale interval boundaries
|
---|
| 74 | double d_p1, d_p2; // paint device interval boundaries
|
---|
| 75 |
|
---|
| 76 | double d_cnv; // conversion factor
|
---|
[8127] | 77 | double d_ts1;
|
---|
[4271] | 78 |
|
---|
[8127] | 79 | QwtTransform *d_transform;
|
---|
[4271] | 80 | };
|
---|
| 81 |
|
---|
| 82 | /*!
|
---|
| 83 | \return First border of the scale interval
|
---|
| 84 | */
|
---|
| 85 | inline double QwtScaleMap::s1() const
|
---|
| 86 | {
|
---|
| 87 | return d_s1;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | /*!
|
---|
| 91 | \return Second border of the scale interval
|
---|
| 92 | */
|
---|
| 93 | inline double QwtScaleMap::s2() const
|
---|
| 94 | {
|
---|
| 95 | return d_s2;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | /*!
|
---|
| 99 | \return First border of the paint interval
|
---|
| 100 | */
|
---|
| 101 | inline double QwtScaleMap::p1() const
|
---|
| 102 | {
|
---|
| 103 | return d_p1;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /*!
|
---|
| 107 | \return Second border of the paint interval
|
---|
| 108 | */
|
---|
| 109 | inline double QwtScaleMap::p2() const
|
---|
| 110 | {
|
---|
| 111 | return d_p2;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /*!
|
---|
| 115 | \return qwtAbs(p2() - p1())
|
---|
| 116 | */
|
---|
| 117 | inline double QwtScaleMap::pDist() const
|
---|
| 118 | {
|
---|
| 119 | return qAbs( d_p2 - d_p1 );
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | /*!
|
---|
| 123 | \return qwtAbs(s2() - s1())
|
---|
| 124 | */
|
---|
| 125 | inline double QwtScaleMap::sDist() const
|
---|
| 126 | {
|
---|
| 127 | return qAbs( d_s2 - d_s1 );
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /*!
|
---|
| 131 | Transform a point related to the scale interval into an point
|
---|
| 132 | related to the interval of the paint device
|
---|
| 133 |
|
---|
| 134 | \param s Value relative to the coordinates of the scale
|
---|
[8127] | 135 | \return Transformed value
|
---|
| 136 |
|
---|
| 137 | \sa invTransform()
|
---|
[4271] | 138 | */
|
---|
| 139 | inline double QwtScaleMap::transform( double s ) const
|
---|
| 140 | {
|
---|
[8127] | 141 | if ( d_transform )
|
---|
| 142 | s = d_transform->transform( s );
|
---|
[4271] | 143 |
|
---|
[8127] | 144 | return d_p1 + ( s - d_ts1 ) * d_cnv;
|
---|
[4271] | 145 | }
|
---|
| 146 |
|
---|
| 147 | /*!
|
---|
| 148 | Transform an paint device value into a value in the
|
---|
| 149 | interval of the scale.
|
---|
| 150 |
|
---|
| 151 | \param p Value relative to the coordinates of the paint device
|
---|
[8127] | 152 | \return Transformed value
|
---|
| 153 |
|
---|
[4271] | 154 | \sa transform()
|
---|
| 155 | */
|
---|
| 156 | inline double QwtScaleMap::invTransform( double p ) const
|
---|
| 157 | {
|
---|
[8127] | 158 | double s = d_ts1 + ( p - d_p1 ) / d_cnv;
|
---|
| 159 | if ( d_transform )
|
---|
| 160 | s = d_transform->invTransform( s );
|
---|
| 161 |
|
---|
| 162 | return s;
|
---|
[4271] | 163 | }
|
---|
| 164 |
|
---|
| 165 | //! \return True, when ( p1() < p2() ) != ( s1() < s2() )
|
---|
| 166 | inline bool QwtScaleMap::isInverting() const
|
---|
| 167 | {
|
---|
| 168 | return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) );
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | #ifndef QT_NO_DEBUG_STREAM
|
---|
| 172 | QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );
|
---|
| 173 | #endif
|
---|
| 174 |
|
---|
| 175 | #endif
|
---|