/* -*- 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" /*! \brief Bridge between QwtSeriesStore and QwtPlotSeriesItem QwtAbstractSeriesStore is an abstract interface only to make it possible to isolate the template based methods ( QwtSeriesStore ) from the regular methods ( QwtPlotSeriesItem ) to make it possible to derive from QwtPlotSeriesItem without any hassle with templates. */ class QwtAbstractSeriesStore { protected: //! Destructor virtual ~QwtAbstractSeriesStore() {} //! dataChanged() indicates, that the series has been changed. virtual void dataChanged() = 0; /*! Set a the "rectangle of interest" for the stored series \sa QwtSeriesData::setRectOfInterest() */ virtual void setRectOfInterest( const QRectF & ) = 0; //! \return Bounding rectangle of the stored series virtual QRectF dataRect() const = 0; //! \return Number of samples virtual size_t dataSize() const = 0; }; /*! \brief Class storing a QwtSeriesData object QwtSeriesStore and QwtPlotSeriesItem are intended as base classes for all plot items iterating over a series of samples. Both classes share a virtual base class ( QwtAbstractSeriesStore ) to bridge between them. QwtSeriesStore offers the template based part for the plot item API, so that QwtPlotSeriesItem can be derived without any hassle with templates. */ template class QwtSeriesStore: public virtual QwtAbstractSeriesStore { public: /*! \brief Constructor The store contains no series */ explicit QwtSeriesStore(); //! Destructor ~QwtSeriesStore(); /*! Assign a series of samples \param series Data \warning The item takes ownership of the data object, deleting it when its not used anymore. */ void setData( QwtSeriesData *series ); //! \return the the series data QwtSeriesData *data(); //! \return the the series data const QwtSeriesData *data() const; /*! \param index Index \return Sample at position index */ T sample( int index ) const; /*! \return Number of samples of the series \sa setData(), QwtSeriesData::size() */ virtual size_t dataSize() const; /*! \return Bounding rectangle of the series or an invalid rectangle, when no series is stored \sa QwtSeriesData::boundingRect() */ virtual QRectF dataRect() const; /*! Set a the "rect of interest" for the series \param rect Rectangle of interest \sa QwtSeriesData::setRectOfInterest() */ virtual void setRectOfInterest( const QRectF &rect ); /*! Replace a series without deleting the previous one \param series New series \return Previously assigned series */ QwtSeriesData *swapData( QwtSeriesData *series ); private: QwtSeriesData *d_series; }; template QwtSeriesStore::QwtSeriesStore(): d_series( NULL ) { } template QwtSeriesStore::~QwtSeriesStore() { delete d_series; } template inline QwtSeriesData *QwtSeriesStore::data() { return d_series; } template inline const QwtSeriesData *QwtSeriesStore::data() const { return d_series; } template inline T QwtSeriesStore::sample( int index ) const { return d_series ? d_series->sample( index ) : T(); } template void QwtSeriesStore::setData( QwtSeriesData *series ) { if ( d_series != series ) { delete d_series; d_series = series; dataChanged(); } } template size_t QwtSeriesStore::dataSize() const { if ( d_series == NULL ) return 0; return d_series->size(); } template QRectF QwtSeriesStore::dataRect() const { if ( d_series == NULL ) return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid return d_series->boundingRect(); } template void QwtSeriesStore::setRectOfInterest( const QRectF &rect ) { if ( d_series ) d_series->setRectOfInterest( rect ); } template QwtSeriesData* QwtSeriesStore::swapData( QwtSeriesData *series ) { QwtSeriesData * swappedSeries = d_series; d_series = series; return swappedSeries; } #endif