Qwt User's Guide: qwt_interval.h Source File

Qwt User's Guide 6.1.6

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 #include <qmetatype.h>
15
16 #ifndef QT_NO_DEBUG_STREAM
17 #include <qdebug.h>
18 #endif
19
26 class QWT_EXPORT QwtInterval
27 {
28 public:
33 enum BorderFlag
34 {
36 IncludeBorders = 0x00,
37
39 ExcludeMinimum = 0x01,
40
42 ExcludeMaximum = 0x02,
43
45 ExcludeBorders = ExcludeMinimum | ExcludeMaximum
46 };
47
49 typedef QFlags<BorderFlag> BorderFlags;
50
51 QwtInterval();
52 QwtInterval( double minValue, double maxValue,
53 BorderFlags = IncludeBorders );
54
55 void setInterval( double minValue, double maxValue,
56 BorderFlags = IncludeBorders );
57
58 QwtInterval normalized() const;
59 QwtInterval inverted() const;
60 QwtInterval limited( double lowerBound, double upperBound ) const;
61
62 bool operator==( const QwtInterval & ) const;
63 bool operator!=( const QwtInterval & ) const;
64
65 void setBorderFlags( BorderFlags );
66 BorderFlags borderFlags() const;
67
68 double minValue() const;
69 double maxValue() const;
70
71 double width() const;
72
73 void setMinValue( double );
74 void setMaxValue( double );
75
76 bool contains( double value ) const;
77
78 bool intersects( const QwtInterval & ) const;
79 QwtInterval intersect( const QwtInterval & ) const;
80 QwtInterval unite( const QwtInterval & ) const;
81
82 QwtInterval operator|( const QwtInterval & ) const;
83 QwtInterval operator&( const QwtInterval & ) const;
84
85 QwtInterval &operator|=( const QwtInterval & );
86 QwtInterval &operator&=( const QwtInterval & );
87
88 QwtInterval extend( double value ) const;
89 QwtInterval operator|( double ) const;
90 QwtInterval &operator|=( double );
91
92 bool isValid() const;
93 bool isNull() const;
94 void invalidate();
95
96 QwtInterval symmetrize( double value ) const;
97
98 private:
99 double d_minValue;
100 double d_maxValue;
101 BorderFlags d_borderFlags;
102 };
103
104 Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
105
112 inline QwtInterval::QwtInterval():
113 d_minValue( 0.0 ),
114 d_maxValue( -1.0 ),
115 d_borderFlags( IncludeBorders )
116 {
117 }
118
128 inline QwtInterval::QwtInterval(
129 double minValue, double maxValue, BorderFlags borderFlags ):
130 d_minValue( minValue ),
131 d_maxValue( maxValue ),
132 d_borderFlags( borderFlags )
133 {
134 }
135
143 inline void QwtInterval::setInterval(
144 double minValue, double maxValue, BorderFlags borderFlags )
145 {
146 d_minValue = minValue;
147 d_maxValue = maxValue;
148 d_borderFlags = borderFlags;
149 }
150
157 inline void QwtInterval::setBorderFlags( BorderFlags borderFlags )
158 {
159 d_borderFlags = borderFlags;
160 }
161
166 inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
167 {
168 return d_borderFlags;
169 }
170
176 inline void QwtInterval::setMinValue( double minValue )
177 {
178 d_minValue = minValue;
179 }
180
186 inline void QwtInterval::setMaxValue( double maxValue )
187 {
188 d_maxValue = maxValue;
189 }
190
192 inline double QwtInterval::minValue() const
193 {
194 return d_minValue;
195 }
196
198 inline double QwtInterval::maxValue() const
199 {
200 return d_maxValue;
201 }
202
210 inline bool QwtInterval::isValid() const
211 {
212 if ( ( d_borderFlags & ExcludeBorders ) == 0 )
213 return d_minValue <= d_maxValue;
214 else
215 return d_minValue < d_maxValue;
216 }
217
227 inline double QwtInterval::width() const
228 {
229 return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
230 }
231
240 inline QwtInterval QwtInterval::operator&(
241 const QwtInterval &other ) const
242 {
243 return intersect( other );
244 }
245
254 inline QwtInterval QwtInterval::operator|(
255 const QwtInterval &other ) const
256 {
257 return unite( other );
258 }
259
266 inline bool QwtInterval::operator==( const QwtInterval &other ) const
267 {
268 return ( d_minValue == other.d_minValue ) &&
269 ( d_maxValue == other.d_maxValue ) &&
270 ( d_borderFlags == other.d_borderFlags );
271 }
278 inline bool QwtInterval::operator!=( const QwtInterval &other ) const
279 {
280 return ( !( *this == other ) );
281 }
282
290 inline QwtInterval QwtInterval::operator|( double value ) const
291 {
292 return extend( value );
293 }
294
296 inline bool QwtInterval::isNull() const
297 {
298 return isValid() && d_minValue >= d_maxValue;
299 }
300
307 inline void QwtInterval::invalidate()
308 {
309 d_minValue = 0.0;
310 d_maxValue = -1.0;
311 }
312
313 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
314 Q_DECLARE_METATYPE( QwtInterval )
315
316 #ifndef QT_NO_DEBUG_STREAM
317 QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );
318 #endif
319
320 #endif
QwtInterval::operator!=
bool operator!=(const QwtInterval &) const
Compare two intervals.
Definition: qwt_interval.h:278
QwtInterval::invalidate
void invalidate()
Definition: qwt_interval.h:307
QwtInterval::operator&
QwtInterval operator&(const QwtInterval &) const
Intersection of two intervals.
Definition: qwt_interval.h:240
QwtInterval::setMinValue
void setMinValue(double)
Definition: qwt_interval.h:176
QwtInterval::QwtInterval
QwtInterval()
Default Constructor.
Definition: qwt_interval.h:112
QwtInterval::ExcludeBorders
@ ExcludeBorders
Min/Max values are not included in the interval.
Definition: qwt_interval.h:45
QwtInterval::setInterval
void setInterval(double minValue, double maxValue, BorderFlags=IncludeBorders)
Definition: qwt_interval.h:143
QwtInterval::extend
QwtInterval extend(double value) const
Extend the interval.
Definition: qwt_interval.cpp:316
QwtInterval::BorderFlag
BorderFlag
Definition: qwt_interval.h:34
QwtInterval::minValue
double minValue() const
Definition: qwt_interval.h:192
QwtInterval::setMaxValue
void setMaxValue(double)
Definition: qwt_interval.h:186
QwtInterval::borderFlags
BorderFlags borderFlags() const
Definition: qwt_interval.h:166
QwtInterval::isValid
bool isValid() const
Definition: qwt_interval.h:210
QwtInterval::unite
QwtInterval unite(const QwtInterval &) const
Unite 2 intervals.
Definition: qwt_interval.cpp:76
QwtInterval::operator==
bool operator==(const QwtInterval &) const
Compare two intervals.
Definition: qwt_interval.h:266
QwtInterval::BorderFlags
QFlags< BorderFlag > BorderFlags
Border flags.
Definition: qwt_interval.h:49
QwtInterval::width
double width() const
Return the width of an interval.
Definition: qwt_interval.h:227
QwtInterval::intersect
QwtInterval intersect(const QwtInterval &) const
Intersect 2 intervals.
Definition: qwt_interval.cpp:139
QwtInterval::isNull
bool isNull() const
Definition: qwt_interval.h:296
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:27
QwtInterval::operator|
QwtInterval operator|(const QwtInterval &) const
Definition: qwt_interval.h:254
QwtInterval::maxValue
double maxValue() const
Definition: qwt_interval.h:198
QwtInterval::setBorderFlags
void setBorderFlags(BorderFlags)
Definition: qwt_interval.h:157