Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_scale_div.cpp


Ignore:
Timestamp:
May 10, 2017, 3:20:54 PM (7 years ago)
Author:
stoecker
Message:

update qwt and qwtpolar, many QT5 fixes (unfinished)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_scale_div.cpp

    r4271 r8127  
    1010#include "qwt_scale_div.h"
    1111#include "qwt_math.h"
    12 #include "qwt_interval.h"
    1312#include <qalgorithms.h>
    1413
    15 //! Construct an invalid QwtScaleDiv instance.
    16 QwtScaleDiv::QwtScaleDiv():
    17     d_lowerBound( 0.0 ),
    18     d_upperBound( 0.0 ),
    19     d_isValid( false )
    20 {
    21 }
    22 
    23 /*!
    24   Construct QwtScaleDiv instance.
     14/*!
     15  Construct a division without ticks
     16
     17  \param lowerBound First boundary
     18  \param upperBound Second boundary
     19
     20  \note lowerBound might be greater than upperBound for inverted scales
     21 */
     22QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound ):
     23    d_lowerBound( lowerBound ),
     24    d_upperBound( upperBound )
     25{
     26}
     27
     28/*!
     29  Construct a scale division
    2530
    2631  \param interval Interval
     
    3035        QList<double> ticks[NTickTypes] ):
    3136    d_lowerBound( interval.minValue() ),
    32     d_upperBound( interval.maxValue() ),
    33     d_isValid( true )
     37    d_upperBound( interval.maxValue() )
    3438{
    3539    for ( int i = 0; i < NTickTypes; i++ )
     
    3842
    3943/*!
    40   Construct QwtScaleDiv instance.
    41 
    42   \param lowerBound First interval limit
    43   \param upperBound Second interval limit
     44  Construct a scale division
     45
     46  \param lowerBound First boundary
     47  \param upperBound Second boundary
    4448  \param ticks List of major, medium and minor ticks
    45 */
    46 QwtScaleDiv::QwtScaleDiv(
    47         double lowerBound, double upperBound,
     49
     50  \note lowerBound might be greater than upperBound for inverted scales
     51*/
     52QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
    4853        QList<double> ticks[NTickTypes] ):
    4954    d_lowerBound( lowerBound ),
    50     d_upperBound( upperBound ),
    51     d_isValid( true )
     55    d_upperBound( upperBound )
    5256{
    5357    for ( int i = 0; i < NTickTypes; i++ )
     
    5660
    5761/*!
     62  Construct a scale division
     63
     64  \param lowerBound First boundary
     65  \param upperBound Second boundary
     66  \param minorTicks List of minor ticks
     67  \param mediumTicks List medium ticks
     68  \param majorTicks List of major ticks
     69
     70  \note lowerBound might be greater than upperBound for inverted scales
     71*/
     72QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
     73        const QList<double> &minorTicks,
     74        const QList<double> &mediumTicks,
     75        const QList<double> &majorTicks ):
     76    d_lowerBound( lowerBound ),
     77    d_upperBound( upperBound )
     78{
     79    d_ticks[ MinorTick ] = minorTicks;
     80    d_ticks[ MediumTick ] = mediumTicks;
     81    d_ticks[ MajorTick ] = majorTicks;
     82}
     83
     84/*!
     85  Change the interval
     86
     87  \param lowerBound First boundary
     88  \param upperBound Second boundary
     89
     90  \note lowerBound might be greater than upperBound for inverted scales
     91*/
     92void QwtScaleDiv::setInterval( double lowerBound, double upperBound )
     93{
     94    d_lowerBound = lowerBound;
     95    d_upperBound = upperBound;
     96}
     97
     98/*!
    5899   Change the interval
     100
    59101   \param interval Interval
    60102*/
    61103void QwtScaleDiv::setInterval( const QwtInterval &interval )
    62104{
    63     setInterval( interval.minValue(), interval.maxValue() );
     105    d_lowerBound = interval.minValue();
     106    d_upperBound = interval.maxValue();
     107}
     108
     109/*!
     110  \return lowerBound -> upperBound
     111*/
     112QwtInterval QwtScaleDiv::interval() const
     113{
     114    return QwtInterval( d_lowerBound, d_upperBound );
     115}
     116
     117/*!
     118  Set the first boundary
     119
     120  \param lowerBound First boundary
     121  \sa lowerBiound(), setUpperBound()
     122 */
     123void QwtScaleDiv::setLowerBound( double lowerBound  )
     124{
     125    d_lowerBound = lowerBound;
     126}
     127
     128/*!
     129  \return First boundary
     130  \sa upperBound()
     131*/
     132double QwtScaleDiv::lowerBound() const
     133{
     134    return d_lowerBound;
     135}   
     136
     137/*!
     138  Set the second boundary
     139
     140  \param upperBound Second boundary
     141  \sa upperBound(), setLowerBound()
     142 */
     143void QwtScaleDiv::setUpperBound( double upperBound  )
     144{
     145    d_upperBound = upperBound;
     146}
     147
     148/*!
     149  \return upper bound
     150  \sa lowerBound()
     151*/
     152double QwtScaleDiv::upperBound() const
     153{
     154    return d_upperBound;
     155}
     156
     157/*!
     158  \return upperBound() - lowerBound()
     159*/
     160double QwtScaleDiv::range() const
     161{
     162    return d_upperBound - d_lowerBound;
    64163}
    65164
     
    71170{
    72171    if ( d_lowerBound != other.d_lowerBound ||
    73         d_upperBound != other.d_upperBound ||
    74         d_isValid != other.d_isValid )
     172        d_upperBound != other.d_upperBound )
    75173    {
    76174        return false;
     
    88186/*!
    89187  \brief Inequality
    90   \return true if this instance is not equal to s
    91 */
    92 bool QwtScaleDiv::operator!=( const QwtScaleDiv &s ) const
    93 {
    94     return ( !( *this == s ) );
    95 }
    96 
    97 //! Invalidate the scale division
    98 void QwtScaleDiv::invalidate()
    99 {
    100     d_isValid = false;
    101 
    102     // detach arrays
    103     for ( int i = 0; i < NTickTypes; i++ )
    104         d_ticks[i].clear();
    105 
    106     d_lowerBound = d_upperBound = 0;
    107 }
    108 
    109 //! Check if the scale division is valid
    110 bool QwtScaleDiv::isValid() const
    111 {
    112     return d_isValid;
     188  \return true if this instance is not equal to other
     189*/
     190bool QwtScaleDiv::operator!=( const QwtScaleDiv &other ) const
     191{
     192    return ( !( *this == other ) );
     193}
     194
     195//! Check if the scale division is empty( lowerBound() == upperBound() )
     196bool QwtScaleDiv::isEmpty() const
     197{
     198    return ( d_lowerBound == d_upperBound );
     199}
     200
     201//! Check if the scale division is increasing( lowerBound() <= upperBound() )
     202bool QwtScaleDiv::isIncreasing() const
     203{
     204    return d_lowerBound <= d_upperBound;
    113205}
    114206
     
    121213bool QwtScaleDiv::contains( double value ) const
    122214{
    123     if ( !d_isValid )
    124         return false;
    125 
    126215    const double min = qMin( d_lowerBound, d_upperBound );
    127216    const double max = qMax( d_lowerBound, d_upperBound );
     
    130219}
    131220
    132 //! Invert the scale divison
     221/*!
     222   Invert the scale division
     223   \sa inverted()
     224 */
    133225void QwtScaleDiv::invert()
    134226{
     
    142234        const int size2 = size / 2;
    143235
    144         for ( int i = 0; i < size2; i++ )
    145             qSwap( ticks[i], ticks[size - 1 - i] );
     236        for ( int j = 0; j < size2; j++ )
     237            qSwap( ticks[j], ticks[size - 1 - j] );
    146238    }
     239}
     240
     241/*!
     242  \return A scale division with inverted boundaries and ticks
     243  \sa invert()
     244 */
     245QwtScaleDiv QwtScaleDiv::inverted() const
     246{
     247    QwtScaleDiv other = *this;
     248    other.invert();
     249
     250    return other;
     251}
     252
     253/*!
     254   Return a scale division with an interval [lowerBound, upperBound]
     255   where all ticks outside this interval are removed
     256
     257   \param lowerBound Lower bound
     258   \param upperBound Upper bound
     259
     260   \return Scale division with all ticks inside of the given interval
     261
     262   \note lowerBound might be greater than upperBound for inverted scales
     263*/
     264QwtScaleDiv QwtScaleDiv::bounded(
     265    double lowerBound, double upperBound ) const
     266{
     267    const double min = qMin( lowerBound, upperBound );
     268    const double max = qMax( lowerBound, upperBound );
     269
     270    QwtScaleDiv sd;
     271    sd.setInterval( lowerBound, upperBound );
     272
     273    for ( int tickType = 0; tickType < QwtScaleDiv::NTickTypes; tickType++ )
     274    {
     275        const QList<double> &ticks = d_ticks[ tickType ];
     276
     277        QList<double> boundedTicks;
     278        for ( int i = 0; i < ticks.size(); i++ )
     279        {
     280            const double tick = ticks[i];
     281            if ( tick >= min && tick <= max )
     282                boundedTicks += tick;
     283        }
     284
     285        sd.setTicks( tickType, boundedTicks );
     286    }
     287
     288    return sd;
     289
    147290}
    148291
     
    155298void QwtScaleDiv::setTicks( int type, const QList<double> &ticks )
    156299{
    157     if ( type >= 0 || type < NTickTypes )
     300    if ( type >= 0 && type < NTickTypes )
    158301        d_ticks[type] = ticks;
    159302}
     
    163306
    164307   \param type MinorTick, MediumTick or MajorTick
    165 */
    166 const QList<double> &QwtScaleDiv::ticks( int type ) const
    167 {
    168     if ( type >= 0 || type < NTickTypes )
     308   \return Tick list
     309*/
     310QList<double> QwtScaleDiv::ticks( int type ) const
     311{
     312    if ( type >= 0 && type < NTickTypes )
    169313        return d_ticks[type];
    170314
    171     static QList<double> noTicks;
    172     return noTicks;
    173 }
     315    return QList<double>();
     316}
     317
     318#ifndef QT_NO_DEBUG_STREAM
     319
     320QDebug operator<<( QDebug debug, const QwtScaleDiv &scaleDiv )
     321{
     322    debug << scaleDiv.lowerBound() << "<->" << scaleDiv.upperBound();
     323    debug << "Major: " << scaleDiv.ticks( QwtScaleDiv::MajorTick );
     324    debug << "Medium: " << scaleDiv.ticks( QwtScaleDiv::MediumTick );
     325    debug << "Minor: " << scaleDiv.ticks( QwtScaleDiv::MinorTick );
     326
     327    return debug;
     328}
     329
     330#endif
     331
Note: See TracChangeset for help on using the changeset viewer.