Loading...
Searching...
No Matches
qwt_interval.h
/******************************************************************************
* 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
*****************************************************************************/
#ifndef QWT_INTERVAL_H
#define QWT_INTERVAL_H
#include "qwt_global.h"
#include <qmetatype.h>
class QWT_EXPORT QwtInterval
{
public:
enum BorderFlag
{
IncludeBorders = 0x00,
ExcludeMinimum = 0x01,
ExcludeMaximum = 0x02,
ExcludeBorders = ExcludeMinimum | ExcludeMaximum
};
Q_DECLARE_FLAGS( BorderFlags, BorderFlag )
QwtInterval();
QwtInterval( double minValue, double maxValue,
BorderFlags = IncludeBorders );
void setInterval( double minValue, double maxValue,
BorderFlags = IncludeBorders );
QwtInterval normalized() const;
QwtInterval inverted() const;
QwtInterval limited( double lowerBound, double upperBound ) const;
bool operator==( const QwtInterval& ) const;
bool operator!=( const QwtInterval& ) const;
void setBorderFlags( BorderFlags );
BorderFlags borderFlags() const;
double minValue() const;
double maxValue() const;
double width() const;
long double widthL() const;
void setMinValue( double );
void setMaxValue( double );
bool contains( double value ) const;
bool contains( const QwtInterval& ) const;
bool intersects( const QwtInterval& ) const;
QwtInterval intersect( const QwtInterval& ) const;
QwtInterval unite( const QwtInterval& ) const;
QwtInterval operator|( const QwtInterval& ) const;
QwtInterval operator&( const QwtInterval& ) const;
QwtInterval& operator|=( const QwtInterval& );
QwtInterval& operator&=( const QwtInterval& );
QwtInterval extend( double value ) const;
QwtInterval operator|( double ) const;
QwtInterval& operator|=( double );
bool isValid() const;
bool isNull() const;
void invalidate();
QwtInterval symmetrize( double value ) const;
private:
double m_minValue;
double m_maxValue;
BorderFlags m_borderFlags;
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
Q_DECLARE_METATYPE( QwtInterval )
Q_DECLARE_TYPEINFO( QwtInterval, Q_MOVABLE_TYPE );
inline QwtInterval::QwtInterval()
: m_minValue( 0.0 )
, m_maxValue( -1.0 )
, m_borderFlags( IncludeBorders )
{
}
inline QwtInterval::QwtInterval(
double minValue, double maxValue, BorderFlags borderFlags )
: m_minValue( minValue )
, m_maxValue( maxValue )
, m_borderFlags( borderFlags )
{
}
inline void QwtInterval::setInterval(
double minValue, double maxValue, BorderFlags borderFlags )
{
m_minValue = minValue;
m_maxValue = maxValue;
m_borderFlags = borderFlags;
}
inline void QwtInterval::setBorderFlags( BorderFlags borderFlags )
{
m_borderFlags = borderFlags;
}
inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
{
return m_borderFlags;
}
inline void QwtInterval::setMinValue( double minValue )
{
m_minValue = minValue;
}
inline void QwtInterval::setMaxValue( double maxValue )
{
m_maxValue = maxValue;
}
inline double QwtInterval::minValue() const
{
return m_minValue;
}
inline double QwtInterval::maxValue() const
{
return m_maxValue;
}
inline bool QwtInterval::isValid() const
{
if ( ( m_borderFlags & ExcludeBorders ) == 0 )
return m_minValue <= m_maxValue;
else
return m_minValue < m_maxValue;
}
inline double QwtInterval::width() const
{
return isValid() ? ( m_maxValue - m_minValue ) : 0.0;
}
inline long double QwtInterval::widthL() const
{
if ( !isValid() )
return 0.0;
return static_cast< long double >( m_maxValue )
- static_cast< long double >( m_minValue );
}
inline QwtInterval QwtInterval::operator&(
const QwtInterval& other ) const
{
return intersect( other );
}
inline QwtInterval QwtInterval::operator|(
const QwtInterval& other ) const
{
return unite( other );
}
inline bool QwtInterval::operator==( const QwtInterval& other ) const
{
return ( m_minValue == other.m_minValue ) &&
( m_maxValue == other.m_maxValue ) &&
( m_borderFlags == other.m_borderFlags );
}
inline bool QwtInterval::operator!=( const QwtInterval& other ) const
{
return ( !( *this == other ) );
}
inline QwtInterval QwtInterval::operator|( double value ) const
{
return extend( value );
}
inline bool QwtInterval::isNull() const
{
return isValid() && m_minValue >= m_maxValue;
}
inline void QwtInterval::invalidate()
{
m_minValue = 0.0;
m_maxValue = -1.0;
}
#ifndef QT_NO_DEBUG_STREAM
QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval& );
#endif
#endif
QwtInterval
A class representing an interval.
Definition qwt_interval.h:23
QwtInterval::setInterval
void setInterval(double minValue, double maxValue, BorderFlags=IncludeBorders)
Definition qwt_interval.h:143
QwtInterval::minValue
double minValue() const
Definition qwt_interval.h:192
QwtInterval::operator|
QwtInterval operator|(const QwtInterval &) const
Definition qwt_interval.h:272
QwtInterval::width
double width() const
Return the width of an interval.
Definition qwt_interval.h:227
QwtInterval::BorderFlag
BorderFlag
Definition qwt_interval.h:30
QwtInterval::ExcludeBorders
@ ExcludeBorders
Min/Max values are not included in the interval.
Definition qwt_interval.h:41
QwtInterval::widthL
long double widthL() const
Return the width of an interval as long double.
Definition qwt_interval.h:241
QwtInterval::setMaxValue
void setMaxValue(double)
Definition qwt_interval.h:186
QwtInterval::maxValue
double maxValue() const
Definition qwt_interval.h:198
QwtInterval::unite
QwtInterval unite(const QwtInterval &) const
Unite 2 intervals.
Definition qwt_interval.cpp:123
QwtInterval::invalidate
void invalidate()
Definition qwt_interval.h:325
QwtInterval::operator==
bool operator==(const QwtInterval &) const
Compare two intervals.
Definition qwt_interval.h:284
QwtInterval::operator!=
bool operator!=(const QwtInterval &) const
Compare two intervals.
Definition qwt_interval.h:296
QwtInterval::operator&
QwtInterval operator&(const QwtInterval &) const
Intersection of two intervals.
Definition qwt_interval.h:258
QwtInterval::extend
QwtInterval extend(double value) const
Extend the interval.
Definition qwt_interval.cpp:363
QwtInterval::setMinValue
void setMinValue(double)
Definition qwt_interval.h:176
QwtInterval::intersect
QwtInterval intersect(const QwtInterval &) const
Intersect 2 intervals.
Definition qwt_interval.cpp:186
QwtInterval::borderFlags
BorderFlags borderFlags() const
Definition qwt_interval.h:166
QwtInterval::isNull
bool isNull() const
Definition qwt_interval.h:314
QwtInterval::QwtInterval
QwtInterval()
Default Constructor.
Definition qwt_interval.h:112
QwtInterval::setBorderFlags
void setBorderFlags(BorderFlags)
Definition qwt_interval.h:157
QwtInterval::isValid
bool isValid() const
Definition qwt_interval.h:210
QwtInterval::BorderFlags
QFlags< BorderFlag > BorderFlags
Border flags.
Definition qwt_interval.h:45