Loading...
Searching...
No Matches
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;
#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(); }
#endif
inline T firstSample() const { return sample( 0 ); }
inline T lastSample() const { return sample( size() - 1 ); }
virtual QRectF boundingRect() const
{
if ( cachedBoundingRect.width() < 0.0 )
cachedBoundingRect = qwtBoundingRect( *this );
return cachedBoundingRect;
}
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 ) ];
}
typedef QwtArraySeriesData< QPointF > QwtPointSeriesData;
typedef QwtArraySeriesData< QwtPoint3D > QwtPoint3DSeriesData;
typedef QwtArraySeriesData< QwtIntervalSample > QwtIntervalSeriesData;
typedef QwtArraySeriesData< QwtSetSample > QwtSetSeriesData;
typedef QwtArraySeriesData< QwtVectorFieldSample > QwtVectorFieldData;
typedef QwtArraySeriesData< QwtOHLCSample > QwtTradingChartData;
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:153
QwtArraySeriesData::sample
virtual T sample(size_t index) const override
Definition qwt_series_data.h:220
QwtArraySeriesData::size
virtual size_t size() const override
Definition qwt_series_data.h:214
QwtArraySeriesData::QwtArraySeriesData
QwtArraySeriesData()
Constructor.
Definition qwt_series_data.h:190
QwtArraySeriesData::setSamples
void setSamples(const QVector< T > &samples)
Definition qwt_series_data.h:201
QwtArraySeriesData::m_samples
QVector< T > m_samples
Vector of samples.
Definition qwt_series_data.h:186
QwtArraySeriesData::samples
const QVector< T > samples() const
Definition qwt_series_data.h:208
QwtPointPolar
A point in polar coordinates.
Definition qwt_point_polar.h:29
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:141
QwtSeriesData::size
virtual size_t size() const =0
QwtSeriesData::QwtSeriesData
QwtSeriesData()
Constructor.
Definition qwt_series_data.h:130
QwtSeriesData::~QwtSeriesData
virtual ~QwtSeriesData()
Destructor.
Definition qwt_series_data.h:136
QwtSeriesData::cachedBoundingRect
QRectF cachedBoundingRect
Can be used to cache a calculated bounding rectangle.
Definition qwt_series_data.h:123
QwtSeriesData::lastSample
T lastSample() const
Definition qwt_series_data.h:86
QwtSeriesData::boundingRect
virtual QRectF boundingRect() const
Definition qwt_series_data.h:100
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtSeriesData::firstSample
T firstSample() const
Definition qwt_series_data.h:80