Qwt User's Guide: qwt_scale_map.h Source File

- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# 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     QwtScaleTransformation();
    00044     QwtScaleTransformation &operator=( const QwtScaleTransformation);
    00045
    00046     const Type d_type;
    00047 };
    00048
    00055 class QWT_EXPORT QwtScaleMap
    00056 {
    00057 public:
    00058     QwtScaleMap();
    00059     QwtScaleMap(const QwtScaleMap&);
    00060
    00061     ~QwtScaleMap();
    00062
    00063     QwtScaleMap &operator=(const QwtScaleMap &);
    00064
    00065     void setTransformation(QwtScaleTransformation * );
    00066     const QwtScaleTransformation *transformation() const;
    00067
    00068     void setPaintInterval(int p1, int p2);
    00069     void setPaintXInterval(double p1, double p2);
    00070     void setScaleInterval(double s1, double s2);
    00071
    00072     int transform(double x) const;
    00073     double invTransform(double i) const;
    00074
    00075     double xTransform(double x) const;
    00076
    00077     inline double p1() const;
    00078     inline double p2() const;
    00079
    00080     inline double s1() const;
    00081     inline double s2() const;
    00082
    00083     inline double pDist() const;
    00084     inline double sDist() const;
    00085
    00086     QT_STATIC_CONST double LogMin;
    00087     QT_STATIC_CONST double LogMax;
    00088
    00089 private:
    00090     void newFactor();
    00091
    00092     double d_s1, d_s2;     // scale interval boundaries
    00093     double d_p1, d_p2;     // paint device interval boundaries
    00094
    00095     double d_cnv;       // conversion factor
    00096
    00097     QwtScaleTransformation *d_transformation;
    00098 };
    00099
    00103 inline double QwtScaleMap::s1() const
    00104 {
    00105     return d_s1;
    00106 }
    00107
    00111 inline double QwtScaleMap::s2() const
    00112 {
    00113     return d_s2;
    00114 }
    00115
    00119 inline double QwtScaleMap::p1() const
    00120 {
    00121     return d_p1;
    00122 }
    00123
    00127 inline double QwtScaleMap::p2() const
    00128 {
    00129     return d_p2;
    00130 }
    00131
    00132 inline double QwtScaleMap::pDist() const
    00133 {
    00134     return qwtAbs(d_p2 - d_p1);
    00135 }
    00136
    00137 inline double QwtScaleMap::sDist() const
    00138 {
    00139     return qwtAbs(d_s2 - d_s1);
    00140 }
    00141
    00146 inline double QwtScaleMap::xTransform(double s) const
    00147 {
    00148     // try to inline code from QwtScaleTransformation
    00149
    00150     if ( d_transformation->type() == QwtScaleTransformation::Linear )
    00151         return d_p1 + (s - d_s1) * d_cnv;
    00152
    00153     if ( d_transformation->type() == QwtScaleTransformation::Log10 )
    00154         return d_p1 + log(s / d_s1) * d_cnv;
    00155
    00156     return d_transformation->xForm(s, d_s1, d_s2, d_p1, d_p2 );
    00157 }
    00158
    00163 inline double QwtScaleMap::invTransform(double p) const
    00164 {
    00165     return d_transformation->invXForm(p, d_p1, d_p2, d_s1, d_s2 );
    00166 }
    00167
    00175 inline int QwtScaleMap::transform(double s) const
    00176 {
    00177     return qRound(xTransform(s));
    00178 }
    00179
    00180 #endif