Qwt User's Guide 6.2.0

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
22 class QWT_EXPORT QwtInterval
23 {
24 public:
29 enum BorderFlag
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
47 QwtInterval();
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
102 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
103 Q_DECLARE_METATYPE( QwtInterval )
104 Q_DECLARE_TYPEINFO( QwtInterval, Q_MOVABLE_TYPE );
105
112 inline QwtInterval::QwtInterval()
113 : m_minValue( 0.0 )
114 , m_maxValue( -1.0 )
115 , m_borderFlags( IncludeBorders )
116 {
117 }
118
128 inline QwtInterval::QwtInterval(
129 double minValue, double maxValue, BorderFlags borderFlags )
130 : m_minValue( minValue )
131 , m_maxValue( maxValue )
132 , m_borderFlags( borderFlags )
133 {
134 }
135
143 inline void QwtInterval::setInterval(
144 double minValue, double maxValue, BorderFlags borderFlags )
145 {
146 m_minValue = minValue;
147 m_maxValue = maxValue;
148 m_borderFlags = borderFlags;
149 }
150
157 inline void QwtInterval::setBorderFlags( BorderFlags borderFlags )
158 {
159 m_borderFlags = borderFlags;
160 }
161
166 inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
167 {
168 return m_borderFlags;
169 }
170
176 inline void QwtInterval::setMinValue( double minValue )
177 {
178 m_minValue = minValue;
179 }
180
186 inline void QwtInterval::setMaxValue( double maxValue )
187 {
188 m_maxValue = maxValue;
189 }
190
192 inline double QwtInterval::minValue() const
193 {
194 return m_minValue;
195 }
196
198 inline double QwtInterval::maxValue() const
199 {
200 return m_maxValue;
201 }
202
210 inline 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
227 inline double QwtInterval::width() const
228 {
229 return isValid() ? ( m_maxValue - m_minValue ) : 0.0;
230 }
231
241 inline 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
258 inline QwtInterval QwtInterval::operator&(
259 const QwtInterval& other ) const
260 {
261 return intersect( other );
262 }
263
272 inline QwtInterval QwtInterval::operator|(
273 const QwtInterval& other ) const
274 {
275 return unite( other );
276 }
277
284 inline 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 }
296 inline bool QwtInterval::operator!=( const QwtInterval& other ) const
297 {
298 return ( !( *this == other ) );
299 }
300
308 inline QwtInterval QwtInterval::operator|( double value ) const
309 {
310 return extend( value );
311 }
312
314 inline bool QwtInterval::isNull() const
315 {
316 return isValid() && m_minValue >= m_maxValue;
317 }
318
325 inline void QwtInterval::invalidate()
326 {
327 m_minValue = 0.0;
328 m_maxValue = -1.0;
329 }
330
331 #ifndef QT_NO_DEBUG_STREAM
332 QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval& );
333 #endif
334
335 #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