Qwt User's Guide
svn
|
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 00028 class QWT_EXPORT QwtScaleTransformation 00029 { 00030 public: 00032 enum Type 00033 { 00035 Linear, 00036 00038 Log10, 00039 00041 Other 00042 }; 00043 00044 QwtScaleTransformation( Type type ); 00045 virtual ~QwtScaleTransformation(); 00046 00047 virtual double xForm( double s, double s1, double s2, 00048 double p1, double p2 ) const; 00049 virtual double invXForm( double p, double p1, double p2, 00050 double s1, double s2 ) const; 00051 00052 Type type() const; 00053 00054 virtual QwtScaleTransformation *copy() const; 00055 00056 private: 00057 QwtScaleTransformation(); 00058 QwtScaleTransformation &operator=( const QwtScaleTransformation ); 00059 00060 const Type d_type; 00061 }; 00062 00064 inline QwtScaleTransformation::Type QwtScaleTransformation::type() const 00065 { 00066 return d_type; 00067 } 00068 00076 class QWT_EXPORT QwtScaleMap 00077 { 00078 public: 00079 QwtScaleMap(); 00080 QwtScaleMap( const QwtScaleMap& ); 00081 00082 ~QwtScaleMap(); 00083 00084 QwtScaleMap &operator=( const QwtScaleMap & ); 00085 00086 void setTransformation( QwtScaleTransformation * ); 00087 const QwtScaleTransformation *transformation() const; 00088 00089 void setPaintInterval( double p1, double p2 ); 00090 void setScaleInterval( double s1, double s2 ); 00091 00092 double transform( double s ) const; 00093 double invTransform( double p ) const; 00094 00095 double p1() const; 00096 double p2() const; 00097 00098 double s1() const; 00099 double s2() const; 00100 00101 double pDist() const; 00102 double sDist() const; 00103 00104 QT_STATIC_CONST double LogMin; 00105 QT_STATIC_CONST double LogMax; 00106 00107 static QRectF transform( const QwtScaleMap &, 00108 const QwtScaleMap &, const QRectF & ); 00109 static QRectF invTransform( const QwtScaleMap &, 00110 const QwtScaleMap &, const QRectF & ); 00111 00112 static QPointF transform( const QwtScaleMap &, 00113 const QwtScaleMap &, const QPointF & ); 00114 static QPointF invTransform( const QwtScaleMap &, 00115 const QwtScaleMap &, const QPointF & ); 00116 00117 bool isInverting() const; 00118 00119 private: 00120 void newFactor(); 00121 00122 double d_s1, d_s2; // scale interval boundaries 00123 double d_p1, d_p2; // paint device interval boundaries 00124 00125 double d_cnv; // conversion factor 00126 00127 QwtScaleTransformation *d_transformation; 00128 }; 00129 00133 inline double QwtScaleMap::s1() const 00134 { 00135 return d_s1; 00136 } 00137 00141 inline double QwtScaleMap::s2() const 00142 { 00143 return d_s2; 00144 } 00145 00149 inline double QwtScaleMap::p1() const 00150 { 00151 return d_p1; 00152 } 00153 00157 inline double QwtScaleMap::p2() const 00158 { 00159 return d_p2; 00160 } 00161 00165 inline double QwtScaleMap::pDist() const 00166 { 00167 return qAbs( d_p2 - d_p1 ); 00168 } 00169 00173 inline double QwtScaleMap::sDist() const 00174 { 00175 return qAbs( d_s2 - d_s1 ); 00176 } 00177 00184 inline double QwtScaleMap::transform( double s ) const 00185 { 00186 // try to inline code from QwtScaleTransformation 00187 00188 if ( d_transformation->type() == QwtScaleTransformation::Linear ) 00189 return d_p1 + ( s - d_s1 ) * d_cnv; 00190 00191 if ( d_transformation->type() == QwtScaleTransformation::Log10 ) 00192 return d_p1 + log( s / d_s1 ) * d_cnv; 00193 00194 return d_transformation->xForm( s, d_s1, d_s2, d_p1, d_p2 ); 00195 } 00196 00204 inline double QwtScaleMap::invTransform( double p ) const 00205 { 00206 return d_transformation->invXForm( p, d_p1, d_p2, d_s1, d_s2 ); 00207 } 00208 00210 inline bool QwtScaleMap::isInverting() const 00211 { 00212 return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) ); 00213 } 00214 00215 #ifndef QT_NO_DEBUG_STREAM 00216 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & ); 00217 #endif 00218 00219 #endif