- Main Page
- Related Pages
- Classes
- Files

- File List

# 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     Type type() const;
    00039
    00040     virtual QwtScaleTransformation *copy() const;
    00041
    00042 private:
    00043     QwtScaleTransformation();
    00044     QwtScaleTransformation &operator=( const QwtScaleTransformation);
    00045
    00046     const Type d_type;
    00047 };
    00048
    00050 inline QwtScaleTransformation::Type QwtScaleTransformation::type() const
    00051 {
    00052     return d_type;
    00053 }
    00054
    00061 class QWT_EXPORT QwtScaleMap
    00062 {
    00063 public:
    00064     QwtScaleMap();
    00065     QwtScaleMap(const QwtScaleMap&);
    00066
    00067     ~QwtScaleMap();
    00068
    00069     QwtScaleMap &operator=(const QwtScaleMap &);
    00070
    00071     void setTransformation(QwtScaleTransformation * );
    00072     const QwtScaleTransformation *transformation() const;
    00073
    00074     void setPaintInterval(int p1, int p2);
    00075     void setPaintXInterval(double p1, double p2);
    00076     void setScaleInterval(double s1, double s2);
    00077
    00078     int transform(double x) const;
    00079     double invTransform(double i) const;
    00080
    00081     double xTransform(double x) const;
    00082
    00083     double p1() const;
    00084     double p2() const;
    00085
    00086     double s1() const;
    00087     double s2() const;
    00088
    00089     double pDist() const;
    00090     double sDist() const;
    00091
    00092     QT_STATIC_CONST double LogMin;
    00093     QT_STATIC_CONST double LogMax;
    00094
    00095 private:
    00096     void newFactor();
    00097
    00098     double d_s1, d_s2;     // scale interval boundaries
    00099     double d_p1, d_p2;     // paint device interval boundaries
    00100
    00101     double d_cnv;       // conversion factor
    00102
    00103     QwtScaleTransformation *d_transformation;
    00104 };
    00105
    00109 inline double QwtScaleMap::s1() const
    00110 {
    00111     return d_s1;
    00112 }
    00113
    00117 inline double QwtScaleMap::s2() const
    00118 {
    00119     return d_s2;
    00120 }
    00121
    00125 inline double QwtScaleMap::p1() const
    00126 {
    00127     return d_p1;
    00128 }
    00129
    00133 inline double QwtScaleMap::p2() const
    00134 {
    00135     return d_p2;
    00136 }
    00137
    00141 inline double QwtScaleMap::pDist() const
    00142 {
    00143     return qwtAbs(d_p2 - d_p1);
    00144 }
    00145
    00149 inline double QwtScaleMap::sDist() const
    00150 {
    00151     return qwtAbs(d_s2 - d_s1);
    00152 }
    00153
    00160 inline double QwtScaleMap::xTransform(double s) const
    00161 {
    00162     // try to inline code from QwtScaleTransformation
    00163
    00164     if ( d_transformation->type() == QwtScaleTransformation::Linear )
    00165         return d_p1 + (s - d_s1) * d_cnv;
    00166
    00167     if ( d_transformation->type() == QwtScaleTransformation::Log10 )
    00168         return d_p1 + log(s / d_s1) * d_cnv;
    00169
    00170     return d_transformation->xForm(s, d_s1, d_s2, d_p1, d_p2 );
    00171 }
    00172
    00180 inline double QwtScaleMap::invTransform(double p) const
    00181 {
    00182     return d_transformation->invXForm(p, d_p1, d_p2, d_s1, d_s2 );
    00183 }
    00184
    00193 inline int QwtScaleMap::transform(double s) const
    00194 {
    00195     return qRound(xTransform(s));
    00196 }
    00197
    00198 #endif