QWT 7.0.1
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 * 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 "qwt_global.h"
31#include <qmetatype.h>
32
39class QWT_EXPORT QwtInterval
40{
41public:
47 {
49 IncludeBorders = 0x00,
50
52 ExcludeMinimum = 0x01,
53
55 ExcludeMaximum = 0x02,
56
58 ExcludeBorders = ExcludeMinimum | ExcludeMaximum
59 };
60
62 Q_DECLARE_FLAGS(BorderFlags, BorderFlag)
63
65 QwtInterval(double minValue, double maxValue, BorderFlags = IncludeBorders);
66
67 void setInterval(double minValue, double maxValue, BorderFlags = IncludeBorders);
68
69 QwtInterval normalized() const;
70 QwtInterval inverted() const;
71 QwtInterval limited(double lowerBound, double upperBound) const;
72
73 bool operator==(const QwtInterval&) const;
74 bool operator!=(const QwtInterval&) const;
75
76 void setBorderFlags(BorderFlags);
77 BorderFlags borderFlags() const;
78
79 double minValue() const;
80 double maxValue() const;
81 double centerValue() const;
82
83 double width() const;
84 long double widthL() const;
85
86 void setMinValue(double);
87 void setMaxValue(double);
88
89 bool contains(double value) const;
90 bool contains(const QwtInterval&) const;
91
92 bool intersects(const QwtInterval&) const;
93 QwtInterval intersect(const QwtInterval&) const;
94 QwtInterval unite(const QwtInterval&) const;
95
96 QwtInterval operator|(const QwtInterval&) const;
97 QwtInterval operator&(const QwtInterval&) const;
98
99 QwtInterval& operator|=(const QwtInterval&);
100 QwtInterval& operator&=(const QwtInterval&);
101
102 QwtInterval extend(double value) const;
103 QwtInterval operator|(double) const;
104 QwtInterval& operator|=(double);
105
106 bool isValid() const;
107 bool isNull() const;
108 void invalidate();
109
110 QwtInterval symmetrize(double value) const;
111
112private:
113 double m_minValue;
114 double m_maxValue;
115 BorderFlags m_borderFlags;
116};
117
118Q_DECLARE_OPERATORS_FOR_FLAGS(QwtInterval::BorderFlags)
119Q_DECLARE_METATYPE(QwtInterval)
120Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
121
128inline QwtInterval::QwtInterval() : m_minValue(0.0), m_maxValue(-1.0), m_borderFlags(IncludeBorders)
129{
130}
131
141inline QwtInterval::QwtInterval(double minValue, double maxValue, BorderFlags borderFlags)
142 : m_minValue(minValue), m_maxValue(maxValue), m_borderFlags(borderFlags)
143{
144}
145
153inline void QwtInterval::setInterval(double minValue, double maxValue, BorderFlags borderFlags)
154{
155 m_minValue = minValue;
156 m_maxValue = maxValue;
157 m_borderFlags = borderFlags;
158}
159
166inline void QwtInterval::setBorderFlags(BorderFlags borderFlags)
167{
168 m_borderFlags = borderFlags;
169}
170
175inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
176{
177 return m_borderFlags;
178}
179
185inline void QwtInterval::setMinValue(double minValue)
186{
187 m_minValue = minValue;
188}
189
195inline void QwtInterval::setMaxValue(double maxValue)
196{
197 m_maxValue = maxValue;
198}
199
201inline double QwtInterval::minValue() const
202{
203 return m_minValue;
204}
205
207inline double QwtInterval::maxValue() const
208{
209 return m_maxValue;
210}
211
213inline double QwtInterval::centerValue() const
214{
215 return isValid() ? (m_minValue + (m_maxValue - m_minValue) * 0.5) : 0.0;
216}
224inline bool QwtInterval::isValid() const
225{
226 if ((m_borderFlags & ExcludeBorders) == 0)
227 return m_minValue <= m_maxValue;
228 else
229 return m_minValue < m_maxValue;
230}
231
241inline double QwtInterval::width() const
242{
243 return isValid() ? (m_maxValue - m_minValue) : 0.0;
244}
245
255inline long double QwtInterval::widthL() const
256{
257 if (!isValid())
258 return 0.0;
259
260 return static_cast< long double >(m_maxValue) - static_cast< long double >(m_minValue);
261}
262
272{
273 return intersect(other);
274}
275
285{
286 return unite(other);
287}
288
295inline bool QwtInterval::operator==(const QwtInterval& other) const
296{
297 return (m_minValue == other.m_minValue) && (m_maxValue == other.m_maxValue) && (m_borderFlags == other.m_borderFlags);
298}
305inline bool QwtInterval::operator!=(const QwtInterval& other) const
306{
307 return (!(*this == other));
308}
309
317inline QwtInterval QwtInterval::operator|(double value) const
318{
319 return extend(value);
320}
321
323inline bool QwtInterval::isNull() const
324{
325 return isValid() && m_minValue >= m_maxValue;
326}
327
335{
336 m_minValue = 0.0;
337 m_maxValue = -1.0;
338}
339
340#ifndef QT_NO_DEBUG_STREAM
341QWT_EXPORT QDebug operator<<(QDebug, const QwtInterval&);
342#endif
343
344#endif
A class representing an interval.
Definition qwt_interval.h:40
void setInterval(double minValue, double maxValue, BorderFlags=IncludeBorders)
Assign the limits of the interval.
Definition qwt_interval.h:153
double minValue() const
Definition qwt_interval.h:201
QwtInterval operator|(const QwtInterval &) const
Union of two intervals.
Definition qwt_interval.h:284
double width() const
Return the width of an interval.
Definition qwt_interval.h:241
BorderFlag
Flag indicating if a border is included or excluded.
Definition qwt_interval.h:47
@ ExcludeBorders
Min/Max values are not included in the interval.
Definition qwt_interval.h:58
long double widthL() const
Return the width of an interval as long double.
Definition qwt_interval.h:255
void setMaxValue(double)
Assign the upper limit of the interval.
Definition qwt_interval.h:195
double maxValue() const
Definition qwt_interval.h:207
QwtInterval unite(const QwtInterval &) const
Unite 2 intervals.
Definition qwt_interval.cpp:134
void invalidate()
Invalidate the interval.
Definition qwt_interval.h:334
bool operator==(const QwtInterval &) const
Compare two intervals.
Definition qwt_interval.h:295
bool operator!=(const QwtInterval &) const
Compare two intervals.
Definition qwt_interval.h:305
QwtInterval operator&(const QwtInterval &) const
Intersection of two intervals.
Definition qwt_interval.h:271
QwtInterval extend(double value) const
Extend the interval.
Definition qwt_interval.cpp:346
void setMinValue(double)
Assign the lower limit of the interval.
Definition qwt_interval.h:185
QwtInterval intersect(const QwtInterval &) const
Intersect 2 intervals.
Definition qwt_interval.cpp:188
BorderFlags borderFlags() const
Definition qwt_interval.h:175
bool isNull() const
Definition qwt_interval.h:323
QwtInterval()
Border flags.
Definition qwt_interval.h:128
void setBorderFlags(BorderFlags)
Change the border flags.
Definition qwt_interval.h:166
bool isValid() const
A interval is valid when minValue() <= maxValue().
Definition qwt_interval.h:224
double centerValue() const
Definition qwt_interval.h:213