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 
00038     inline Type type() const { return d_type; }
00039     
00040     virtual QwtScaleTransformation *copy() const;
00041 
00042 private:
00043     const Type d_type;
00044 };
00045 
00052 class QWT_EXPORT QwtScaleMap
00053 {
00054 public:
00055     QwtScaleMap();
00056     QwtScaleMap(const QwtScaleMap&);
00057 
00058     ~QwtScaleMap();
00059 
00060     QwtScaleMap &operator=(const QwtScaleMap &);
00061 
00062     void setTransformation(QwtScaleTransformation * );
00063     const QwtScaleTransformation *transformation() const;
00064 
00065     void setPaintInterval(int p1, int p2);
00066     void setPaintXInterval(double p1, double p2);
00067     void setScaleInterval(double s1, double s2);
00068 
00069     int transform(double x) const;
00070     double invTransform(double i) const;
00071 
00072     double xTransform(double x) const;
00073 
00074     inline double p1() const;
00075     inline double p2() const;
00076 
00077     inline double s1() const;
00078     inline double s2() const;
00079 
00080     inline double pDist() const;
00081     inline double sDist() const;
00082 
00083     QT_STATIC_CONST double LogMin;
00084     QT_STATIC_CONST double LogMax;
00085 
00086 private:
00087     void newFactor();   
00088 
00089     double d_s1, d_s2;     // scale interval boundaries
00090     double d_p1, d_p2;     // paint device interval boundaries
00091 
00092     double d_cnv;       // conversion factor
00093 
00094     QwtScaleTransformation *d_transformation;
00095 };
00096 
00100 inline double QwtScaleMap::s1() const 
00101 {
00102     return d_s1;
00103 }
00104 
00108 inline double QwtScaleMap::s2() const 
00109 {
00110     return d_s2;
00111 }
00112 
00116 inline double QwtScaleMap::p1() const 
00117 {
00118     return d_p1;
00119 }
00120 
00124 inline double QwtScaleMap::p2() const 
00125 {
00126     return d_p2;
00127 }
00128 
00129 inline double QwtScaleMap::pDist() const
00130 {
00131     return qwtAbs(d_p2 - d_p1);
00132 }
00133 
00134 inline double QwtScaleMap::sDist() const
00135 {
00136     return qwtAbs(d_s2 - d_s1);
00137 }
00138 
00143 inline double QwtScaleMap::xTransform(double s) const
00144 {
00145     // try to inline code from QwtScaleTransformation
00146 
00147     if ( d_transformation->type() == QwtScaleTransformation::Linear )
00148         return d_p1 + (s - d_s1) * d_cnv;
00149 
00150     if ( d_transformation->type() == QwtScaleTransformation::Log10 )
00151         return d_p1 + log(s / d_s1) * d_cnv;
00152 
00153     return d_transformation->xForm(s, d_s1, d_s2, d_p1, d_p2 );
00154 }
00155 
00160 inline double QwtScaleMap::invTransform(double p) const
00161 {
00162     return d_transformation->invXForm(p, d_p1, d_p2, d_s1, d_s2 );
00163 }
00164 
00172 inline int QwtScaleMap::transform(double s) const
00173 {
00174     return qRound(xTransform(s));
00175 }
00176 
00177 #endif

Generated on Thu Jan 18 10:39:39 2007 for Qwt User's Guide by  doxygen 1.4.6