Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_interval.h
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#ifndef QWT_INTERVAL_H
11#define QWT_INTERVAL_H
12
13#include "qwt_global.h"
14#include <qmetatype.h>
15
22class QWT_EXPORT QwtInterval
23{
24 public:
30 {
32 IncludeBorders = 0x00,
33
35 ExcludeMinimum = 0x01,
36
38 ExcludeMaximum = 0x02,
39
41 ExcludeBorders = ExcludeMinimum | ExcludeMaximum
42 };
43
45 Q_DECLARE_FLAGS( BorderFlags, BorderFlag )
46
48 QwtInterval( double minValue, double maxValue,
49 BorderFlags = IncludeBorders );
50
51 void setInterval( double minValue, double maxValue,
52 BorderFlags = IncludeBorders );
53
54 QwtInterval normalized() const;
55 QwtInterval inverted() const;
56 QwtInterval limited( double lowerBound, double upperBound ) const;
57
58 bool operator==( const QwtInterval& ) const;
59 bool operator!=( const QwtInterval& ) const;
60
61 void setBorderFlags( BorderFlags );
62 BorderFlags borderFlags() const;
63
64 double minValue() const;
65 double maxValue() const;
66
67 double width() const;
68 long double widthL() const;
69
70 void setMinValue( double );
71 void setMaxValue( double );
72
73 bool contains( double value ) const;
74 bool contains( const QwtInterval& ) const;
75
76 bool intersects( const QwtInterval& ) const;
77 QwtInterval intersect( const QwtInterval& ) const;
78 QwtInterval unite( const QwtInterval& ) const;
79
80 QwtInterval operator|( const QwtInterval& ) const;
81 QwtInterval operator&( const QwtInterval& ) const;
82
83 QwtInterval& operator|=( const QwtInterval& );
84 QwtInterval& operator&=( const QwtInterval& );
85
86 QwtInterval extend( double value ) const;
87 QwtInterval operator|( double ) const;
88 QwtInterval& operator|=( double );
89
90 bool isValid() const;
91 bool isNull() const;
92 void invalidate();
93
94 QwtInterval symmetrize( double value ) const;
95
96 private:
97 double m_minValue;
98 double m_maxValue;
99 BorderFlags m_borderFlags;
100};
101
102Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
103Q_DECLARE_METATYPE( QwtInterval )
104Q_DECLARE_TYPEINFO( QwtInterval, Q_MOVABLE_TYPE );
105
113 : m_minValue( 0.0 )
114 , m_maxValue( -1.0 )
115 , m_borderFlags( IncludeBorders )
116{
117}
118
129 double minValue, double maxValue, BorderFlags borderFlags )
130 : m_minValue( minValue )
131 , m_maxValue( maxValue )
132 , m_borderFlags( borderFlags )
133{
134}
135
144 double minValue, double maxValue, BorderFlags borderFlags )
145{
146 m_minValue = minValue;
147 m_maxValue = maxValue;
148 m_borderFlags = borderFlags;
149}
150
157inline void QwtInterval::setBorderFlags( BorderFlags borderFlags )
158{
159 m_borderFlags = borderFlags;
160}
161
167{
168 return m_borderFlags;
169}
170
176inline void QwtInterval::setMinValue( double minValue )
177{
178 m_minValue = minValue;
179}
180
186inline void QwtInterval::setMaxValue( double maxValue )
187{
188 m_maxValue = maxValue;
189}
190
192inline double QwtInterval::minValue() const
193{
194 return m_minValue;
195}
196
198inline double QwtInterval::maxValue() const
199{
200 return m_maxValue;
201}
202
210inline bool QwtInterval::isValid() const
211{
212 if ( ( m_borderFlags & ExcludeBorders ) == 0 )
213 return m_minValue <= m_maxValue;
214 else
215 return m_minValue < m_maxValue;
216}
217
227inline double QwtInterval::width() const
228{
229 return isValid() ? ( m_maxValue - m_minValue ) : 0.0;
230}
231
241inline long double QwtInterval::widthL() const
242{
243 if ( !isValid() )
244 return 0.0;
245
246 return static_cast< long double >( m_maxValue )
247 - static_cast< long double >( m_minValue );
248}
249
259 const QwtInterval& other ) const
260{
261 return intersect( other );
262}
263
273 const QwtInterval& other ) const
274{
275 return unite( other );
276}
277
284inline bool QwtInterval::operator==( const QwtInterval& other ) const
285{
286 return ( m_minValue == other.m_minValue ) &&
287 ( m_maxValue == other.m_maxValue ) &&
288 ( m_borderFlags == other.m_borderFlags );
289}
296inline bool QwtInterval::operator!=( const QwtInterval& other ) const
297{
298 return ( !( *this == other ) );
299}
300
308inline QwtInterval QwtInterval::operator|( double value ) const
309{
310 return extend( value );
311}
312
314inline bool QwtInterval::isNull() const
315{
316 return isValid() && m_minValue >= m_maxValue;
317}
318
326{
327 m_minValue = 0.0;
328 m_maxValue = -1.0;
329}
330
331#ifndef QT_NO_DEBUG_STREAM
332QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval& );
333#endif
334
335#endif
A class representing an interval.
void setInterval(double minValue, double maxValue, BorderFlags=IncludeBorders)
double minValue() const
QwtInterval operator|(const QwtInterval &) const
double width() const
Return the width of an interval.
@ ExcludeBorders
Min/Max values are not included in the interval.
long double widthL() const
Return the width of an interval as long double.
void setMaxValue(double)
double maxValue() const
QwtInterval unite(const QwtInterval &) const
Unite 2 intervals.
void invalidate()
bool operator==(const QwtInterval &) const
Compare two intervals.
bool operator!=(const QwtInterval &) const
Compare two intervals.
QwtInterval operator&(const QwtInterval &) const
Intersection of two intervals.
QwtInterval extend(double value) const
Extend the interval.
void setMinValue(double)
QwtInterval intersect(const QwtInterval &) const
Intersect 2 intervals.
BorderFlags borderFlags() const
bool isNull() const
QwtInterval()
Default Constructor.
void setBorderFlags(BorderFlags)
bool isValid() const
QFlags< BorderFlag > BorderFlags
Border flags.