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 <qalgorithms.h>
00013
00022 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound ):
00023 d_lowerBound( lowerBound ),
00024 d_upperBound( upperBound )
00025 {
00026 }
00027
00034 QwtScaleDiv::QwtScaleDiv( const QwtInterval &interval,
00035 QList<double> ticks[NTickTypes] ):
00036 d_lowerBound( interval.minValue() ),
00037 d_upperBound( interval.maxValue() )
00038 {
00039 for ( int i = 0; i < NTickTypes; i++ )
00040 d_ticks[i] = ticks[i];
00041 }
00042
00052 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
00053 QList<double> ticks[NTickTypes] ):
00054 d_lowerBound( lowerBound ),
00055 d_upperBound( upperBound )
00056 {
00057 for ( int i = 0; i < NTickTypes; i++ )
00058 d_ticks[i] = ticks[i];
00059 }
00060
00072 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
00073 const QList<double> &minorTicks,
00074 const QList<double> &mediumTicks,
00075 const QList<double> &majorTicks ):
00076 d_lowerBound( lowerBound ),
00077 d_upperBound( upperBound )
00078 {
00079 d_ticks[ MinorTick ] = minorTicks;
00080 d_ticks[ MediumTick ] = mediumTicks;
00081 d_ticks[ MajorTick ] = majorTicks;
00082 }
00083
00092 void QwtScaleDiv::setInterval( double lowerBound, double upperBound )
00093 {
00094 d_lowerBound = lowerBound;
00095 d_upperBound = upperBound;
00096 }
00097
00103 void QwtScaleDiv::setInterval( const QwtInterval &interval )
00104 {
00105 d_lowerBound = interval.minValue();
00106 d_upperBound = interval.maxValue();
00107 }
00108
00112 QwtInterval QwtScaleDiv::interval() const
00113 {
00114 return QwtInterval( d_lowerBound, d_upperBound );
00115 }
00116
00123 void QwtScaleDiv::setLowerBound( double lowerBound )
00124 {
00125 d_lowerBound = lowerBound;
00126 }
00127
00132 double QwtScaleDiv::lowerBound() const
00133 {
00134 return d_lowerBound;
00135 }
00136
00143 void QwtScaleDiv::setUpperBound( double upperBound )
00144 {
00145 d_upperBound = upperBound;
00146 }
00147
00152 double QwtScaleDiv::upperBound() const
00153 {
00154 return d_upperBound;
00155 }
00156
00160 double QwtScaleDiv::range() const
00161 {
00162 return d_upperBound - d_lowerBound;
00163 }
00164
00169 bool QwtScaleDiv::operator==( const QwtScaleDiv &other ) const
00170 {
00171 if ( d_lowerBound != other.d_lowerBound ||
00172 d_upperBound != other.d_upperBound )
00173 {
00174 return false;
00175 }
00176
00177 for ( int i = 0; i < NTickTypes; i++ )
00178 {
00179 if ( d_ticks[i] != other.d_ticks[i] )
00180 return false;
00181 }
00182
00183 return true;
00184 }
00185
00190 bool QwtScaleDiv::operator!=( const QwtScaleDiv &other ) const
00191 {
00192 return ( !( *this == other ) );
00193 }
00194
00196 bool QwtScaleDiv::isEmpty() const
00197 {
00198 return ( d_lowerBound == d_upperBound );
00199 }
00200
00202 bool QwtScaleDiv::isIncreasing() const
00203 {
00204 return d_lowerBound <= d_upperBound;
00205 }
00206
00213 bool QwtScaleDiv::contains( double value ) const
00214 {
00215 const double min = qMin( d_lowerBound, d_upperBound );
00216 const double max = qMax( d_lowerBound, d_upperBound );
00217
00218 return value >= min && value <= max;
00219 }
00220
00225 void QwtScaleDiv::invert()
00226 {
00227 qSwap( d_lowerBound, d_upperBound );
00228
00229 for ( int i = 0; i < NTickTypes; i++ )
00230 {
00231 QList<double>& ticks = d_ticks[i];
00232
00233 const int size = ticks.count();
00234 const int size2 = size / 2;
00235
00236 for ( int j = 0; j < size2; j++ )
00237 qSwap( ticks[j], ticks[size - 1 - j] );
00238 }
00239 }
00240
00245 QwtScaleDiv QwtScaleDiv::inverted() const
00246 {
00247 QwtScaleDiv other = *this;
00248 other.invert();
00249
00250 return other;
00251 }
00252
00264 QwtScaleDiv QwtScaleDiv::bounded(
00265 double lowerBound, double upperBound ) const
00266 {
00267 const double min = qMin( lowerBound, upperBound );
00268 const double max = qMax( lowerBound, upperBound );
00269
00270 QwtScaleDiv sd;
00271 sd.setInterval( lowerBound, upperBound );
00272
00273 for ( int tickType = 0; tickType < QwtScaleDiv::NTickTypes; tickType++ )
00274 {
00275 const QList<double> &ticks = d_ticks[ tickType ];
00276
00277 QList<double> boundedTicks;
00278 for ( int i = 0; i < ticks.size(); i++ )
00279 {
00280 const double tick = ticks[i];
00281 if ( tick >= min && tick <= max )
00282 boundedTicks += tick;
00283 }
00284
00285 sd.setTicks( tickType, boundedTicks );
00286 }
00287
00288 return sd;
00289
00290 }
00291
00298 void QwtScaleDiv::setTicks( int type, const QList<double> &ticks )
00299 {
00300 if ( type >= 0 && type < NTickTypes )
00301 d_ticks[type] = ticks;
00302 }
00303
00310 QList<double> QwtScaleDiv::ticks( int type ) const
00311 {
00312 if ( type >= 0 && type < NTickTypes )
00313 return d_ticks[type];
00314
00315 return QList<double>();
00316 }
00317
00318 #ifndef QT_NO_DEBUG_STREAM
00319
00320 QDebug operator<<( QDebug debug, const QwtScaleDiv &scaleDiv )
00321 {
00322 debug << scaleDiv.lowerBound() << "<->" << scaleDiv.upperBound();
00323 debug << "Major: " << scaleDiv.ticks( QwtScaleDiv::MajorTick );
00324 debug << "Medium: " << scaleDiv.ticks( QwtScaleDiv::MediumTick );
00325 debug << "Minor: " << scaleDiv.ticks( QwtScaleDiv::MinorTick );
00326
00327 return debug;
00328 }
00329
00330 #endif
00331