您的位置:首页 > 其它

Qwt源码解读之样本类——QwtIntervalSample、QwtSetSample、QwtOHLCSample

2014-07-11 13:56 218 查看
QwtIntervalSample类

A sample of the types (x1-x2, y) or (x, y1-y2)

QwtIntervalSample类表征一个区间样点。

class QWT_EXPORT QwtIntervalSample
{
public:
QwtIntervalSample();// value初始为0,interval为一个无效的区间[0.0. -1.0]
QwtIntervalSample( double, const QwtInterval & );
QwtIntervalSample( double value, double min, double max );

bool operator==( const QwtIntervalSample & ) const;
bool operator!=( const QwtIntervalSample & ) const;

//! Value
double value;//值

//! Interval
QwtInterval interval;//区间
};
这个类十分简单。成员变量声明为public,因此只提供了简单的构造函数和==、!=操作符。

QwtSetSample类

A sample of the types (x1...xn, y) or (x, y1..yn)

class QWT_EXPORT QwtSetSample
{
public:
QwtSetSample();
QwtSetSample( double, const QVector<double> & = QVector<double>() );

bool operator==( const QwtSetSample &other ) const;
bool operator!=( const QwtSetSample &other ) const;

double added() const;

//! value
double value;

//! Vector of values associated to value
QVector<double> set;
};
一个成员函数
//! \return All values of the set added
inline double QwtSetSample::added() const
{
double y = 0.0;
for ( int i = 0; i < set.size(); i++ )
y += set[i];

return y;
}
返回set中所有值的和。

QwtOHLCSample类

/*!
\brief Open-High-Low-Close sample used in financial charts

In financial charts the movement of a price in a time interval is often
represented by the opening/closing prices and the lowest/highest prices
in this interval.

\sa QwtTradingChartData
*/
class QWT_EXPORT QwtOHLCSample
{
public:
QwtOHLCSample( double time = 0.0,
double open = 0.0, double high = 0.0,
double low = 0.0, double close = 0.0 );

QwtInterval boundingInterval() const;

bool isValid() const;

/*!
Time of the sample, usually a number representing
a specific interval - like a day.
*/
double time;

//! Opening price
double open;

//! Highest price
double high;

//! Lowest price
double low;

//! Closing price
double close;
};
成员函数

/*!
\brief Check if a sample is valid

A sample is valid, when all of the following checks are true:

- low <= high
- low <= open <= high
- low <= close <= high

\return True, when the sample is valid
*/
inline bool QwtOHLCSample::isValid() const
{
return ( low <= high )
&& ( open >= low )
&& ( open <= high )
&& ( close >= low )
&& ( close <= high );
}
/*!
\brief Calculate the bounding interval of the OHLC values

For valid samples the limits of this interval are always low/high.

\return Bounding interval
\sa isValid()
*/
inline QwtInterval QwtOHLCSample::boundingInterval() const
{
double minY = open;
minY = qMin( minY, high );
minY = qMin( minY, low );
minY = qMin( minY, close );

double maxY = open;
maxY = qMax( maxY, high );
maxY = qMax( maxY, low );
maxY = qMax( maxY, close );

return QwtInterval( minY, maxY );
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: