QWT 7.0.1
Loading...
Searching...
No Matches
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 "qwt_global.h"
31#include "qwt_interval.h"
32
33#include <qvector.h>
34#include <qrect.h>
35
37class QWT_EXPORT QwtIntervalSample
38{
39 public:
41 QwtIntervalSample( double, const QwtInterval& );
42 QwtIntervalSample( double value, double min, double max );
43
44 bool operator==( const QwtIntervalSample& ) const;
45 bool operator!=( const QwtIntervalSample& ) const;
46
48 double value;
49
52};
53
59 : value( 0.0 )
60{
61}
62
65 : value( v )
66 , interval( intv )
67{
68}
69
71inline QwtIntervalSample::QwtIntervalSample( double v, double min, double max )
72 : value( v )
73 , interval( min, max )
74{
75}
76
78inline bool QwtIntervalSample::operator==( const QwtIntervalSample& other ) const
79{
80 return value == other.value && interval == other.interval;
81}
82
84inline bool QwtIntervalSample::operator!=( const QwtIntervalSample& other ) const
85{
86 return !( *this == other );
87}
88
90class QWT_EXPORT QwtSetSample
91{
92 public:
94 explicit QwtSetSample( double, const QVector< double >& = QVector< double >( ) );
95
96 bool operator==( const QwtSetSample& other ) const;
97 bool operator!=( const QwtSetSample& other ) const;
98
99 double added() const;
100
102 double value;
103
106};
107
113 : value( 0.0 )
114{
115}
116
124 : value( v )
125 , set( s )
126{
127}
128
130inline bool QwtSetSample::operator==( const QwtSetSample& other ) const
131{
132 return value == other.value && set == other.set;
133}
134
136inline bool QwtSetSample::operator!=( const QwtSetSample& other ) const
137{
138 return !( *this == other );
139}
140
142inline double QwtSetSample::added() const
143{
144 double y = 0.0;
145 for ( int i = 0; i < set.size(); i++ )
146 y += set[i];
147
148 return y;
149}
150
160class QWT_EXPORT QwtOHLCSample
161{
162 public:
163 QwtOHLCSample( double time = 0.0,
164 double open = 0.0, double high = 0.0,
165 double low = 0.0, double close = 0.0 );
166
167 QwtInterval boundingInterval() const;
168
169 bool isValid() const;
170
175 double time;
176
178 double open;
179
181 double high;
182
184 double low;
185
187 double close;
188};
189
200 double t, double o, double h, double l, double c )
201 : time( t )
202 , open( o )
203 , high( h )
204 , low( l )
205 , close( c )
206{
207}
208
220inline bool QwtOHLCSample::isValid() const
221{
222 return ( low <= high )
223 && ( open >= low )
224 && ( open <= high )
225 && ( close >= low )
226 && ( close <= high );
227}
228
238{
239 double minY = open;
240 minY = qMin( minY, high );
241 minY = qMin( minY, low );
242 minY = qMin( minY, close );
243
244 double maxY = open;
245 maxY = qMax( maxY, high );
246 maxY = qMax( maxY, low );
247 maxY = qMax( maxY, close );
248
249 return QwtInterval( minY, maxY );
250}
251
260class QWT_EXPORT QwtVectorFieldSample
261{
262 public:
263 QwtVectorFieldSample( double x = 0.0, double y = 0.0,
264 double vx = 0.0, double vy = 0.0 );
265
266 QwtVectorFieldSample( const QPointF& pos,
267 double vx = 0.0, double vy = 0.0 );
268
269 QPointF pos() const;
270
271 bool isNull() const;
272
274 double x;
275
277 double y;
278
280 double vx;
281
283 double vy;
284};
285
295 double posX, double posY, double vectorX, double vectorY )
296 : x( posX )
297 , y( posY )
298 , vx( vectorX )
299 , vy( vectorY )
300{
301}
302
311 const QPointF& pos, double vectorX, double vectorY )
312 : x( pos.x() )
313 , y( pos.y() )
314 , vx( vectorX )
315 , vy( vectorY )
316{
317}
318
320inline QPointF QwtVectorFieldSample::pos() const
321{
322 return QPointF( x, y );
323}
324
327{
328 return ( vx == 0.0 ) && ( vy == 0.0 );
329}
330
331#endif
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition qwt_samples.h:38
QwtInterval interval
Interval.
Definition qwt_samples.h:51
bool operator==(const QwtIntervalSample &) const
Compare operator.
Definition qwt_samples.h:78
bool operator!=(const QwtIntervalSample &) const
Compare operator.
Definition qwt_samples.h:84
QwtIntervalSample()
Constructor The value is set to 0.0, the interval is invalid.
Definition qwt_samples.h:58
double value
Value.
Definition qwt_samples.h:48
A class representing an interval.
Definition qwt_interval.h:40
Open-High-Low-Close sample used in financial charts.
Definition qwt_samples.h:161
double high
Highest price.
Definition qwt_samples.h:181
bool isValid() const
Check if a sample is valid.
Definition qwt_samples.h:220
double open
Opening price.
Definition qwt_samples.h:178
double close
Closing price.
Definition qwt_samples.h:187
double time
Time of the sample, usually a number representing a specific interval - like a day.
Definition qwt_samples.h:175
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
Definition qwt_samples.h:237
QwtOHLCSample(double time=0.0, double open=0.0, double high=0.0, double low=0.0, double close=0.0)
Constructor.
Definition qwt_samples.h:199
double low
Lowest price.
Definition qwt_samples.h:184
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition qwt_samples.h:91
double added() const
Definition qwt_samples.h:142
double value
value
Definition qwt_samples.h:102
QVector< double > set
Vector of values associated to value.
Definition qwt_samples.h:105
bool operator!=(const QwtSetSample &other) const
Compare operator.
Definition qwt_samples.h:136
bool operator==(const QwtSetSample &other) const
Compare operator.
Definition qwt_samples.h:130
QwtSetSample()
Constructor The value is set to 0.0.
Definition qwt_samples.h:112
Sample used in vector fields.
Definition qwt_samples.h:261
double y
y coordinate of the position
Definition qwt_samples.h:277
QwtVectorFieldSample(double x=0.0, double y=0.0, double vx=0.0, double vy=0.0)
Constructor.
Definition qwt_samples.h:294
QPointF pos() const
Definition qwt_samples.h:320
bool isNull() const
Definition qwt_samples.h:326
double vx
x coordinate of the vector
Definition qwt_samples.h:280
double x
x coordinate of the position
Definition qwt_samples.h:274
double vy
y coordinate of the vector
Definition qwt_samples.h:283