Qwt User's Guide
|
00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** 00002 * Qwt Widget Library 00003 * Copyright (C) 1997 Josef Wilgen 00004 * Copyright (C) 2002 Uwe Rathmann 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the Qwt License, Version 1.0 00008 *****************************************************************************/ 00009 00010 #ifndef QWT_SAMPLES_H 00011 #define QWT_SAMPLES_H 1 00012 00013 #include "qwt_global.h" 00014 #include "qwt_interval.h" 00015 #include <qvector.h> 00016 #include <qrect.h> 00017 00019 class QWT_EXPORT QwtIntervalSample 00020 { 00021 public: 00022 QwtIntervalSample(); 00023 QwtIntervalSample( double, const QwtInterval & ); 00024 QwtIntervalSample( double value, double min, double max ); 00025 00026 bool operator==( const QwtIntervalSample & ) const; 00027 bool operator!=( const QwtIntervalSample & ) const; 00028 00030 double value; 00031 00033 QwtInterval interval; 00034 }; 00035 00040 inline QwtIntervalSample::QwtIntervalSample(): 00041 value( 0.0 ) 00042 { 00043 } 00044 00046 inline QwtIntervalSample::QwtIntervalSample( 00047 double v, const QwtInterval &intv ): 00048 value( v ), 00049 interval( intv ) 00050 { 00051 } 00052 00054 inline QwtIntervalSample::QwtIntervalSample( 00055 double v, double min, double max ): 00056 value( v ), 00057 interval( min, max ) 00058 { 00059 } 00060 00062 inline bool QwtIntervalSample::operator==( 00063 const QwtIntervalSample &other ) const 00064 { 00065 return value == other.value && interval == other.interval; 00066 } 00067 00069 inline bool QwtIntervalSample::operator!=( 00070 const QwtIntervalSample &other ) const 00071 { 00072 return !( *this == other ); 00073 } 00074 00076 class QWT_EXPORT QwtSetSample 00077 { 00078 public: 00079 QwtSetSample(); 00080 QwtSetSample( double, const QVector<double> & = QVector<double>() ); 00081 00082 bool operator==( const QwtSetSample &other ) const; 00083 bool operator!=( const QwtSetSample &other ) const; 00084 00085 double added() const; 00086 00088 double value; 00089 00091 QVector<double> set; 00092 }; 00093 00098 inline QwtSetSample::QwtSetSample(): 00099 value( 0.0 ) 00100 { 00101 } 00102 00109 inline QwtSetSample::QwtSetSample( double v, const QVector< double > &s ): 00110 value( v ), 00111 set( s ) 00112 { 00113 } 00114 00116 inline bool QwtSetSample::operator==( const QwtSetSample &other ) const 00117 { 00118 return value == other.value && set == other.set; 00119 } 00120 00122 inline bool QwtSetSample::operator!=( const QwtSetSample &other ) const 00123 { 00124 return !( *this == other ); 00125 } 00126 00128 inline double QwtSetSample::added() const 00129 { 00130 double y = 0.0; 00131 for ( int i = 0; i < set.size(); i++ ) 00132 y += set[i]; 00133 00134 return y; 00135 } 00136 00146 class QWT_EXPORT QwtOHLCSample 00147 { 00148 public: 00149 QwtOHLCSample( double time = 0.0, 00150 double open = 0.0, double high = 0.0, 00151 double low = 0.0, double close = 0.0 ); 00152 00153 QwtInterval boundingInterval() const; 00154 00155 bool isValid() const; 00156 00161 double time; 00162 00164 double open; 00165 00167 double high; 00168 00170 double low; 00171 00173 double close; 00174 }; 00175 00176 00186 inline QwtOHLCSample::QwtOHLCSample( double t, 00187 double o, double h, double l, double c ): 00188 time( t ), 00189 open( o ), 00190 high( h ), 00191 low( l ), 00192 close( c ) 00193 { 00194 } 00195 00207 inline bool QwtOHLCSample::isValid() const 00208 { 00209 return ( low <= high ) 00210 && ( open >= low ) 00211 && ( open <= high ) 00212 && ( close >= low ) 00213 && ( close <= high ); 00214 } 00215 00224 inline QwtInterval QwtOHLCSample::boundingInterval() const 00225 { 00226 double minY = open; 00227 minY = qMin( minY, high ); 00228 minY = qMin( minY, low ); 00229 minY = qMin( minY, close ); 00230 00231 double maxY = open; 00232 maxY = qMax( maxY, high ); 00233 maxY = qMax( maxY, low ); 00234 maxY = qMax( maxY, close ); 00235 00236 return QwtInterval( minY, maxY ); 00237 } 00238 00239 #endif