All Classes Functions Variables Typedefs Enumerations Enumerator Pages
qwt_interval.h
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* 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>
#ifndef QT_NO_DEBUG_STREAM
#include <qdebug.h>
#endif
class QWT_EXPORT QwtInterval
{
public:
enum BorderFlag
{
IncludeBorders = 0x00,
ExcludeMinimum = 0x01,
ExcludeMaximum = 0x02,
ExcludeBorders = ExcludeMinimum | ExcludeMaximum
};
typedef QFlags<BorderFlag> BorderFlags;
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 minValue, double maxValue ) 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;
void setMinValue( double );
void setMaxValue( double );
bool contains( double value ) 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 d_minValue;
double d_maxValue;
BorderFlags d_borderFlags;
};
Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
inline QwtInterval::QwtInterval():
d_minValue( 0.0 ),
d_maxValue( -1.0 ),
d_borderFlags( IncludeBorders )
{
}
inline QwtInterval::QwtInterval(
double minValue, double maxValue, BorderFlags borderFlags ):
d_minValue( minValue ),
d_maxValue( maxValue ),
d_borderFlags( borderFlags )
{
}
inline void QwtInterval::setInterval(
double minValue, double maxValue, BorderFlags borderFlags )
{
d_minValue = minValue;
d_maxValue = maxValue;
d_borderFlags = borderFlags;
}
inline void QwtInterval::setBorderFlags( BorderFlags borderFlags )
{
d_borderFlags = borderFlags;
}
inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
{
return d_borderFlags;
}
inline void QwtInterval::setMinValue( double minValue )
{
d_minValue = minValue;
}
inline void QwtInterval::setMaxValue( double maxValue )
{
d_maxValue = maxValue;
}
inline double QwtInterval::minValue() const
{
return d_minValue;
}
inline double QwtInterval::maxValue() const
{
return d_maxValue;
}
inline bool QwtInterval::isValid() const
{
if ( ( d_borderFlags & ExcludeBorders ) == 0 )
return d_minValue <= d_maxValue;
else
return d_minValue < d_maxValue;
}
inline double QwtInterval::width() const
{
return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
}
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 ( d_minValue == other.d_minValue ) &&
( d_maxValue == other.d_maxValue ) &&
( d_borderFlags == other.d_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() && d_minValue >= d_maxValue;
}
inline void QwtInterval::invalidate()
{
d_minValue = 0.0;
d_maxValue = -1.0;
}
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
Q_DECLARE_METATYPE( QwtInterval )
#ifndef QT_NO_DEBUG_STREAM
QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );
#endif
#endif