QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
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 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner → QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
27#ifndef QWT_INTERVAL_H
28#define QWT_INTERVAL_H
29
30#include "qwtcore_global.h"
31#include <qmetatype.h>
32
38class QWTCORE_EXPORT QwtInterval
39{
40public:
46 {
48 IncludeBorders = 0x00,
49
51 ExcludeMinimum = 0x01,
52
54 ExcludeMaximum = 0x02,
55
57 ExcludeBorders = ExcludeMinimum | ExcludeMaximum
58 };
59
61 Q_DECLARE_FLAGS(BorderFlags, BorderFlag)
62
63 constexpr QwtInterval() noexcept;
64 constexpr QwtInterval(double minValue, double maxValue, BorderFlags = IncludeBorders) noexcept;
65
66 // Assign the limits of the interval
67 void setInterval(double minValue, double maxValue, BorderFlags = IncludeBorders) noexcept;
68
69 // Normalize the limits of the interval
70 QwtInterval normalized() const;
71 // Invert the interval
72 QwtInterval inverted() const;
73 // Limit the interval, keeping the border modes
74 QwtInterval limited(double lowerBound, double upperBound) const;
75
76 // Compare two intervals for equality
77 bool operator==(const QwtInterval&) const;
78 // Compare two intervals for inequality
79 bool operator!=(const QwtInterval&) const;
80
81 void setBorderFlags(BorderFlags) noexcept;
82 constexpr BorderFlags borderFlags() const noexcept;
83
84 constexpr double minValue() const noexcept;
85 constexpr double maxValue() const noexcept;
86 constexpr double centerValue() const noexcept;
87
88 constexpr double width() const noexcept;
89 constexpr long double widthL() const noexcept;
90
91 void setMinValue(double) noexcept;
92 void setMaxValue(double) noexcept;
93
94 // Test if a value is inside the interval
95 bool contains(double value) const;
96 // Test if an interval is inside the interval
97 bool contains(const QwtInterval&) const;
98
99 // Test if two intervals overlap
100 bool intersects(const QwtInterval&) const;
101 // Intersect two intervals
102 QwtInterval intersect(const QwtInterval&) const;
103 // Unite two intervals
104 QwtInterval unite(const QwtInterval&) const;
105
106 // Union of two intervals
107 QwtInterval operator|(const QwtInterval&) const;
108 // Intersection of two intervals
109 QwtInterval operator&(const QwtInterval&) const;
110
111 // Unite this interval with the given interval
112 QwtInterval& operator|=(const QwtInterval&);
113 // Intersect this interval with the given interval
114 QwtInterval& operator&=(const QwtInterval&);
115
116 // Extend the interval with a value
117 QwtInterval extend(double value) const;
118 // Extend an interval with a value
119 QwtInterval operator|(double) const;
120 // Extend an interval with a value
121 QwtInterval& operator|=(double);
122
123 constexpr bool isValid() const noexcept;
124 constexpr bool isNull() const noexcept;
125 void invalidate() noexcept;
126
127 // Symmetrize the interval around a value
128 QwtInterval symmetrize(double value) const;
129
130private:
131 double m_minValue { 0.0 };
132 double m_maxValue { -1.0 };
133 BorderFlags m_borderFlags { IncludeBorders };
134};
135
136Q_DECLARE_OPERATORS_FOR_FLAGS(QwtInterval::BorderFlags)
137Q_DECLARE_METATYPE(QwtInterval)
138Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
139
145inline constexpr QwtInterval::QwtInterval() noexcept : m_minValue(0.0), m_maxValue(-1.0), m_borderFlags(IncludeBorders)
146{
147}
148
155inline constexpr QwtInterval::QwtInterval(double minValue, double maxValue, BorderFlags borderFlags) noexcept
156 : m_minValue(minValue), m_maxValue(maxValue), m_borderFlags(borderFlags)
157{
158}
159
166inline void QwtInterval::setInterval(double minValue, double maxValue, BorderFlags borderFlags) noexcept
167{
168 m_minValue = minValue;
169 m_maxValue = maxValue;
170 m_borderFlags = borderFlags;
171}
172
178inline void QwtInterval::setBorderFlags(BorderFlags borderFlags) noexcept
179{
180 m_borderFlags = borderFlags;
181}
182
187inline constexpr QwtInterval::BorderFlags QwtInterval::borderFlags() const noexcept
188{
189 return m_borderFlags;
190}
191
196inline void QwtInterval::setMinValue(double minValue) noexcept
197{
198 m_minValue = minValue;
199}
200
205inline void QwtInterval::setMaxValue(double maxValue) noexcept
206{
207 m_maxValue = maxValue;
208}
209
214inline constexpr double QwtInterval::minValue() const noexcept
215{
216 return m_minValue;
217}
218
223inline constexpr double QwtInterval::maxValue() const noexcept
224{
225 return m_maxValue;
226}
227
232inline constexpr double QwtInterval::centerValue() const noexcept
233{
234 return isValid() ? (m_minValue + (m_maxValue - m_minValue) * 0.5) : 0.0;
235}
244inline constexpr bool QwtInterval::isValid() const noexcept
245{
246 return ((m_borderFlags & ExcludeBorders) == 0) ? (m_minValue <= m_maxValue) : (m_minValue < m_maxValue);
247}
248
255inline constexpr double QwtInterval::width() const noexcept
256{
257 return isValid() ? (m_maxValue - m_minValue) : 0.0;
258}
259
267inline constexpr long double QwtInterval::widthL() const noexcept
268{
269 return isValid() ? static_cast< long double >(m_maxValue) - static_cast< long double >(m_minValue) : 0.0L;
270}
271
279{
280 return intersect(other);
281}
282
290{
291 return unite(other);
292}
293
299inline bool QwtInterval::operator==(const QwtInterval& other) const
300{
301 return (m_minValue == other.m_minValue) && (m_maxValue == other.m_maxValue) && (m_borderFlags == other.m_borderFlags);
302}
303
309inline bool QwtInterval::operator!=(const QwtInterval& other) const
310{
311 return (!(*this == other));
312}
313
320inline QwtInterval QwtInterval::operator|(double value) const
321{
322 return extend(value);
323}
324
329inline constexpr bool QwtInterval::isNull() const noexcept
330{
331 return isValid() && m_minValue >= m_maxValue;
332}
333
339inline void QwtInterval::invalidate() noexcept
340{
341 m_minValue = 0.0;
342 m_maxValue = -1.0;
343}
344
345#ifndef QT_NO_DEBUG_STREAM
346QWTCORE_EXPORT QDebug operator<<(QDebug, const QwtInterval&);
347#endif
348
349#endif
A class representing an interval
Definition qwt_interval.h:39
QwtInterval operator|(const QwtInterval &) const
Union of two intervals
Definition qwt_interval.h:289
BorderFlag
Flag indicating if a border is included or excluded
Definition qwt_interval.h:46
@ ExcludeBorders
Min/Max values are not included in the interval
Definition qwt_interval.h:57
constexpr QwtInterval() noexcept
Border flags
Definition qwt_interval.h:145
void setBorderFlags(BorderFlags) noexcept
Change the border flags
Definition qwt_interval.h:178
void invalidate() noexcept
Invalidate the interval
Definition qwt_interval.h:339
void setMinValue(double) noexcept
Assign the lower limit of the interval
Definition qwt_interval.h:196
QwtInterval unite(const QwtInterval &) const
Unite two intervals
Definition qwt_interval.cpp:137
constexpr double centerValue() const noexcept
Definition qwt_interval.h:232
bool operator==(const QwtInterval &) const
Compare two intervals
Definition qwt_interval.h:299
bool operator!=(const QwtInterval &) const
Compare two intervals
Definition qwt_interval.h:309
constexpr bool isNull() const noexcept
Check if interval is null
Definition qwt_interval.h:329
void setInterval(double minValue, double maxValue, BorderFlags=IncludeBorders) noexcept
Assign the limits of the interval
Definition qwt_interval.h:166
QwtInterval operator&(const QwtInterval &) const
Intersection of two intervals
Definition qwt_interval.h:278
constexpr double minValue() const noexcept
Definition qwt_interval.h:214
QwtInterval extend(double value) const
Extend the interval
Definition qwt_interval.cpp:339
constexpr BorderFlags borderFlags() const noexcept
Definition qwt_interval.h:187
void setMaxValue(double) noexcept
Assign the upper limit of the interval
Definition qwt_interval.h:205
QwtInterval intersect(const QwtInterval &) const
Intersect two intervals
Definition qwt_interval.cpp:190
constexpr double maxValue() const noexcept
Definition qwt_interval.h:223
constexpr long double widthL() const noexcept
Return the width of an interval as long double
Definition qwt_interval.h:267
constexpr double width() const noexcept
Return the width of an interval
Definition qwt_interval.h:255
constexpr bool isValid() const noexcept
Check if the interval is valid
Definition qwt_interval.h:244