Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "qwt_scale_div.h"
00011 #include "qwt_math.h"
00012 #include "qwt_double_interval.h"
00013
00015 QwtScaleDiv::QwtScaleDiv():
00016 d_lowerBound(0.0),
00017 d_upperBound(0.0),
00018 d_isValid(false)
00019 {
00020 }
00021
00028 QwtScaleDiv::QwtScaleDiv(
00029 const QwtDoubleInterval &interval,
00030 QwtValueList ticks[NTickTypes]):
00031 d_lowerBound(interval.minValue()),
00032 d_upperBound(interval.maxValue()),
00033 d_isValid(true)
00034 {
00035 for ( int i = 0; i < NTickTypes; i++ )
00036 d_ticks[i] = ticks[i];
00037 }
00038
00046 QwtScaleDiv::QwtScaleDiv(
00047 double lowerBound, double upperBound,
00048 QwtValueList ticks[NTickTypes]):
00049 d_lowerBound(lowerBound),
00050 d_upperBound(upperBound),
00051 d_isValid(true)
00052 {
00053 for ( int i = 0; i < NTickTypes; i++ )
00054 d_ticks[i] = ticks[i];
00055 }
00056
00061 void QwtScaleDiv::setInterval(const QwtDoubleInterval &interval)
00062 {
00063 setInterval(interval.minValue(), interval.maxValue());
00064 }
00065
00070 int QwtScaleDiv::operator==(const QwtScaleDiv &other) const
00071 {
00072 if ( d_lowerBound != other.d_lowerBound ||
00073 d_upperBound != other.d_upperBound ||
00074 d_isValid != other.d_isValid )
00075 {
00076 return false;
00077 }
00078
00079 for ( int i = 0; i < NTickTypes; i++ )
00080 {
00081 if ( d_ticks[i] != other.d_ticks[i] )
00082 return false;
00083 }
00084
00085 return true;
00086 }
00087
00092 int QwtScaleDiv::operator!=(const QwtScaleDiv &s) const
00093 {
00094 return (!(*this == s));
00095 }
00096
00098 void QwtScaleDiv::invalidate()
00099 {
00100 d_isValid = false;
00101
00102
00103 for ( int i = 0; i < NTickTypes; i++ )
00104 d_ticks[i].clear();
00105
00106 d_lowerBound = d_upperBound = 0;
00107 }
00108
00110 bool QwtScaleDiv::isValid() const
00111 {
00112 return d_isValid;
00113 }
00114
00121 bool QwtScaleDiv::contains(double value) const
00122 {
00123 if ( !d_isValid )
00124 return false;
00125
00126 const double min = qwtMin(d_lowerBound, d_upperBound);
00127 const double max = qwtMax(d_lowerBound, d_upperBound);
00128
00129 return value >= min && value <= max;
00130 }
00131
00133 void QwtScaleDiv::invert()
00134 {
00135 qSwap(d_lowerBound, d_upperBound);
00136
00137 for ( int i = 0; i < NTickTypes; i++ )
00138 {
00139 QwtValueList& ticks = d_ticks[i];
00140
00141 const int size = ticks.count();
00142 const int size2 = size / 2;
00143
00144 for (int i=0; i < size2; i++)
00145 qSwap(ticks[i], ticks[size - 1 - i]);
00146 }
00147 }
00148
00155 void QwtScaleDiv::setTicks(int type, const QwtValueList &ticks)
00156 {
00157 if ( type >= 0 || type < NTickTypes )
00158 d_ticks[type] = ticks;
00159 }
00160
00166 const QwtValueList &QwtScaleDiv::ticks(int type) const
00167 {
00168 if ( type >= 0 || type < NTickTypes )
00169 return d_ticks[type];
00170
00171 static QwtValueList noTicks;
00172 return noTicks;
00173 }