Qwt User's Guide 6.3.0
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
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
20class QWT_EXPORT QwtIntervalSample
21{
22 public:
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
35};
36
42 : value( 0.0 )
43{
44}
45
48 : value( v )
49 , interval( intv )
50{
51}
52
54inline QwtIntervalSample::QwtIntervalSample( double v, double min, double max )
55 : value( v )
56 , interval( min, max )
57{
58}
59
61inline bool QwtIntervalSample::operator==( const QwtIntervalSample& other ) const
62{
63 return value == other.value && interval == other.interval;
64}
65
67inline bool QwtIntervalSample::operator!=( const QwtIntervalSample& other ) const
68{
69 return !( *this == other );
70}
71
73class QWT_EXPORT QwtSetSample
74{
75 public:
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
89};
90
96 : value( 0.0 )
97{
98}
99
107 : value( v )
108 , set( s )
109{
110}
111
113inline bool QwtSetSample::operator==( const QwtSetSample& other ) const
114{
115 return value == other.value && set == other.set;
116}
117
119inline bool QwtSetSample::operator!=( const QwtSetSample& other ) const
120{
121 return !( *this == other );
122}
123
125inline 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
143class 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
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
203inline bool QwtOHLCSample::isValid() const
204{
205 return ( low <= high )
206 && ( open >= low )
207 && ( open <= high )
208 && ( close >= low )
209 && ( close <= high );
210}
211
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
243class 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
278 double posX, double posY, double vectorX, double vectorY )
279 : x( posX )
280 , y( posY )
281 , vx( vectorX )
282 , vy( vectorY )
283{
284}
285
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
303inline QPointF QwtVectorFieldSample::pos() const
304{
305 return QPointF( x, y );
306}
307
310{
311 return ( vx == 0.0 ) && ( vy == 0.0 );
312}
313
314#endif
A class representing an interval.
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition qwt_samples.h:21
QwtInterval interval
Interval.
Definition qwt_samples.h:34
bool operator==(const QwtIntervalSample &) const
Compare operator.
Definition qwt_samples.h:61
bool operator!=(const QwtIntervalSample &) const
Compare operator.
Definition qwt_samples.h:67
double value
Value.
Definition qwt_samples.h:31
Open-High-Low-Close sample used in financial charts.
double high
Highest price.
bool isValid() const
Check if a sample is valid.
double open
Opening price.
double close
Closing price.
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
QwtOHLCSample(double time=0.0, double open=0.0, double high=0.0, double low=0.0, double close=0.0)
double low
Lowest price.
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition qwt_samples.h:74
double added() const
double value
value
Definition qwt_samples.h:85
QVector< double > set
Vector of values associated to value.
Definition qwt_samples.h:88
bool operator!=(const QwtSetSample &other) const
Compare operator.
bool operator==(const QwtSetSample &other) const
Compare operator.
Sample used in vector fields.
double y
y coordinate of the position
QwtVectorFieldSample(double x=0.0, double y=0.0, double vx=0.0, double vy=0.0)
Constructor.
QPointF pos() const
bool isNull() const
double vx
x coordinate of the vector
double x
x coordinate of the position
double vy
y coordinate of the vector