Qwt User's Guide 6.0.2

- Main Page
- Related Pages
- Classes

qwt_interval.h
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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 #ifndef QT_NO_DEBUG_STREAM
15 #include <qdebug.h>
16 #endif
17
24 class QWT_EXPORT QwtInterval
25 {
26 public:
31 enum BorderFlag
32 {
34 IncludeBorders = 0x00,
35
37 ExcludeMinimum = 0x01,
38
40 ExcludeMaximum = 0x02,
41
43 ExcludeBorders = ExcludeMinimum | ExcludeMaximum
44 };
45
47 typedef QFlags<BorderFlag> BorderFlags;
48
49 QwtInterval();
50 QwtInterval( double minValue, double maxValue,
51 BorderFlags = IncludeBorders );
52
53 void setInterval( double minValue, double maxValue,
54 BorderFlags = IncludeBorders );
55
56 QwtInterval normalized() const;
57 QwtInterval inverted() const;
58 QwtInterval limited( double minValue, double maxValue ) const;
59
60 bool operator==( const QwtInterval & ) const;
61 bool operator!=( const QwtInterval & ) const;
62
63 void setBorderFlags( BorderFlags );
64 BorderFlags borderFlags() const;
65
66 double minValue() const;
67 double maxValue() const;
68
69 double width() const;
70
71 void setMinValue( double );
72 void setMaxValue( double );
73
74 bool contains( double value ) 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 d_minValue;
98 double d_maxValue;
99 BorderFlags d_borderFlags;
100 };
101
102 Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
103
110 inline QwtInterval::QwtInterval():
111 d_minValue( 0.0 ),
112 d_maxValue( -1.0 ),
113 d_borderFlags( IncludeBorders )
114 {
115 }
116
126 inline QwtInterval::QwtInterval(
127 double minValue, double maxValue, BorderFlags borderFlags ):
128 d_minValue( minValue ),
129 d_maxValue( maxValue ),
130 d_borderFlags( borderFlags )
131 {
132 }
133
141 inline void QwtInterval::setInterval(
142 double minValue, double maxValue, BorderFlags borderFlags )
143 {
144 d_minValue = minValue;
145 d_maxValue = maxValue;
146 d_borderFlags = borderFlags;
147 }
148
155 inline void QwtInterval::setBorderFlags( BorderFlags borderFlags )
156 {
157 d_borderFlags = borderFlags;
158 }
159
164 inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
165 {
166 return d_borderFlags;
167 }
168
174 inline void QwtInterval::setMinValue( double minValue )
175 {
176 d_minValue = minValue;
177 }
178
184 inline void QwtInterval::setMaxValue( double maxValue )
185 {
186 d_maxValue = maxValue;
187 }
188
190 inline double QwtInterval::minValue() const
191 {
192 return d_minValue;
193 }
194
196 inline double QwtInterval::maxValue() const
197 {
198 return d_maxValue;
199 }
200
206 inline bool QwtInterval::isValid() const
207 {
208 if ( ( d_borderFlags & ExcludeBorders ) == 0 )
209 return d_minValue <= d_maxValue;
210 else
211 return d_minValue < d_maxValue;
212 }
213
221 inline double QwtInterval::width() const
222 {
223 return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
224 }
225
230 inline QwtInterval QwtInterval::operator&(
231 const QwtInterval &interval ) const
232 {
233 return intersect( interval );
234 }
235
240 inline QwtInterval QwtInterval::operator|(
241 const QwtInterval &interval ) const
242 {
243 return unite( interval );
244 }
245
247 inline bool QwtInterval::operator==( const QwtInterval &other ) const
248 {
249 return ( d_minValue == other.d_minValue ) &&
250 ( d_maxValue == other.d_maxValue ) &&
251 ( d_borderFlags == other.d_borderFlags );
252 }
253
255 inline bool QwtInterval::operator!=( const QwtInterval &other ) const
256 {
257 return ( !( *this == other ) );
258 }
259
267 inline QwtInterval QwtInterval::operator|( double value ) const
268 {
269 return extend( value );
270 }
271
273 inline bool QwtInterval::isNull() const
274 {
275 return isValid() && d_minValue >= d_maxValue;
276 }
277
284 inline void QwtInterval::invalidate()
285 {
286 d_minValue = 0.0;
287 d_maxValue = -1.0;
288 }
289
290 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
291
292 #ifndef QT_NO_DEBUG_STREAM
293 QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );
294 #endif
295
296 #endif