All Classes Functions Variables Typedefs Enumerations Enumerator Pages
qwt_series_store.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_STORE_H
#define QWT_SERIES_STORE_H
#include "qwt_global.h"
#include "qwt_series_data.h"
class QwtAbstractSeriesStore
{
protected:
virtual ~QwtAbstractSeriesStore() {}
virtual void dataChanged() = 0;
virtual void setRectOfInterest( const QRectF & ) = 0;
virtual QRectF dataRect() const = 0;
virtual size_t dataSize() const = 0;
};
template <typename T>
class QwtSeriesStore: public virtual QwtAbstractSeriesStore
{
public:
explicit QwtSeriesStore<T>();
~QwtSeriesStore<T>();
void setData( QwtSeriesData<T> *series );
QwtSeriesData<T> *data();
const QwtSeriesData<T> *data() const;
T sample( int index ) const;
virtual size_t dataSize() const;
virtual QRectF dataRect() const;
virtual void setRectOfInterest( const QRectF &rect );
QwtSeriesData<T> *swapData( QwtSeriesData<T> *series );
private:
QwtSeriesData<T> *d_series;
};
template <typename T>
QwtSeriesStore<T>::QwtSeriesStore():
d_series( NULL )
{
}
template <typename T>
QwtSeriesStore<T>::~QwtSeriesStore()
{
delete d_series;
}
template <typename T>
inline QwtSeriesData<T> *QwtSeriesStore<T>::data()
{
return d_series;
}
template <typename T>
inline const QwtSeriesData<T> *QwtSeriesStore<T>::data() const
{
return d_series;
}
template <typename T>
inline T QwtSeriesStore<T>::sample( int index ) const
{
return d_series ? d_series->sample( index ) : T();
}
template <typename T>
void QwtSeriesStore<T>::setData( QwtSeriesData<T> *series )
{
if ( d_series != series )
{
delete d_series;
d_series = series;
dataChanged();
}
}
template <typename T>
size_t QwtSeriesStore<T>::dataSize() const
{
if ( d_series == NULL )
return 0;
return d_series->size();
}
template <typename T>
QRectF QwtSeriesStore<T>::dataRect() const
{
if ( d_series == NULL )
return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
return d_series->boundingRect();
}
template <typename T>
void QwtSeriesStore<T>::setRectOfInterest( const QRectF &rect )
{
if ( d_series )
d_series->setRectOfInterest( rect );
}
template <typename T>
QwtSeriesData<T>* QwtSeriesStore<T>::swapData( QwtSeriesData<T> *series )
{
QwtSeriesData<T> * swappedSeries = d_series;
d_series = series;
return swappedSeries;
}
#endif