qwt_scale_div.cpp

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 #include "qwt_scale_div.h"
00011 #include "qwt_math.h"
00012 #include "qwt_double_interval.h"
00013 
00015 QwtScaleDiv::QwtScaleDiv():
00016     d_lBound(0.0),
00017     d_hBound(0.0),
00018     d_isValid(false)
00019 {
00020 }
00021 
00028 QwtScaleDiv::QwtScaleDiv(
00029         const QwtDoubleInterval &interval, 
00030         QwtValueList ticks[NTickTypes]):
00031     d_lBound(interval.minValue()),
00032     d_hBound(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 lBound, double hBound,
00048         QwtValueList ticks[NTickTypes]):
00049     d_lBound(lBound),
00050     d_hBound(hBound),
00051     d_isValid(true)
00052 {
00053     for ( int i = 0; i < NTickTypes; i++ )
00054         d_ticks[i] = ticks[i];
00055 }
00056 
00061 int QwtScaleDiv::operator==(const QwtScaleDiv &other) const
00062 {
00063     if ( d_lBound != other.d_lBound ||
00064         d_hBound != other.d_hBound ||
00065         d_isValid != other.d_isValid )
00066     {
00067         return false;
00068     }
00069 
00070     for ( int i = 0; i < NTickTypes; i++ )
00071     {
00072         if ( d_ticks[i] != other.d_ticks[i] )
00073             return false;
00074     }
00075 
00076     return true;
00077 }
00078 
00083 int QwtScaleDiv::operator!=(const QwtScaleDiv &s) const
00084 {
00085     return (!(*this == s));
00086 }
00087 
00089 void QwtScaleDiv::invalidate()
00090 {
00091     d_isValid = false;
00092 
00093     // detach arrays
00094     for ( int i = 0; i < NTickTypes; i++ )
00095         d_ticks[i].clear();
00096 
00097     d_lBound = d_hBound = 0;
00098 }
00099 
00101 bool QwtScaleDiv::isValid() const
00102 {
00103     return d_isValid;
00104 }
00105 
00106 bool QwtScaleDiv::contains(double v) const
00107 {
00108     if ( !d_isValid )
00109         return false;
00110 
00111     const double min = qwtMin(d_lBound, d_hBound);
00112     const double max = qwtMax(d_lBound, d_hBound);
00113 
00114     return v >= min && v <= max;
00115 }
00116 
00118 void QwtScaleDiv::invert()
00119 {
00120     qSwap(d_lBound, d_hBound);
00121 
00122     for ( int i = 0; i < NTickTypes; i++ )
00123     {
00124         QwtValueList& ticks = d_ticks[i];
00125 
00126         const int size = ticks.count();
00127         const int size2 = size / 2;
00128  
00129         for (int i=0; i < size2; i++)
00130             qSwap(ticks[i], ticks[size - 1 - i]);
00131     }
00132 }
00133 
00139 const QwtValueList &QwtScaleDiv::ticks(int type) const
00140 {
00141     if ( type >= 0 || type < NTickTypes )
00142         return d_ticks[type];
00143 
00144     static QwtValueList noTicks;
00145     return noTicks;
00146 }

Generated on Mon Feb 26 21:22:38 2007 for Qwt User's Guide by  doxygen 1.4.6