qwt_scale_div.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_scale_div.h"
#include "qwt_interval.h"
QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound )
: m_lowerBound( lowerBound )
, m_upperBound( upperBound )
{
}
QwtScaleDiv::QwtScaleDiv( const QwtInterval& interval,
QList< double > ticks[NTickTypes] )
: m_lowerBound( interval.minValue() )
, m_upperBound( interval.maxValue() )
{
for ( int i = 0; i < NTickTypes; i++ )
m_ticks[i] = ticks[i];
}
QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
QList< double > ticks[NTickTypes] )
: m_lowerBound( lowerBound )
, m_upperBound( upperBound )
{
for ( int i = 0; i < NTickTypes; i++ )
m_ticks[i] = ticks[i];
}
QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
const QList< double >& minorTicks,
const QList< double >& mediumTicks,
const QList< double >& majorTicks )
: m_lowerBound( lowerBound )
, m_upperBound( upperBound )
{
m_ticks[ MinorTick ] = minorTicks;
m_ticks[ MediumTick ] = mediumTicks;
m_ticks[ MajorTick ] = majorTicks;
}
void QwtScaleDiv::setInterval( double lowerBound, double upperBound )
{
m_lowerBound = lowerBound;
m_upperBound = upperBound;
}
void QwtScaleDiv::setInterval( const QwtInterval& interval )
{
m_lowerBound = interval.minValue();
m_upperBound = interval.maxValue();
}
QwtInterval QwtScaleDiv::interval() const
{
return QwtInterval( m_lowerBound, m_upperBound );
}
void QwtScaleDiv::setLowerBound( double lowerBound )
{
m_lowerBound = lowerBound;
}
double QwtScaleDiv::lowerBound() const
{
return m_lowerBound;
}
void QwtScaleDiv::setUpperBound( double upperBound )
{
m_upperBound = upperBound;
}
double QwtScaleDiv::upperBound() const
{
return m_upperBound;
}
double QwtScaleDiv::range() const
{
return m_upperBound - m_lowerBound;
}
bool QwtScaleDiv::operator==( const QwtScaleDiv& other ) const
{
if ( m_lowerBound != other.m_lowerBound ||
m_upperBound != other.m_upperBound )
{
return false;
}
for ( int i = 0; i < NTickTypes; i++ )
{
if ( m_ticks[i] != other.m_ticks[i] )
return false;
}
return true;
}
bool QwtScaleDiv::operator!=( const QwtScaleDiv& other ) const
{
return ( !( *this == other ) );
}
bool QwtScaleDiv::isEmpty() const
{
return ( m_lowerBound == m_upperBound );
}
bool QwtScaleDiv::isIncreasing() const
{
return m_lowerBound <= m_upperBound;
}
bool QwtScaleDiv::contains( double value ) const
{
const double min = qMin( m_lowerBound, m_upperBound );
const double max = qMax( m_lowerBound, m_upperBound );
return value >= min && value <= max;
}
void QwtScaleDiv::invert()
{
qSwap( m_lowerBound, m_upperBound );
for ( int i = 0; i < NTickTypes; i++ )
{
QList< double >& ticks = m_ticks[i];
const int size = ticks.count();
const int size2 = size / 2;
for ( int j = 0; j < size2; j++ )
qSwap( ticks[j], ticks[size - 1 - j] );
}
}
QwtScaleDiv QwtScaleDiv::inverted() const
{
QwtScaleDiv other = *this;
other.invert();
return other;
}
QwtScaleDiv QwtScaleDiv::bounded(
double lowerBound, double upperBound ) const
{
const double min = qMin( lowerBound, upperBound );
const double max = qMax( lowerBound, upperBound );
QwtScaleDiv sd;
sd.setInterval( lowerBound, upperBound );
for ( int tickType = 0; tickType < QwtScaleDiv::NTickTypes; tickType++ )
{
const QList< double >& ticks = m_ticks[ tickType ];
QList< double > boundedTicks;
for ( int i = 0; i < ticks.size(); i++ )
{
const double tick = ticks[i];
if ( tick >= min && tick <= max )
boundedTicks += tick;
}
sd.setTicks( tickType, boundedTicks );
}
return sd;
}
void QwtScaleDiv::setTicks( int tickType, const QList< double >& ticks )
{
if ( tickType >= 0 && tickType < NTickTypes )
m_ticks[tickType] = ticks;
}
QList< double > QwtScaleDiv::ticks( int tickType ) const
{
if ( tickType >= 0 && tickType < NTickTypes )
return m_ticks[tickType];
return QList< double >();
}
#ifndef QT_NO_DEBUG_STREAM
#include <qdebug.h>
QDebug operator<<( QDebug debug, const QwtScaleDiv& scaleDiv )
{
debug << scaleDiv.lowerBound() << "<->" << scaleDiv.upperBound();
debug << "Major: " << scaleDiv.ticks( QwtScaleDiv::MajorTick );
debug << "Medium: " << scaleDiv.ticks( QwtScaleDiv::MediumTick );
debug << "Minor: " << scaleDiv.ticks( QwtScaleDiv::MinorTick );
return debug;
}
#endif
QList< double >
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:23
QwtInterval::minValue
double minValue() const
Definition: qwt_interval.h:192
QwtInterval::maxValue
double maxValue() const
Definition: qwt_interval.h:198
QwtScaleDiv
A class representing a scale division.
Definition: qwt_scale_div.h:34
QwtScaleDiv::bounded
QwtScaleDiv bounded(double lowerBound, double upperBound) const
Definition: qwt_scale_div.cpp:263
QwtScaleDiv::lowerBound
double lowerBound() const
Definition: qwt_scale_div.cpp:131
QwtScaleDiv::invert
void invert()
Definition: qwt_scale_div.cpp:224
QwtScaleDiv::operator==
bool operator==(const QwtScaleDiv &) const
Equality operator.
Definition: qwt_scale_div.cpp:168
QwtScaleDiv::interval
QwtInterval interval() const
Definition: qwt_scale_div.cpp:111
QwtScaleDiv::range
double range() const
Definition: qwt_scale_div.cpp:159
QwtScaleDiv::upperBound
double upperBound() const
Definition: qwt_scale_div.cpp:151
QwtScaleDiv::setUpperBound
void setUpperBound(double)
Definition: qwt_scale_div.cpp:142
QwtScaleDiv::QwtScaleDiv
QwtScaleDiv(double lowerBound=0.0, double upperBound=0.0)
Definition: qwt_scale_div.cpp:21
QwtScaleDiv::operator!=
bool operator!=(const QwtScaleDiv &) const
Inequality.
Definition: qwt_scale_div.cpp:189
QwtScaleDiv::setLowerBound
void setLowerBound(double)
Definition: qwt_scale_div.cpp:122
QwtScaleDiv::ticks
QList< double > ticks(int tickType) const
Definition: qwt_scale_div.cpp:309
QwtScaleDiv::contains
bool contains(double value) const
Definition: qwt_scale_div.cpp:212
QwtScaleDiv::setInterval
void setInterval(double lowerBound, double upperBound)
Definition: qwt_scale_div.cpp:91
QwtScaleDiv::inverted
QwtScaleDiv inverted() const
Definition: qwt_scale_div.cpp:244
QwtScaleDiv::isEmpty
bool isEmpty() const
Check if the scale division is empty( lowerBound() == upperBound() )
Definition: qwt_scale_div.cpp:195
QwtScaleDiv::isIncreasing
bool isIncreasing() const
Check if the scale division is increasing( lowerBound() <= upperBound() )
Definition: qwt_scale_div.cpp:201
QwtScaleDiv::MediumTick
@ MediumTick
Medium ticks.
Definition: qwt_scale_div.h:46
QwtScaleDiv::MinorTick
@ MinorTick
Minor ticks.
Definition: qwt_scale_div.h:43
QwtScaleDiv::NTickTypes
@ NTickTypes
Number of valid tick types.
Definition: qwt_scale_div.h:52
QwtScaleDiv::MajorTick
@ MajorTick
Major ticks.
Definition: qwt_scale_div.h:49
QwtScaleDiv::setTicks
void setTicks(int tickType, const QList< double > &)
Definition: qwt_scale_div.cpp:297