QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_samples.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_SAMPLES_H
28#define QWT_SAMPLES_H
29
30#include "qwtcore_global.h"
31#include "qwt_interval.h"
32
33#include <qvector.h>
34#include <qrect.h>
35
42class QWTCORE_EXPORT QwtStatisticalSample
43{
44public:
49 QwtStatisticalSample(double position = 0.0);
50
52 double position;
53
55 double lower;
56
58 double upper;
59
61 double center;
62};
63
64inline QwtStatisticalSample::QwtStatisticalSample(double pos) : position(pos), lower(0.0), upper(0.0), center(0.0)
65{
66}
67
73class QWTCORE_EXPORT QwtIntervalSample
74{
75public:
77 QwtIntervalSample(double, const QwtInterval&);
78 QwtIntervalSample(double value, double min, double max);
79
80 bool operator==(const QwtIntervalSample&) const;
81 bool operator!=(const QwtIntervalSample&) const;
82
84 double value;
85
88};
89
95{
96}
97
103inline QwtIntervalSample::QwtIntervalSample(double v, const QwtInterval& intv) : value(v), interval(intv)
104{
105}
106
113inline QwtIntervalSample::QwtIntervalSample(double v, double min, double max) : value(v), interval(min, max)
114{
115}
116
121{
122 return value == other.value && interval == other.interval;
123}
124
129{
130 return !(*this == other);
131}
132
138class QWTCORE_EXPORT QwtSetSample
139{
140public:
141 QwtSetSample();
142 explicit QwtSetSample(double, const QVector< double >& = QVector< double >());
143
144 bool operator==(const QwtSetSample& other) const;
145 bool operator!=(const QwtSetSample& other) const;
146
147 double added() const;
148
150 double value;
151
154};
155
160inline QwtSetSample::QwtSetSample() : value(0.0)
161{
162}
163
169inline QwtSetSample::QwtSetSample(double v, const QVector< double >& s) : value(v), set(s)
170{
171}
172
176inline bool QwtSetSample::operator==(const QwtSetSample& other) const
177{
178 return value == other.value && set == other.set;
179}
180
184inline bool QwtSetSample::operator!=(const QwtSetSample& other) const
185{
186 return !(*this == other);
187}
188
193inline double QwtSetSample::added() const
194{
195 double y = 0.0;
196 for (int i = 0; i < set.size(); i++)
197 y += set[ i ];
198
199 return y;
200}
201
209class QWTCORE_EXPORT QwtOHLCSample
210{
211public:
212 QwtOHLCSample(double time = 0.0, double open = 0.0, double high = 0.0, double low = 0.0, double close = 0.0);
213
214 QwtInterval boundingInterval() const;
215
216 bool isValid() const;
217
222 double time;
223
225 double open;
226
228 double high;
229
231 double low;
232
234 double close;
235};
236
245inline QwtOHLCSample::QwtOHLCSample(double t, double o, double h, double l, double c)
246 : time(t), open(o), high(h), low(l), close(c)
247{
248}
249
258inline bool QwtOHLCSample::isValid() const
259{
260 return (low <= high) && (open >= low) && (open <= high) && (close >= low) && (close <= high);
261}
262
270{
271 double minY = open;
272 minY = qMin(minY, high);
273 minY = qMin(minY, low);
274 minY = qMin(minY, close);
275
276 double maxY = open;
277 maxY = qMax(maxY, high);
278 maxY = qMax(maxY, low);
279 maxY = qMax(maxY, close);
280
281 return QwtInterval(minY, maxY);
282}
283
290class QWTCORE_EXPORT QwtVectorFieldSample
291{
292public:
293 QwtVectorFieldSample(double x = 0.0, double y = 0.0, double vx = 0.0, double vy = 0.0);
294
295 QwtVectorFieldSample(const QPointF& pos, double vx = 0.0, double vy = 0.0);
296
297 QPointF pos() const;
298
299 bool isNull() const;
300
302 double x;
303
305 double y;
306
308 double vx;
309
311 double vy;
312};
313
321inline QwtVectorFieldSample::QwtVectorFieldSample(double posX, double posY, double vectorX, double vectorY)
322 : x(posX), y(posY), vx(vectorX), vy(vectorY)
323{
324}
325
332inline QwtVectorFieldSample::QwtVectorFieldSample(const QPointF& pos, double vectorX, double vectorY)
333 : x(pos.x()), y(pos.y()), vx(vectorX), vy(vectorY)
334{
335}
336
341inline QPointF QwtVectorFieldSample::pos() const
342{
343 return QPointF(x, y);
344}
345
351{
352 return (vx == 0.0) && (vy == 0.0);
353}
354
362class QWTCORE_EXPORT QwtBoxSample : public QwtStatisticalSample
363{
364public:
369 QwtBoxSample(double position = 0.0);
370
380 QwtBoxSample(double position, double whiskerLower, double q1, double median, double q3, double whiskerUpper);
381
386 bool isValid() const;
387
392 QwtInterval boundingInterval() const;
393
398 QwtInterval boxInterval() const;
399
402
404 double q1;
405
407 double median;
408
410 double q3;
411
414
417};
418
420 : QwtStatisticalSample(pos), whiskerLower(0.0), q1(0.0), median(0.0), q3(0.0), whiskerUpper(0.0), outlierCount(0)
421{
422}
423
424inline QwtBoxSample::QwtBoxSample(double pos, double wl, double q1v, double med, double q3v, double wu)
425 : QwtStatisticalSample(pos), whiskerLower(wl), q1(q1v), median(med), q3(q3v), whiskerUpper(wu), outlierCount(0)
426{
427 center = median;
428}
429
430inline bool QwtBoxSample::isValid() const
431{
432 return (whiskerLower <= q1) && (q1 <= median) && (median <= q3) && (q3 <= whiskerUpper);
433}
434
439
441{
442 return QwtInterval(q1, q3);
443}
444
451class QWTCORE_EXPORT QwtBoxOutlierSample
452{
453public:
457 QwtBoxOutlierSample(double boxPosition = 0.0);
458
464 QwtBoxOutlierSample(double boxPosition, const QVector< double >& values);
465
469 QwtBoxOutlierSample(double boxPosition, QVector< double >&& values);
470
472 bool isEmpty() const
473 {
474 return values.isEmpty();
475 }
476
478 int count() const
479 {
480 return values.size();
481 }
482
485
488};
489
490inline QwtBoxOutlierSample::QwtBoxOutlierSample(double pos) : boxPosition(pos), values()
491{
492}
493
495 : boxPosition(pos), values(vals)
496{
497}
498
500 : boxPosition(pos), values(std::move(vals))
501{
502}
503
504Q_DECLARE_METATYPE(QwtIntervalSample)
505Q_DECLARE_METATYPE(QwtOHLCSample)
506Q_DECLARE_METATYPE(QwtVectorFieldSample)
507Q_DECLARE_METATYPE(QwtBoxSample)
508Q_DECLARE_METATYPE(QwtSetSample)
509
510#endif
Outlier values for a single boxplot position
Definition qwt_samples.h:452
bool isEmpty() const
Check if no outliers present
Definition qwt_samples.h:472
double boxPosition
Position of the parent box (matches QwtBoxSample.position)
Definition qwt_samples.h:484
QVector< double > values
All outlier values for this box
Definition qwt_samples.h:487
int count() const
Get number of outliers
Definition qwt_samples.h:478
QwtBoxOutlierSample(double boxPosition=0.0)
Default constructor
Definition qwt_samples.h:490
Sample for box-and-whisker plot (boxplot) visualization
Definition qwt_samples.h:363
double q3
Third quartile (75th percentile)
Definition qwt_samples.h:410
double whiskerLower
Lower whisker endpoint
Definition qwt_samples.h:401
double whiskerUpper
Upper whisker endpoint
Definition qwt_samples.h:413
int outlierCount
Number of outliers (stored separately, this is count only)
Definition qwt_samples.h:416
QwtBoxSample(double position=0.0)
Default constructor
Definition qwt_samples.h:419
QwtInterval boundingInterval() const
Get bounding interval including whiskers
Definition qwt_samples.h:435
bool isValid() const
Check if sample has valid ordering
Definition qwt_samples.h:430
double q1
First quartile (25th percentile)
Definition qwt_samples.h:404
QwtInterval boxInterval() const
Get box body interval (Q1 to Q3)
Definition qwt_samples.h:440
double median
Median (50th percentile) - also stored in inherited 'center' field
Definition qwt_samples.h:407
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition qwt_samples.h:74
QwtInterval interval
Interval
Definition qwt_samples.h:87
bool operator==(const QwtIntervalSample &) const
Equality comparison operator
Definition qwt_samples.h:120
bool operator!=(const QwtIntervalSample &) const
Inequality comparison operator
Definition qwt_samples.h:128
QwtIntervalSample()
Default constructor
Definition qwt_samples.h:94
double value
Value
Definition qwt_samples.h:84
A class representing an interval
Definition qwt_interval.h:39
Open-High-Low-Close sample used in financial charts
Definition qwt_samples.h:210
double high
Highest price
Definition qwt_samples.h:228
bool isValid() const
Check if a sample is valid
Definition qwt_samples.h:258
double open
Opening price
Definition qwt_samples.h:225
double close
Closing price
Definition qwt_samples.h:234
double time
Time of the sample, usually a number representing a specific interval - like a day.
Definition qwt_samples.h:222
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values
Definition qwt_samples.h:269
QwtOHLCSample(double time=0.0, double open=0.0, double high=0.0, double low=0.0, double close=0.0)
Constructor with all OHLC values
Definition qwt_samples.h:245
double low
Lowest price
Definition qwt_samples.h:231
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition qwt_samples.h:139
double added() const
Return all values of the set added together
Definition qwt_samples.h:193
double value
value
Definition qwt_samples.h:150
QVector< double > set
Vector of values associated to value
Definition qwt_samples.h:153
bool operator!=(const QwtSetSample &other) const
Inequality comparison operator
Definition qwt_samples.h:184
bool operator==(const QwtSetSample &other) const
Equality comparison operator
Definition qwt_samples.h:176
QwtSetSample()
Default constructor
Definition qwt_samples.h:160
Base class for statistical samples with position and range
Definition qwt_samples.h:43
double lower
Lower bound of the statistical range
Definition qwt_samples.h:55
double position
Position on the "time" axis (x for vertical, y for horizontal orientation)
Definition qwt_samples.h:52
QwtStatisticalSample(double position=0.0)
Default constructor
Definition qwt_samples.h:64
double upper
Upper bound of the statistical range
Definition qwt_samples.h:58
double center
Central reference value
Definition qwt_samples.h:61
Sample used in vector fields
Definition qwt_samples.h:291
double y
y coordinate of the position
Definition qwt_samples.h:305
QwtVectorFieldSample(double x=0.0, double y=0.0, double vx=0.0, double vy=0.0)
Constructor with position and vector coordinates
Definition qwt_samples.h:321
QPointF pos() const
Return position as QPointF
Definition qwt_samples.h:341
bool isNull() const
Check if the vector is null
Definition qwt_samples.h:350
double vx
x coordinate of the vector
Definition qwt_samples.h:308
double x
x coordinate of the position
Definition qwt_samples.h:302
double vy
y coordinate of the vector
Definition qwt_samples.h:311