00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** 00002 * Qwt Widget Library 00003 * Copyright (C) 1997 Josef Wilgen 00004 * Copyright (C) 2002 Uwe Rathmann 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the Qwt License, Version 1.0 00008 *****************************************************************************/ 00009 00010 #ifndef QWT_SERIES_STORE_H 00011 #define QWT_SERIES_STORE_H 00012 00013 #include "qwt_global.h" 00014 #include "qwt_series_data.h" 00015 00024 class QwtAbstractSeriesStore 00025 { 00026 protected: 00028 virtual ~QwtAbstractSeriesStore() {} 00029 00030 #ifndef QWT_PYTHON_WRAPPER 00031 00032 virtual void dataChanged() = 0; 00033 00038 virtual void setRectOfInterest( const QRectF & ) = 0; 00039 00041 virtual QRectF dataRect() const = 0; 00042 00044 virtual size_t dataSize() const = 0; 00045 #else 00046 // Needed for generating the python bindings, but not for using them ! 00047 virtual void dataChanged() {} 00048 virtual void setRectOfInterest( const QRectF & ) {} 00049 virtual QRectF dataRect() const { return QRectF( 0.0, 0.0, -1.0, -1.0 ); } 00050 virtual size_t dataSize() const { return 0; } 00051 #endif 00052 }; 00053 00064 template <typename T> 00065 class QwtSeriesStore: public virtual QwtAbstractSeriesStore 00066 { 00067 public: 00072 explicit QwtSeriesStore<T>(); 00073 00075 ~QwtSeriesStore<T>(); 00076 00084 void setData( QwtSeriesData<T> *series ); 00085 00087 QwtSeriesData<T> *data(); 00088 00090 const QwtSeriesData<T> *data() const; 00091 00096 T sample( int index ) const; 00097 00102 virtual size_t dataSize() const; 00103 00110 virtual QRectF dataRect() const; 00111 00118 virtual void setRectOfInterest( const QRectF &rect ); 00119 00126 QwtSeriesData<T> *swapData( QwtSeriesData<T> *series ); 00127 00128 private: 00129 QwtSeriesData<T> *d_series; 00130 }; 00131 00132 template <typename T> 00133 QwtSeriesStore<T>::QwtSeriesStore(): 00134 d_series( NULL ) 00135 { 00136 } 00137 00138 template <typename T> 00139 QwtSeriesStore<T>::~QwtSeriesStore() 00140 { 00141 delete d_series; 00142 } 00143 00144 template <typename T> 00145 inline QwtSeriesData<T> *QwtSeriesStore<T>::data() 00146 { 00147 return d_series; 00148 } 00149 00150 template <typename T> 00151 inline const QwtSeriesData<T> *QwtSeriesStore<T>::data() const 00152 { 00153 return d_series; 00154 } 00155 00156 template <typename T> 00157 inline T QwtSeriesStore<T>::sample( int index ) const 00158 { 00159 return d_series ? d_series->sample( index ) : T(); 00160 } 00161 00162 template <typename T> 00163 void QwtSeriesStore<T>::setData( QwtSeriesData<T> *series ) 00164 { 00165 if ( d_series != series ) 00166 { 00167 delete d_series; 00168 d_series = series; 00169 dataChanged(); 00170 } 00171 } 00172 00173 template <typename T> 00174 size_t QwtSeriesStore<T>::dataSize() const 00175 { 00176 if ( d_series == NULL ) 00177 return 0; 00178 00179 return d_series->size(); 00180 } 00181 00182 template <typename T> 00183 QRectF QwtSeriesStore<T>::dataRect() const 00184 { 00185 if ( d_series == NULL ) 00186 return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid 00187 00188 return d_series->boundingRect(); 00189 } 00190 00191 template <typename T> 00192 void QwtSeriesStore<T>::setRectOfInterest( const QRectF &rect ) 00193 { 00194 if ( d_series ) 00195 d_series->setRectOfInterest( rect ); 00196 } 00197 00198 template <typename T> 00199 QwtSeriesData<T>* QwtSeriesStore<T>::swapData( QwtSeriesData<T> *series ) 00200 { 00201 QwtSeriesData<T> * swappedSeries = d_series; 00202 d_series = series; 00203 00204 return swappedSeries; 00205 } 00206 00207 #endif