Qwt User's Guide 6.2.0

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
10 #ifndef QWT_SAMPLES_H
11 #define QWT_SAMPLES_H
12
13 #include "qwt_global.h"
14 #include "qwt_interval.h"
15
16 #include <qvector.h>
17 #include <qrect.h>
18
20 class QWT_EXPORT QwtIntervalSample
21 {
22 public:
23 QwtIntervalSample();
24 QwtIntervalSample( double, const QwtInterval& );
25 QwtIntervalSample( double value, double min, double max );
26
27 bool operator==( const QwtIntervalSample& ) const;
28 bool operator!=( const QwtIntervalSample& ) const;
29
31 double value;
32
34 QwtInterval interval;
35 };
36
41 inline QwtIntervalSample::QwtIntervalSample()
42 : value( 0.0 )
43 {
44 }
45
47 inline QwtIntervalSample::QwtIntervalSample( double v, const QwtInterval& intv )
48 : value( v )
49 , interval( intv )
50 {
51 }
52
54 inline QwtIntervalSample::QwtIntervalSample( double v, double min, double max )
55 : value( v )
56 , interval( min, max )
57 {
58 }
59
61 inline bool QwtIntervalSample::operator==( const QwtIntervalSample& other ) const
62 {
63 return value == other.value && interval == other.interval;
64 }
65
67 inline bool QwtIntervalSample::operator!=( const QwtIntervalSample& other ) const
68 {
69 return !( *this == other );
70 }
71
73 class QWT_EXPORT QwtSetSample
74 {
75 public:
76 QwtSetSample();
77 explicit QwtSetSample( double, const QVector< double >& = QVector< double >( ) );
78
79 bool operator==( const QwtSetSample& other ) const;
80 bool operator!=( const QwtSetSample& other ) const;
81
82 double added() const;
83
85 double value;
86
88 QVector< double > set;
89 };
90
95 inline QwtSetSample::QwtSetSample()
96 : value( 0.0 )
97 {
98 }
99
106 inline QwtSetSample::QwtSetSample( double v, const QVector< double >& s )
107 : value( v )
108 , set( s )
109 {
110 }
111
113 inline bool QwtSetSample::operator==( const QwtSetSample& other ) const
114 {
115 return value == other.value && set == other.set;
116 }
117
119 inline bool QwtSetSample::operator!=( const QwtSetSample& other ) const
120 {
121 return !( *this == other );
122 }
123
125 inline double QwtSetSample::added() const
126 {
127 double y = 0.0;
128 for ( int i = 0; i < set.size(); i++ )
129 y += set[i];
130
131 return y;
132 }
133
143 class QWT_EXPORT QwtOHLCSample
144 {
145 public:
146 QwtOHLCSample( double time = 0.0,
147 double open = 0.0, double high = 0.0,
148 double low = 0.0, double close = 0.0 );
149
150 QwtInterval boundingInterval() const;
151
152 bool isValid() const;
153
158 double time;
159
161 double open;
162
164 double high;
165
167 double low;
168
170 double close;
171 };
172
182 inline QwtOHLCSample::QwtOHLCSample(
183 double t, double o, double h, double l, double c )
184 : time( t )
185 , open( o )
186 , high( h )
187 , low( l )
188 , close( c )
189 {
190 }
191
203 inline bool QwtOHLCSample::isValid() const
204 {
205 return ( low <= high )
206 && ( open >= low )
207 && ( open <= high )
208 && ( close >= low )
209 && ( close <= high );
210 }
211
220 inline QwtInterval QwtOHLCSample::boundingInterval() const
221 {
222 double minY = open;
223 minY = qMin( minY, high );
224 minY = qMin( minY, low );
225 minY = qMin( minY, close );
226
227 double maxY = open;
228 maxY = qMax( maxY, high );
229 maxY = qMax( maxY, low );
230 maxY = qMax( maxY, close );
231
232 return QwtInterval( minY, maxY );
233 }
234
243 class QWT_EXPORT QwtVectorFieldSample
244 {
245 public:
246 QwtVectorFieldSample( double x = 0.0, double y = 0.0,
247 double vx = 0.0, double vy = 0.0 );
248
249 QwtVectorFieldSample( const QPointF& pos,
250 double vx = 0.0, double vy = 0.0 );
251
252 QPointF pos() const;
253
254 bool isNull() const;
255
257 double x;
258
260 double y;
261
263 double vx;
264
266 double vy;
267 };
268
277 inline QwtVectorFieldSample::QwtVectorFieldSample(
278 double posX, double posY, double vectorX, double vectorY )
279 : x( posX )
280 , y( posY )
281 , vx( vectorX )
282 , vy( vectorY )
283 {
284 }
285
293 inline QwtVectorFieldSample::QwtVectorFieldSample(
294 const QPointF& pos, double vectorX, double vectorY )
295 : x( pos.x() )
296 , y( pos.y() )
297 , vx( vectorX )
298 , vy( vectorY )
299 {
300 }
301
303 inline QPointF QwtVectorFieldSample::pos() const
304 {
305 return QPointF( x, y );
306 }
307
309 inline bool QwtVectorFieldSample::isNull() const
310 {
311 return ( vx == 0.0 ) && ( vy == 0.0 );
312 }
313
314 #endif
QVector< double >
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:23
QwtIntervalSample
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition: qwt_samples.h:21
QwtIntervalSample::interval
QwtInterval interval
Interval.
Definition: qwt_samples.h:34
QwtIntervalSample::operator==
bool operator==(const QwtIntervalSample &) const
Compare operator.
Definition: qwt_samples.h:61
QwtIntervalSample::operator!=
bool operator!=(const QwtIntervalSample &) const
Compare operator.
Definition: qwt_samples.h:67
QwtIntervalSample::QwtIntervalSample
QwtIntervalSample()
Definition: qwt_samples.h:41
QwtIntervalSample::value
double value
Value.
Definition: qwt_samples.h:31
QwtOHLCSample
Open-High-Low-Close sample used in financial charts.
Definition: qwt_samples.h:144
QwtOHLCSample::high
double high
Highest price.
Definition: qwt_samples.h:164
QwtOHLCSample::isValid
bool isValid() const
Check if a sample is valid.
Definition: qwt_samples.h:203
QwtOHLCSample::open
double open
Opening price.
Definition: qwt_samples.h:161
QwtOHLCSample::close
double close
Closing price.
Definition: qwt_samples.h:170
QwtOHLCSample::time
double time
Definition: qwt_samples.h:158
QwtOHLCSample::boundingInterval
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
Definition: qwt_samples.h:220
QwtOHLCSample::QwtOHLCSample
QwtOHLCSample(double time=0.0, double open=0.0, double high=0.0, double low=0.0, double close=0.0)
Definition: qwt_samples.h:182
QwtOHLCSample::low
double low
Lowest price.
Definition: qwt_samples.h:167
QwtSetSample
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition: qwt_samples.h:74
QwtSetSample::added
double added() const
Definition: qwt_samples.h:125
QwtSetSample::value
double value
value
Definition: qwt_samples.h:85
QwtSetSample::set
QVector< double > set
Vector of values associated to value.
Definition: qwt_samples.h:88
QwtSetSample::operator!=
bool operator!=(const QwtSetSample &other) const
Compare operator.
Definition: qwt_samples.h:119
QwtSetSample::operator==
bool operator==(const QwtSetSample &other) const
Compare operator.
Definition: qwt_samples.h:113
QwtSetSample::QwtSetSample
QwtSetSample()
Definition: qwt_samples.h:95
QwtVectorFieldSample
Sample used in vector fields.
Definition: qwt_samples.h:244
QwtVectorFieldSample::y
double y
y coordinate of the position
Definition: qwt_samples.h:260
QwtVectorFieldSample::QwtVectorFieldSample
QwtVectorFieldSample(double x=0.0, double y=0.0, double vx=0.0, double vy=0.0)
Constructor.
Definition: qwt_samples.h:277
QwtVectorFieldSample::pos
QPointF pos() const
Definition: qwt_samples.h:303
QwtVectorFieldSample::isNull
bool isNull() const
Definition: qwt_samples.h:309
QwtVectorFieldSample::vx
double vx
x coordinate of the vector
Definition: qwt_samples.h:263
QwtVectorFieldSample::x
double x
x coordinate of the position
Definition: qwt_samples.h:257
QwtVectorFieldSample::vy
double vy
y coordinate of the vector
Definition: qwt_samples.h:266