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();
#ifndef QWT_PYTHON_WRAPPER
virtual size_t size() const = 0;
virtual T sample( size_t i ) const = 0;
virtual QRectF boundingRect() const = 0;
#else
// Needed for generating the python bindings, but not for using them !
virtual size_t size() const { return 0; }
virtual T sample( size_t i ) const { return T(); }
virtual QRectF boundingRect() const { return d_boundingRect; }
#endif
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
QwtArraySeriesData::setSamples
void setSamples(const QVector< T > &samples)
Definition: qwt_series_data.h:182
QwtSeriesData::QwtSeriesData
QwtSeriesData()
Constructor.
Definition: qwt_series_data.h:111
QwtPointSeriesData
Interface for iterating over an array of points.
Definition: qwt_series_data.h:207
QwtTradingChartData
Definition: qwt_series_data.h:248
QwtSetSeriesData
Interface for iterating over an array of samples.
Definition: qwt_series_data.h:236
QwtSeriesData::boundingRect
virtual QRectF boundingRect() const =0
QwtArraySeriesData::d_samples
QVector< T > d_samples
Vector of samples.
Definition: qwt_series_data.h:167
QwtIntervalSeriesData
Interface for iterating over an array of intervals.
Definition: qwt_series_data.h:226
QwtArraySeriesData::QwtArraySeriesData
QwtArraySeriesData()
Constructor.
Definition: qwt_series_data.h:171
QwtSeriesData::setRectOfInterest
virtual void setRectOfInterest(const QRectF &rect)
Definition: qwt_series_data.h:122
QwtSeriesData
Abstract interface for iterating over samples.
Definition: qwt_series_data.h:47
QwtArraySeriesData::samples
const QVector< T > samples() const
Definition: qwt_series_data.h:189
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtArraySeriesData
Template class for data, that is organized as QVector.
Definition: qwt_series_data.h:133
QwtArraySeriesData::sample
virtual T sample(size_t index) const
Definition: qwt_series_data.h:201
QwtArraySeriesData::size
virtual size_t size() const
Definition: qwt_series_data.h:195
QwtSeriesData::d_boundingRect
QRectF d_boundingRect
Can be used to cache a calculated bounding rectangle.
Definition: qwt_series_data.h:104
QwtSeriesData::~QwtSeriesData
virtual ~QwtSeriesData()
Destructor.
Definition: qwt_series_data.h:117
QwtPoint3DSeriesData
Interface for iterating over an array of 3D points.
Definition: qwt_series_data.h:217
QwtSeriesData::size
virtual size_t size() const =0