qwt_series_data.h
/******************************************************************************
* 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
#include "qwt_global.h"
#include "qwt_samples.h"
#include "qwt_point_3d.h"
#include <qvector.h>
#include <qrect.h>
class QwtPointPolar;
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 cachedBoundingRect; }
#endif
virtual void setRectOfInterest( const QRectF& rect );
protected:
mutable QRectF cachedBoundingRect;
private:
QwtSeriesData< T >& operator=( const QwtSeriesData< T >& );
};
template< typename T >
QwtSeriesData< T >::QwtSeriesData()
: cachedBoundingRect( 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();
explicit QwtArraySeriesData( const QVector< T >& samples );
void setSamples( const QVector< T >& samples );
const QVector< T > samples() const;
virtual size_t size() const QWT_OVERRIDE;
virtual T sample( size_t index ) const QWT_OVERRIDE;
protected:
QVector< T > m_samples;
};
template< typename T >
QwtArraySeriesData< T >::QwtArraySeriesData()
{
}
template< typename T >
QwtArraySeriesData< T >::QwtArraySeriesData( const QVector< T >& samples )
: m_samples( samples )
{
}
template< typename T >
void QwtArraySeriesData< T >::setSamples( const QVector< T >& samples )
{
QwtSeriesData< T >::cachedBoundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
m_samples = samples;
}
template< typename T >
const QVector< T > QwtArraySeriesData< T >::samples() const
{
return m_samples;
}
template< typename T >
size_t QwtArraySeriesData< T >::size() const
{
return m_samples.size();
}
template< typename T >
T QwtArraySeriesData< T >::sample( size_t i ) const
{
return m_samples[ static_cast< int >( i ) ];
}
class QWT_EXPORT QwtPointSeriesData : public QwtArraySeriesData< QPointF >
{
public:
QwtPointSeriesData(
const QVector< QPointF >& = QVector< QPointF >( ) );
virtual QRectF boundingRect() const QWT_OVERRIDE;
};
class QWT_EXPORT QwtPoint3DSeriesData : public QwtArraySeriesData< QwtPoint3D >
{
public:
QwtPoint3DSeriesData(
const QVector< QwtPoint3D >& = QVector< QwtPoint3D >( ) );
virtual QRectF boundingRect() const QWT_OVERRIDE;
};
class QWT_EXPORT QwtIntervalSeriesData : public QwtArraySeriesData< QwtIntervalSample >
{
public:
QwtIntervalSeriesData(
const QVector< QwtIntervalSample >& = QVector< QwtIntervalSample >( ) );
virtual QRectF boundingRect() const QWT_OVERRIDE;
};
class QWT_EXPORT QwtSetSeriesData : public QwtArraySeriesData< QwtSetSample >
{
public:
QwtSetSeriesData(
const QVector< QwtSetSample >& = QVector< QwtSetSample >( ) );
virtual QRectF boundingRect() const QWT_OVERRIDE;
};
class QWT_EXPORT QwtVectorFieldData : public QwtArraySeriesData< QwtVectorFieldSample >
{
public:
QwtVectorFieldData(
const QVector< QwtVectorFieldSample >& = QVector< QwtVectorFieldSample >( ) );
virtual QRectF boundingRect() const QWT_OVERRIDE;
};
class QWT_EXPORT QwtTradingChartData : public QwtArraySeriesData< QwtOHLCSample >
{
public:
QwtTradingChartData(
const QVector< QwtOHLCSample >& = QVector< QwtOHLCSample >( ) );
virtual QRectF boundingRect() const QWT_OVERRIDE;
};
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 );
QWT_EXPORT QRectF qwtBoundingRect(
const QwtSeriesData< QwtVectorFieldSample >&, 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
QVector
Definition: qwt_clipper.h:23
QwtArraySeriesData
Template class for data, that is organized as QVector.
Definition: qwt_series_data.h:136
QwtArraySeriesData::sample
virtual T sample(size_t index) const override
Definition: qwt_series_data.h:203
QwtArraySeriesData::size
virtual size_t size() const override
Definition: qwt_series_data.h:197
QwtArraySeriesData::QwtArraySeriesData
QwtArraySeriesData()
Constructor.
Definition: qwt_series_data.h:173
QwtArraySeriesData::setSamples
void setSamples(const QVector< T > &samples)
Definition: qwt_series_data.h:184
QwtArraySeriesData::QwtArraySeriesData
QwtArraySeriesData(const QVector< T > &samples)
Definition: qwt_series_data.h:178
QwtArraySeriesData::m_samples
QVector< T > m_samples
Vector of samples.
Definition: qwt_series_data.h:169
QwtArraySeriesData::samples
const QVector< T > samples() const
Definition: qwt_series_data.h:191
QwtIntervalSeriesData
Interface for iterating over an array of intervals.
Definition: qwt_series_data.h:230
QwtPoint3DSeriesData
Interface for iterating over an array of 3D points.
Definition: qwt_series_data.h:220
QwtPointPolar
A point in polar coordinates.
Definition: qwt_point_polar.h:29
QwtPointSeriesData
Interface for iterating over an array of points.
Definition: qwt_series_data.h:210
QwtSeriesData
Abstract interface for iterating over samples.
Definition: qwt_series_data.h:50
QwtSeriesData::setRectOfInterest
virtual void setRectOfInterest(const QRectF &rect)
Definition: qwt_series_data.h:124
QwtSeriesData::size
virtual size_t size() const =0
QwtSeriesData::QwtSeriesData
QwtSeriesData()
Constructor.
Definition: qwt_series_data.h:113
QwtSeriesData::~QwtSeriesData
virtual ~QwtSeriesData()
Destructor.
Definition: qwt_series_data.h:119
QwtSeriesData::cachedBoundingRect
QRectF cachedBoundingRect
Can be used to cache a calculated bounding rectangle.
Definition: qwt_series_data.h:106
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtSeriesData::boundingRect
virtual QRectF boundingRect() const =0
QwtSetSeriesData
Interface for iterating over an array of samples.
Definition: qwt_series_data.h:240
QwtTradingChartData
Definition: qwt_series_data.h:262
QwtVectorFieldData
Interface for iterating over an array of vector field samples.
Definition: qwt_series_data.h:250