QWT API (中文) 7.0.1
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 "qwt_global.h"
31#include <qmetatype.h>
32
44class QWT_EXPORT QwtInterval
45{
46public:
58 {
60 IncludeBorders = 0x00,
61
63 ExcludeMinimum = 0x01,
64
66 ExcludeMaximum = 0x02,
67
69 ExcludeBorders = ExcludeMinimum | ExcludeMaximum
70 };
71
73 Q_DECLARE_FLAGS(BorderFlags, BorderFlag)
74
76 QwtInterval(double minValue, double maxValue, BorderFlags = IncludeBorders);
77
78 // Assign the limits of the interval
79 void setInterval(double minValue, double maxValue, BorderFlags = IncludeBorders);
80
81 // Normalize the limits of the interval
82 QwtInterval normalized() const;
83 // Invert the interval
84 QwtInterval inverted() const;
85 // Limit the interval, keeping the border modes
86 QwtInterval limited(double lowerBound, double upperBound) const;
87
88 // Compare two intervals for equality
89 bool operator==(const QwtInterval&) const;
90 // Compare two intervals for inequality
91 bool operator!=(const QwtInterval&) const;
92
93 void setBorderFlags(BorderFlags);
94 BorderFlags borderFlags() const;
95
96 double minValue() const;
97 double maxValue() const;
98 double centerValue() const;
99
100 double width() const;
101 long double widthL() const;
102
103 void setMinValue(double);
104 void setMaxValue(double);
105
106 // Test if a value is inside the interval
107 bool contains(double value) const;
108 // Test if an interval is inside the interval
109 bool contains(const QwtInterval&) const;
110
111 // Test if two intervals overlap
112 bool intersects(const QwtInterval&) const;
113 // Intersect two intervals
114 QwtInterval intersect(const QwtInterval&) const;
115 // Unite two intervals
116 QwtInterval unite(const QwtInterval&) const;
117
118 // Union of two intervals
119 QwtInterval operator|(const QwtInterval&) const;
120 // Intersection of two intervals
121 QwtInterval operator&(const QwtInterval&) const;
122
123 // Unite this interval with the given interval
124 QwtInterval& operator|=(const QwtInterval&);
125 // Intersect this interval with the given interval
126 QwtInterval& operator&=(const QwtInterval&);
127
128 // Extend the interval with a value
129 QwtInterval extend(double value) const;
130 // Extend an interval with a value
131 QwtInterval operator|(double) const;
132 // Extend an interval with a value
133 QwtInterval& operator|=(double);
134
135 bool isValid() const;
136 bool isNull() const;
137 void invalidate();
138
139 // Symmetrize the interval around a value
140 QwtInterval symmetrize(double value) const;
141
142private:
143 double m_minValue;
144 double m_maxValue;
145 BorderFlags m_borderFlags;
146};
147
148Q_DECLARE_OPERATORS_FOR_FLAGS(QwtInterval::BorderFlags)
149Q_DECLARE_METATYPE(QwtInterval)
150Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
151
164inline QwtInterval::QwtInterval() : m_minValue(0.0), m_maxValue(-1.0), m_borderFlags(IncludeBorders)
165{
166}
167
182inline QwtInterval::QwtInterval(double minValue, double maxValue, BorderFlags borderFlags)
183 : m_minValue(minValue), m_maxValue(maxValue), m_borderFlags(borderFlags)
184{
185}
186
201inline void QwtInterval::setInterval(double minValue, double maxValue, BorderFlags borderFlags)
202{
203 m_minValue = minValue;
204 m_maxValue = maxValue;
205 m_borderFlags = borderFlags;
206}
207
220inline void QwtInterval::setBorderFlags(BorderFlags borderFlags)
221{
222 m_borderFlags = borderFlags;
223}
224
235inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
236{
237 return m_borderFlags;
238}
239
250inline void QwtInterval::setMinValue(double minValue)
251{
252 m_minValue = minValue;
253}
254
265inline void QwtInterval::setMaxValue(double maxValue)
266{
267 m_maxValue = maxValue;
268}
269
280inline double QwtInterval::minValue() const
281{
282 return m_minValue;
283}
284
295inline double QwtInterval::maxValue() const
296{
297 return m_maxValue;
298}
299
310inline double QwtInterval::centerValue() const
311{
312 return isValid() ? (m_minValue + (m_maxValue - m_minValue) * 0.5) : 0.0;
313}
331inline bool QwtInterval::isValid() const
332{
333 if ((m_borderFlags & ExcludeBorders) == 0)
334 return m_minValue <= m_maxValue;
335 else
336 return m_minValue < m_maxValue;
337}
338
353inline double QwtInterval::width() const
354{
355 return isValid() ? (m_maxValue - m_minValue) : 0.0;
356}
357
373inline long double QwtInterval::widthL() const
374{
375 if (!isValid())
376 return 0.0;
377
378 return static_cast< long double >(m_maxValue) - static_cast< long double >(m_minValue);
379}
380
396{
397 return intersect(other);
398}
399
415{
416 return unite(other);
417}
418
431inline bool QwtInterval::operator==(const QwtInterval& other) const
432{
433 return (m_minValue == other.m_minValue) && (m_maxValue == other.m_maxValue) && (m_borderFlags == other.m_borderFlags);
434}
435
448inline bool QwtInterval::operator!=(const QwtInterval& other) const
449{
450 return (!(*this == other));
451}
452
467inline QwtInterval QwtInterval::operator|(double value) const
468{
469 return extend(value);
470}
471
482inline bool QwtInterval::isNull() const
483{
484 return isValid() && m_minValue >= m_maxValue;
485}
486
500{
501 m_minValue = 0.0;
502 m_maxValue = -1.0;
503}
504
505#ifndef QT_NO_DEBUG_STREAM
506QWT_EXPORT QDebug operator<<(QDebug, const QwtInterval&);
507#endif
508
509#endif
表示区间的类
Definition qwt_interval.h:45
void setInterval(double minValue, double maxValue, BorderFlags=IncludeBorders)
设置区间的界限
Definition qwt_interval.h:201
double minValue() const
Definition qwt_interval.h:280
QwtInterval operator|(const QwtInterval &) const
两个区间的并集
Definition qwt_interval.h:414
double width() const
返回区间的宽度
Definition qwt_interval.h:353
BorderFlag
Definition qwt_interval.h:58
@ ExcludeBorders
最小值/最大值都不包含在区间内
Definition qwt_interval.h:69
long double widthL() const
以 long double 返回区间的宽度
Definition qwt_interval.h:373
void setMaxValue(double)
设置区间的上限
Definition qwt_interval.h:265
double maxValue() const
Definition qwt_interval.h:295
QwtInterval unite(const QwtInterval &) const
合并两个区间
Definition qwt_interval.cpp:166
void invalidate()
使区间无效
Definition qwt_interval.h:499
bool operator==(const QwtInterval &) const
比较两个区间
Definition qwt_interval.h:431
bool operator!=(const QwtInterval &) const
比较两个区间
Definition qwt_interval.h:448
QwtInterval operator&(const QwtInterval &) const
两个区间的交集
Definition qwt_interval.h:395
QwtInterval extend(double value) const
扩展区间
Definition qwt_interval.cpp:423
void setMinValue(double)
设置区间的下限
Definition qwt_interval.h:250
QwtInterval intersect(const QwtInterval &) const
交集两个区间
Definition qwt_interval.cpp:226
BorderFlags borderFlags() const
Definition qwt_interval.h:235
bool isNull() const
检查区间是否为空
Definition qwt_interval.h:482
QwtInterval()
Border flags
Definition qwt_interval.h:164
void setBorderFlags(BorderFlags)
更改边界标志
Definition qwt_interval.h:220
bool isValid() const
检查区间是否有效
Definition qwt_interval.h:331
double centerValue() const
Definition qwt_interval.h:310