Qwt User's Guide: qwt_scale_div.cpp Source File

- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# 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 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_lBound != other.d_lBound ||
    00073         d_hBound != other.d_hBound ||
    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     // detach arrays
    00103     for ( int i = 0; i < NTickTypes; i++ )
    00104         d_ticks[i].clear();
    00105
    00106     d_lBound = d_hBound = 0;
    00107 }
    00108
    00110 bool QwtScaleDiv::isValid() const
    00111 {
    00112     return d_isValid;
    00113 }
    00114
    00115 bool QwtScaleDiv::contains(double v) const
    00116 {
    00117     if ( !d_isValid )
    00118         return false;
    00119
    00120     const double min = qwtMin(d_lBound, d_hBound);
    00121     const double max = qwtMax(d_lBound, d_hBound);
    00122
    00123     return v >= min && v <= max;
    00124 }
    00125
    00127 void QwtScaleDiv::invert()
    00128 {
    00129     qSwap(d_lBound, d_hBound);
    00130
    00131     for ( int i = 0; i < NTickTypes; i++ )
    00132     {
    00133         QwtValueList& ticks = d_ticks[i];
    00134
    00135         const int size = ticks.count();
    00136         const int size2 = size / 2;
    00137
    00138         for (int i=0; i < size2; i++)
    00139             qSwap(ticks[i], ticks[size - 1 - i]);
    00140     }
    00141 }
    00142
    00149 void QwtScaleDiv::setTicks(int type, const QwtValueList &ticks)
    00150 {
    00151     if ( type >= 0 || type < NTickTypes )
    00152         d_ticks[type] = ticks;
    00153 }
    00154
    00160 const QwtValueList &QwtScaleDiv::ticks(int type) const
    00161 {
    00162     if ( type >= 0 || type < NTickTypes )
    00163         return d_ticks[type];
    00164
    00165     static QwtValueList noTicks;
    00166     return noTicks;
    00167 }