Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "qwt_scale_map.h"
00011
00012 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMin = 1.0e-150;
00013 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMax = 1.0e150;
00014
00016 QwtScaleTransformation::QwtScaleTransformation(Type type):
00017 d_type(type)
00018 {
00019 }
00020
00022 QwtScaleTransformation::~QwtScaleTransformation()
00023 {
00024 }
00025
00027 QwtScaleTransformation *QwtScaleTransformation::copy() const
00028 {
00029 return new QwtScaleTransformation(d_type);
00030 }
00031
00049 double QwtScaleTransformation::xForm(
00050 double s, double s1, double s2, double p1, double p2) const
00051 {
00052 if ( d_type == Log10 )
00053 return p1 + (p2 - p1) / log(s2 / s1) * log(s / s1);
00054 else
00055 return p1 + (p2 - p1) / (s2 - s1) * (s - s1);
00056 }
00057
00072 double QwtScaleTransformation::invXForm(double p, double p1, double p2,
00073 double s1, double s2) const
00074 {
00075 if ( d_type == Log10 )
00076 return exp((p - p1) / (p2 - p1) * log(s2 / s1)) * s1;
00077 else
00078 return s1 + (s2 - s1) / (p2 - p1) * (p - p1);
00079 }
00080
00086 QwtScaleMap::QwtScaleMap():
00087 d_s1(0.0),
00088 d_s2(1.0),
00089 d_p1(0.0),
00090 d_p2(1.0),
00091 d_cnv(1.0)
00092 {
00093 d_transformation = new QwtScaleTransformation(
00094 QwtScaleTransformation::Linear);
00095 }
00096
00098 QwtScaleMap::QwtScaleMap(const QwtScaleMap& other):
00099 d_s1(other.d_s1),
00100 d_s2(other.d_s2),
00101 d_p1(other.d_p1),
00102 d_p2(other.d_p2),
00103 d_cnv(other.d_cnv)
00104 {
00105 d_transformation = other.d_transformation->copy();
00106 }
00107
00111 QwtScaleMap::~QwtScaleMap()
00112 {
00113 delete d_transformation;
00114 }
00115
00117 QwtScaleMap &QwtScaleMap::operator=(const QwtScaleMap &other)
00118 {
00119 d_s1 = other.d_s1;
00120 d_s2 = other.d_s2;
00121 d_p1 = other.d_p1;
00122 d_p2 = other.d_p2;
00123 d_cnv = other.d_cnv;
00124
00125 delete d_transformation;
00126 d_transformation = other.d_transformation->copy();
00127
00128 return *this;
00129 }
00130
00134 void QwtScaleMap::setTransformation(
00135 QwtScaleTransformation *transformation)
00136 {
00137 if ( transformation == NULL )
00138 return;
00139
00140 delete d_transformation;
00141 d_transformation = transformation;
00142 setScaleInterval(d_s1, d_s2);
00143 }
00144
00146 const QwtScaleTransformation *QwtScaleMap::transformation() const
00147 {
00148 return d_transformation;
00149 }
00150
00157 void QwtScaleMap::setScaleInterval(double s1, double s2)
00158 {
00159 if (d_transformation->type() == QwtScaleTransformation::Log10 )
00160 {
00161 if (s1 < LogMin)
00162 s1 = LogMin;
00163 else if (s1 > LogMax)
00164 s1 = LogMax;
00165
00166 if (s2 < LogMin)
00167 s2 = LogMin;
00168 else if (s2 > LogMax)
00169 s2 = LogMax;
00170 }
00171
00172 d_s1 = s1;
00173 d_s2 = s2;
00174
00175 if ( d_transformation->type() != QwtScaleTransformation::Other )
00176 newFactor();
00177 }
00178
00184 void QwtScaleMap::setPaintInterval(int p1, int p2)
00185 {
00186 d_p1 = p1;
00187 d_p2 = p2;
00188
00189 if ( d_transformation->type() != QwtScaleTransformation::Other )
00190 newFactor();
00191 }
00192
00198 void QwtScaleMap::setPaintXInterval(double p1, double p2)
00199 {
00200 d_p1 = p1;
00201 d_p2 = p2;
00202
00203 if ( d_transformation->type() != QwtScaleTransformation::Other )
00204 newFactor();
00205 }
00206
00210 void QwtScaleMap::newFactor()
00211 {
00212 d_cnv = 0.0;
00213 #if 1
00214 if (d_s2 == d_s1)
00215 return;
00216 #endif
00217
00218 switch( d_transformation->type() )
00219 {
00220 case QwtScaleTransformation::Linear:
00221 d_cnv = (d_p2 - d_p1) / (d_s2 - d_s1);
00222 break;
00223 case QwtScaleTransformation::Log10:
00224 d_cnv = (d_p2 - d_p1) / log(d_s2 / d_s1);
00225 break;
00226 default:;
00227 }
00228 }