地面站终端 App
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

332 lines
7.4 KiB

15 years ago
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
15 years ago
* 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_math.h"
#include <qalgorithms.h>
15 years ago
/*!
Construct a division without ticks
\param lowerBound First boundary
\param upperBound Second boundary
\note lowerBound might be greater than upperBound for inverted scales
*/
QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound ):
d_lowerBound( lowerBound ),
d_upperBound( upperBound )
15 years ago
{
}
/*!
Construct a scale division
15 years ago
\param interval Interval
\param ticks List of major, medium and minor ticks
*/
QwtScaleDiv::QwtScaleDiv( const QwtInterval &interval,
QList<double> ticks[NTickTypes] ):
d_lowerBound( interval.minValue() ),
d_upperBound( interval.maxValue() )
15 years ago
{
for ( int i = 0; i < NTickTypes; i++ )
d_ticks[i] = ticks[i];
}
/*!
Construct a scale division
15 years ago
\param lowerBound First boundary
\param upperBound Second boundary
15 years ago
\param ticks List of major, medium and minor ticks
\note lowerBound might be greater than upperBound for inverted scales
15 years ago
*/
QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
QList<double> ticks[NTickTypes] ):
d_lowerBound( lowerBound ),
d_upperBound( upperBound )
15 years ago
{
for ( int i = 0; i < NTickTypes; i++ )
d_ticks[i] = ticks[i];
}
/*!
Construct a scale division
\param lowerBound First boundary
\param upperBound Second boundary
\param minorTicks List of minor ticks
\param mediumTicks List medium ticks
\param majorTicks List of major ticks
\note lowerBound might be greater than upperBound for inverted scales
*/
QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
const QList<double> &minorTicks,
const QList<double> &mediumTicks,
const QList<double> &majorTicks ):
d_lowerBound( lowerBound ),
d_upperBound( upperBound )
{
d_ticks[ MinorTick ] = minorTicks;
d_ticks[ MediumTick ] = mediumTicks;
d_ticks[ MajorTick ] = majorTicks;
}
/*!
Change the interval
\param lowerBound First boundary
\param upperBound Second boundary
\note lowerBound might be greater than upperBound for inverted scales
*/
void QwtScaleDiv::setInterval( double lowerBound, double upperBound )
{
d_lowerBound = lowerBound;
d_upperBound = upperBound;
}
/*!
15 years ago
Change the interval
\param interval Interval
*/
void QwtScaleDiv::setInterval( const QwtInterval &interval )
{
d_lowerBound = interval.minValue();
d_upperBound = interval.maxValue();
}
/*!
\return lowerBound -> upperBound
*/
QwtInterval QwtScaleDiv::interval() const
{
return QwtInterval( d_lowerBound, d_upperBound );
}
/*!
Set the first boundary
\param lowerBound First boundary
\sa lowerBiound(), setUpperBound()
*/
void QwtScaleDiv::setLowerBound( double lowerBound )
{
d_lowerBound = lowerBound;
}
/*!
\return First boundary
\sa upperBound()
*/
double QwtScaleDiv::lowerBound() const
{
return d_lowerBound;
}
/*!
Set the second boundary
\param upperBound Second boundary
\sa upperBound(), setLowerBound()
*/
void QwtScaleDiv::setUpperBound( double upperBound )
{
d_upperBound = upperBound;
}
/*!
\return upper bound
\sa lowerBound()
*/
double QwtScaleDiv::upperBound() const
{
return d_upperBound;
}
/*!
\return upperBound() - lowerBound()
15 years ago
*/
double QwtScaleDiv::range() const
15 years ago
{
return d_upperBound - d_lowerBound;
15 years ago
}
/*!
\brief Equality operator
\return true if this instance is equal to other
*/
bool QwtScaleDiv::operator==( const QwtScaleDiv &other ) const
15 years ago
{
if ( d_lowerBound != other.d_lowerBound ||
d_upperBound != other.d_upperBound )
{
15 years ago
return false;
}
for ( int i = 0; i < NTickTypes; i++ )
{
15 years ago
if ( d_ticks[i] != other.d_ticks[i] )
return false;
}
return true;
}
/*!
\brief Inequality
\return true if this instance is not equal to other
15 years ago
*/
bool QwtScaleDiv::operator!=( const QwtScaleDiv &other ) const
15 years ago
{
return ( !( *this == other ) );
15 years ago
}
//! Check if the scale division is empty( lowerBound() == upperBound() )
bool QwtScaleDiv::isEmpty() const
15 years ago
{
return ( d_lowerBound == d_upperBound );
15 years ago
}
//! Check if the scale division is increasing( lowerBound() <= upperBound() )
bool QwtScaleDiv::isIncreasing() const
15 years ago
{
return d_lowerBound <= d_upperBound;
15 years ago
}
/*!
Return if a value is between lowerBound() and upperBound()
15 years ago
\param value Value
\return true/false
*/
bool QwtScaleDiv::contains( double value ) const
{
const double min = qMin( d_lowerBound, d_upperBound );
const double max = qMax( d_lowerBound, d_upperBound );
15 years ago
return value >= min && value <= max;
15 years ago
}
/*!
Invert the scale division
\sa inverted()
*/
15 years ago
void QwtScaleDiv::invert()
{
qSwap( d_lowerBound, d_upperBound );
15 years ago
for ( int i = 0; i < NTickTypes; i++ )
{
QList<double>& ticks = d_ticks[i];
15 years ago
const int size = ticks.count();
const int size2 = size / 2;
for ( int j = 0; j < size2; j++ )
qSwap( ticks[j], ticks[size - 1 - j] );
15 years ago
}
}
/*!
\return A scale division with inverted boundaries and ticks
\sa invert()
*/
QwtScaleDiv QwtScaleDiv::inverted() const
{
QwtScaleDiv other = *this;
other.invert();
return other;
}
/*!
Return a scale division with an interval [lowerBound, upperBound]
where all ticks outside this interval are removed
\param lowerBound Lower bound
\param upperBound Upper bound
\return Scale division with all ticks inside of the given interval
\note lowerBound might be greater than upperBound for inverted scales
*/
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 = d_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;
}
15 years ago
/*!
Assign ticks
\param type MinorTick, MediumTick or MajorTick
\param ticks Values of the tick positions
*/
void QwtScaleDiv::setTicks( int type, const QList<double> &ticks )
15 years ago
{
if ( type >= 0 && type < NTickTypes )
15 years ago
d_ticks[type] = ticks;
}
/*!
Return a list of ticks
\param type MinorTick, MediumTick or MajorTick
\return Tick list
15 years ago
*/
QList<double> QwtScaleDiv::ticks( int type ) const
15 years ago
{
if ( type >= 0 && type < NTickTypes )
15 years ago
return d_ticks[type];
return QList<double>();
}
#ifndef QT_NO_DEBUG_STREAM
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;
15 years ago
}
#endif