QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_series_data.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_SERIES_DATA_H
28#define QWT_SERIES_DATA_H
29
30#include "qwtcore_global.h"
31#include "qwt_samples.h"
32#include "qwt_point_3d.h"
33
34#include <qvector.h>
35#include <qrect.h>
36
37class QwtPointPolar;
38
43QWTCORE_EXPORT bool isSampleNanOrInf(const QPointF& sample);
44
46QWTCORE_EXPORT bool isSampleNanOrInf(const QwtPoint3D& sample);
47
49QWTCORE_EXPORT bool isSampleNanOrInf(const QwtPointPolar& sample);
50
52QWTCORE_EXPORT bool isSampleNanOrInf(const QwtSetSample& sample);
53
55QWTCORE_EXPORT bool isSampleNanOrInf(const QwtIntervalSample& sample);
56
58QWTCORE_EXPORT bool isSampleNanOrInf(const QwtOHLCSample& sample);
59
61QWTCORE_EXPORT bool isSampleNanOrInf(const QwtVectorFieldSample& sample);
62
64QWTCORE_EXPORT bool isSampleNanOrInf(const QwtBoxSample& sample);
65
67QWTCORE_EXPORT bool isSampleNanOrInf(const QwtBoxOutlierSample& sample);
68
86template< typename T >
88{
89public:
92
94 virtual ~QwtSeriesData();
95
96#ifndef QWT_PYTHON_WRAPPER
97
99 virtual size_t size() const = 0;
100
102 virtual T sample(size_t i) const = 0;
103
105 virtual QRectF boundingRect() const = 0;
106
107#else
108 // Needed for generating the python bindings, but not for using them !
109 virtual size_t size() const
110 {
111 return 0;
112 }
113 virtual T sample(size_t i) const
114 {
115 return T();
116 }
117 virtual QRectF boundingRect() const
118 {
119 return cachedBoundingRect;
120 }
121#endif
122
124 virtual void setRectOfInterest(const QRectF& rect);
125
126protected:
128 mutable QRectF cachedBoundingRect;
129
130private:
131 QwtSeriesData< T >& operator=(const QwtSeriesData< T >&);
132};
133
134template< typename T >
135QwtSeriesData< T >::QwtSeriesData() : cachedBoundingRect(0.0, 0.0, -1.0, -1.0)
136{
137}
138
139template< typename T >
143
144template< typename T >
146{
147}
148
153template< typename T >
155{
156public:
159
163
167
169 const QVector< T > samples() const;
170
172 virtual size_t size() const override;
173
175 virtual T sample(size_t index) const override;
176
177protected:
180};
181
182template< typename T >
186
187template< typename T >
189{
190}
191
192template< typename T >
194{
195 m_samples = std::move(samples);
196}
197
198template< typename T >
200{
201 QwtSeriesData< T >::cachedBoundingRect = QRectF(0.0, 0.0, -1.0, -1.0);
202 m_samples = samples;
203}
204
205template< typename T >
207{
208 QwtSeriesData< T >::cachedBoundingRect = QRectF(0.0, 0.0, -1.0, -1.0);
209 m_samples = std::move(samples);
210}
211
212template< typename T >
214{
215 return m_samples;
216}
217
218template< typename T >
220{
221 return m_samples.size();
222}
223
224template< typename T >
226{
227 return m_samples[ static_cast< int >(i) ];
228}
229
234class QWTCORE_EXPORT QwtPointSeriesData : public QwtArraySeriesData< QPointF >
235{
236public:
239
241 virtual QRectF boundingRect() const override;
242};
243
248class QWTCORE_EXPORT QwtPoint3DSeriesData : public QwtArraySeriesData< QwtPoint3D >
249{
250public:
253
255 virtual QRectF boundingRect() const override;
256};
257
262class QWTCORE_EXPORT QwtIntervalSeriesData : public QwtArraySeriesData< QwtIntervalSample >
263{
264public:
267
269 virtual QRectF boundingRect() const override;
270};
271
276class QWTCORE_EXPORT QwtSetSeriesData : public QwtArraySeriesData< QwtSetSample >
277{
278public:
281
283 virtual QRectF boundingRect() const override;
284};
285
290class QWTCORE_EXPORT QwtVectorFieldData : public QwtArraySeriesData< QwtVectorFieldSample >
291{
292public:
295
297 virtual QRectF boundingRect() const override;
298};
299
305class QWTCORE_EXPORT QwtTradingChartData : public QwtArraySeriesData< QwtOHLCSample >
306{
307public:
310
312 virtual QRectF boundingRect() const override;
313};
314
320class QWTCORE_EXPORT QwtBoxChartData : public QwtArraySeriesData< QwtBoxSample >
321{
322public:
325
327 virtual QRectF boundingRect() const override;
328};
329
335class QWTCORE_EXPORT QwtBoxOutlierChartData : public QwtArraySeriesData< QwtBoxOutlierSample >
336{
337public:
340
342 virtual QRectF boundingRect() const override;
343
345 int totalOutlierCount() const;
346};
347
348QWTCORE_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QPointF >&, size_t from = 0, size_t to = 0);
349
350QWTCORE_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QwtPoint3D >&, size_t from = 0, size_t to = 0);
351
352QWTCORE_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QwtPointPolar >&, size_t from = 0, size_t to = 0);
353
354QWTCORE_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QwtIntervalSample >&, size_t from = 0, size_t to = 0);
355
356QWTCORE_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QwtSetSample >&, size_t from = 0, size_t to = 0);
357
358QWTCORE_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QwtOHLCSample >&, size_t from = 0, size_t to = 0);
359
360QWTCORE_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QwtVectorFieldSample >&, size_t from = 0, size_t to = 0);
361
362QWTCORE_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QwtBoxSample >&, size_t from = 0, size_t to = 0);
363
364QWTCORE_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QwtBoxOutlierSample >&, size_t from = 0, size_t to = 0);
365
419template< typename T, typename LessThan >
420inline size_t qwtUpperSampleIndex(const QwtSeriesData< T >& series, double value, LessThan lessThan)
421{
422 const size_t count = series.size();
423 if (count == 0) {
424 return count; // Return 0 as "not found" marker (valid indices start from 0, count is beyond valid range)
425 }
426
427 const size_t indexMax = count - 1;
428
429 // If value is greater than or equal to the last element, no element is greater than value, return count
430 if (!lessThan(value, series.sample(indexMax))) {
431 return count;
432 }
433
434 size_t indexMin = 0;
435 size_t n = indexMax; // n represents the current search interval size
436
437 while (n > 0) {
438 const size_t half = n >> 1;
439 const size_t indexMid = indexMin + half;
440
441 if (lessThan(value, series.sample(indexMid))) {
442 // Target is in the left interval [indexMin, indexMid]
443 n = half;
444 } else {
445 // Target is in the right interval [indexMid + 1, indexMin + n - 1]
446 indexMin = indexMid + 1;
447 n -= half + 1;
448 }
449 }
450
451 return indexMin;
452}
453
454#endif
Definition qwt_clipper.h:41
Template class for data, that is organized as QVector
Definition qwt_series_data.h:155
virtual T sample(size_t index) const override
Definition qwt_series_data.h:225
virtual size_t size() const override
Definition qwt_series_data.h:219
QwtArraySeriesData()
Constructor
Definition qwt_series_data.h:183
void setSamples(const QVector< T > &samples)
Assign an array of samples
Definition qwt_series_data.h:199
QwtArraySeriesData(const QVector< T > &samples)
Constructor
Definition qwt_series_data.h:188
QVector< T > m_samples
Vector of samples
Definition qwt_series_data.h:179
const QVector< T > samples() const
Definition qwt_series_data.h:213
Interface for iterating over an array of boxplot samples
Definition qwt_series_data.h:321
Interface for iterating over an array of boxplot outlier samples
Definition qwt_series_data.h:336
Outlier values for a single boxplot position
Definition qwt_samples.h:452
Sample for box-and-whisker plot (boxplot) visualization
Definition qwt_samples.h:363
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition qwt_samples.h:74
Interface for iterating over an array of intervals
Definition qwt_series_data.h:263
Open-High-Low-Close sample used in financial charts
Definition qwt_samples.h:210
Interface for iterating over an array of 3D points
Definition qwt_series_data.h:249
QwtPoint3D class defines a 3D point in double coordinates
Definition qwt_point_3d.h:40
A point in polar coordinates
Definition qwt_point_polar.h:45
Interface for iterating over an array of points
Definition qwt_series_data.h:235
Abstract interface for iterating over samples
Definition qwt_series_data.h:88
virtual void setRectOfInterest(const QRectF &rect)
Set a the "rect of interest"
Definition qwt_series_data.h:145
virtual size_t size() const =0
QwtSeriesData()
Constructor
Definition qwt_series_data.h:135
virtual ~QwtSeriesData()
Destructor
Definition qwt_series_data.h:140
QRectF cachedBoundingRect
Can be used to cache a calculated bounding rectangle
Definition qwt_series_data.h:128
virtual T sample(size_t i) const =0
Return a sample
virtual QRectF boundingRect() const =0
Calculate the bounding rect of all samples
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition qwt_samples.h:139
Interface for iterating over an array of set samples
Definition qwt_series_data.h:277
Interface for iterating over an array of OHLC samples
Definition qwt_series_data.h:306
Interface for iterating over an array of vector field samples
Definition qwt_series_data.h:291
Sample used in vector fields
Definition qwt_samples.h:291