All Classes Functions Variables Typedefs Enumerations Enumerator Pages
qwt_series_data.h
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef QWT_SERIES_DATA_H
#define QWT_SERIES_DATA_H 1
#include "qwt_global.h"
#include "qwt_samples.h"
#include "qwt_point_3d.h"
#include "qwt_point_polar.h"
#include <qvector.h>
#include <qrect.h>
template <typename T>
class QwtSeriesData
{
public:
QwtSeriesData();
virtual ~QwtSeriesData();
virtual size_t size() const = 0;
virtual T sample( size_t i ) const = 0;
virtual QRectF boundingRect() const = 0;
virtual void setRectOfInterest( const QRectF &rect );
protected:
mutable QRectF d_boundingRect;
private:
QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
};
template <typename T>
QwtSeriesData<T>::QwtSeriesData():
d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
{
}
template <typename T>
QwtSeriesData<T>::~QwtSeriesData()
{
}
template <typename T>
void QwtSeriesData<T>::setRectOfInterest( const QRectF & )
{
}
template <typename T>
class QwtArraySeriesData: public QwtSeriesData<T>
{
public:
QwtArraySeriesData();
QwtArraySeriesData( const QVector<T> &samples );
void setSamples( const QVector<T> &samples );
const QVector<T> samples() const;
virtual size_t size() const;
virtual T sample( size_t index ) const;
protected:
QVector<T> d_samples;
};
template <typename T>
QwtArraySeriesData<T>::QwtArraySeriesData()
{
}
template <typename T>
QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
d_samples( samples )
{
}
template <typename T>
void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
{
QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
d_samples = samples;
}
template <typename T>
const QVector<T> QwtArraySeriesData<T>::samples() const
{
return d_samples;
}
template <typename T>
size_t QwtArraySeriesData<T>::size() const
{
return d_samples.size();
}
template <typename T>
T QwtArraySeriesData<T>::sample( size_t i ) const
{
return d_samples[ static_cast<int>( i ) ];
}
class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF>
{
public:
QwtPointSeriesData(
const QVector<QPointF> & = QVector<QPointF>() );
virtual QRectF boundingRect() const;
};
class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D>
{
public:
QwtPoint3DSeriesData(
const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
virtual QRectF boundingRect() const;
};
class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
{
public:
QwtIntervalSeriesData(
const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
virtual QRectF boundingRect() const;
};
class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
{
public:
QwtSetSeriesData(
const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
virtual QRectF boundingRect() const;
};
class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample>
{
public:
QwtTradingChartData(
const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() );
virtual QRectF boundingRect() const;
};
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 );
template <typename T, typename LessThan>
inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series,
double value, LessThan lessThan )
{
const int indexMax = series.size() - 1;
if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
return -1;
int indexMin = 0;
int n = indexMax;
while ( n > 0 )
{
const int half = n >> 1;
const int indexMid = indexMin + half;
if ( lessThan( value, series.sample( indexMid ) ) )
{
n = half;
}
else
{
indexMin = indexMid + 1;
n -= half + 1;
}
}
return indexMin;
}
#endif