Qwt User's Guide 6.0.0
|
00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** 00002 * Qwt Widget Library 00003 * Copyright (C) 1997 Josef Wilgen 00004 * Copyright (C) 2002 Uwe Rathmann 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the Qwt License, Version 1.0 00008 *****************************************************************************/ 00009 00010 #ifndef QWT_SCALE_MAP_H 00011 #define QWT_SCALE_MAP_H 00012 00013 #include "qwt_global.h" 00014 #include "qwt_math.h" 00015 #ifndef QT_NO_DEBUG_STREAM 00016 #include <qdebug.h> 00017 #endif 00018 00019 class QRectF; 00020 00024 class QWT_EXPORT QwtScaleTransformation 00025 { 00026 public: 00028 enum Type 00029 { 00031 Linear, 00032 00034 Log10, 00035 00037 Other 00038 }; 00039 00040 QwtScaleTransformation( Type type ); 00041 virtual ~QwtScaleTransformation(); 00042 00043 virtual double xForm( double x, double s1, double s2, 00044 double p1, double p2 ) const; 00045 virtual double invXForm( double x, double s1, double s2, 00046 double p1, double p2 ) const; 00047 00048 Type type() const; 00049 00050 virtual QwtScaleTransformation *copy() const; 00051 00052 private: 00053 QwtScaleTransformation(); 00054 QwtScaleTransformation &operator=( const QwtScaleTransformation ); 00055 00056 const Type d_type; 00057 }; 00058 00060 inline QwtScaleTransformation::Type QwtScaleTransformation::type() const 00061 { 00062 return d_type; 00063 } 00064 00071 class QWT_EXPORT QwtScaleMap 00072 { 00073 public: 00074 QwtScaleMap(); 00075 QwtScaleMap( const QwtScaleMap& ); 00076 00077 ~QwtScaleMap(); 00078 00079 QwtScaleMap &operator=( const QwtScaleMap & ); 00080 00081 void setTransformation( QwtScaleTransformation * ); 00082 const QwtScaleTransformation *transformation() const; 00083 00084 void setPaintInterval( double p1, double p2 ); 00085 void setScaleInterval( double s1, double s2 ); 00086 00087 double transform( double s ) const; 00088 double invTransform( double p ) const; 00089 00090 double p1() const; 00091 double p2() const; 00092 00093 double s1() const; 00094 double s2() const; 00095 00096 double pDist() const; 00097 double sDist() const; 00098 00099 QT_STATIC_CONST double LogMin; 00100 QT_STATIC_CONST double LogMax; 00101 00102 static QRectF transform( const QwtScaleMap &, 00103 const QwtScaleMap &, const QRectF & ); 00104 static QRectF invTransform( const QwtScaleMap &, 00105 const QwtScaleMap &, const QRectF & ); 00106 00107 static QPointF transform( const QwtScaleMap &, 00108 const QwtScaleMap &, const QPointF & ); 00109 static QPointF invTransform( const QwtScaleMap &, 00110 const QwtScaleMap &, const QPointF & ); 00111 00112 bool isInverting() const; 00113 00114 private: 00115 void newFactor(); 00116 00117 double d_s1, d_s2; // scale interval boundaries 00118 double d_p1, d_p2; // paint device interval boundaries 00119 00120 double d_cnv; // conversion factor 00121 00122 QwtScaleTransformation *d_transformation; 00123 }; 00124 00128 inline double QwtScaleMap::s1() const 00129 { 00130 return d_s1; 00131 } 00132 00136 inline double QwtScaleMap::s2() const 00137 { 00138 return d_s2; 00139 } 00140 00144 inline double QwtScaleMap::p1() const 00145 { 00146 return d_p1; 00147 } 00148 00152 inline double QwtScaleMap::p2() const 00153 { 00154 return d_p2; 00155 } 00156 00160 inline double QwtScaleMap::pDist() const 00161 { 00162 return qAbs( d_p2 - d_p1 ); 00163 } 00164 00168 inline double QwtScaleMap::sDist() const 00169 { 00170 return qAbs( d_s2 - d_s1 ); 00171 } 00172 00179 inline double QwtScaleMap::transform( double s ) const 00180 { 00181 // try to inline code from QwtScaleTransformation 00182 00183 if ( d_transformation->type() == QwtScaleTransformation::Linear ) 00184 return d_p1 + ( s - d_s1 ) * d_cnv; 00185 00186 if ( d_transformation->type() == QwtScaleTransformation::Log10 ) 00187 return d_p1 + log( s / d_s1 ) * d_cnv; 00188 00189 return d_transformation->xForm( s, d_s1, d_s2, d_p1, d_p2 ); 00190 } 00191 00199 inline double QwtScaleMap::invTransform( double p ) const 00200 { 00201 return d_transformation->invXForm( p, d_p1, d_p2, d_s1, d_s2 ); 00202 } 00203 00205 inline bool QwtScaleMap::isInverting() const 00206 { 00207 return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) ); 00208 } 00209 00210 #ifndef QT_NO_DEBUG_STREAM 00211 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & ); 00212 #endif 00213 00214 #endif