qwt_scale_map.h
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 00019 class QWT_EXPORT QwtScaleTransformation 00020 { 00021 public: 00022 enum Type 00023 { 00024 Linear, 00025 Log10, 00026 00027 Other 00028 }; 00029 00030 QwtScaleTransformation(Type type); 00031 virtual ~QwtScaleTransformation(); 00032 00033 virtual double xForm(double x, double s1, double s2, 00034 double p1, double p2) const; 00035 virtual double invXForm(double x, double s1, double s2, 00036 double p1, double p2) const; 00037 00039 inline Type type() const { return d_type; } 00040 00041 virtual QwtScaleTransformation *copy() const; 00042 00043 private: 00044 QwtScaleTransformation(); 00045 QwtScaleTransformation &operator=( const QwtScaleTransformation); 00046 00047 const Type d_type; 00048 }; 00049 00056 class QWT_EXPORT QwtScaleMap 00057 { 00058 public: 00059 QwtScaleMap(); 00060 QwtScaleMap(const QwtScaleMap&); 00061 00062 ~QwtScaleMap(); 00063 00064 QwtScaleMap &operator=(const QwtScaleMap &); 00065 00066 void setTransformation(QwtScaleTransformation * ); 00067 const QwtScaleTransformation *transformation() const; 00068 00069 void setPaintInterval(int p1, int p2); 00070 void setPaintXInterval(double p1, double p2); 00071 void setScaleInterval(double s1, double s2); 00072 00073 int transform(double x) const; 00074 double invTransform(double i) const; 00075 00076 double xTransform(double x) const; 00077 00078 inline double p1() const; 00079 inline double p2() const; 00080 00081 inline double s1() const; 00082 inline double s2() const; 00083 00084 inline double pDist() const; 00085 inline double sDist() const; 00086 00087 QT_STATIC_CONST double LogMin; 00088 QT_STATIC_CONST double LogMax; 00089 00090 private: 00091 void newFactor(); 00092 00093 double d_s1, d_s2; // scale interval boundaries 00094 double d_p1, d_p2; // paint device interval boundaries 00095 00096 double d_cnv; // conversion factor 00097 00098 QwtScaleTransformation *d_transformation; 00099 }; 00100 00104 inline double QwtScaleMap::s1() const 00105 { 00106 return d_s1; 00107 } 00108 00112 inline double QwtScaleMap::s2() const 00113 { 00114 return d_s2; 00115 } 00116 00120 inline double QwtScaleMap::p1() const 00121 { 00122 return d_p1; 00123 } 00124 00128 inline double QwtScaleMap::p2() const 00129 { 00130 return d_p2; 00131 } 00132 00136 inline double QwtScaleMap::pDist() const 00137 { 00138 return qwtAbs(d_p2 - d_p1); 00139 } 00140 00144 inline double QwtScaleMap::sDist() const 00145 { 00146 return qwtAbs(d_s2 - d_s1); 00147 } 00148 00155 inline double QwtScaleMap::xTransform(double s) const 00156 { 00157 // try to inline code from QwtScaleTransformation 00158 00159 if ( d_transformation->type() == QwtScaleTransformation::Linear ) 00160 return d_p1 + (s - d_s1) * d_cnv; 00161 00162 if ( d_transformation->type() == QwtScaleTransformation::Log10 ) 00163 return d_p1 + log(s / d_s1) * d_cnv; 00164 00165 return d_transformation->xForm(s, d_s1, d_s2, d_p1, d_p2 ); 00166 } 00167 00175 inline double QwtScaleMap::invTransform(double p) const 00176 { 00177 return d_transformation->invXForm(p, d_p1, d_p2, d_s1, d_s2 ); 00178 } 00179 00188 inline int QwtScaleMap::transform(double s) const 00189 { 00190 return qRound(xTransform(s)); 00191 } 00192 00193 #endif
Generated on Wed Sep 2 18:37:22 2009 for Qwt User's Guide by
