Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QWT_SERIES_DATA_H
00011 #define QWT_SERIES_DATA_H 1
00012
00013 #include "qwt_global.h"
00014 #include "qwt_samples.h"
00015 #include "qwt_point_3d.h"
00016 #include "qwt_point_polar.h"
00017 #include <qvector.h>
00018 #include <qrect.h>
00019
00046 template <typename T>
00047 class QwtSeriesData
00048 {
00049 public:
00051 QwtSeriesData();
00052
00054 virtual ~QwtSeriesData();
00055
00056 #ifndef QWT_PYTHON_WRAPPER
00057
00059 virtual size_t size() const = 0;
00060
00066 virtual T sample( size_t i ) const = 0;
00067
00080 virtual QRectF boundingRect() const = 0;
00081
00082 #else
00083
00084 virtual size_t size() const { return 0; }
00085 virtual T sample( size_t i ) const { return T(); }
00086 virtual QRectF boundingRect() const { return d_boundingRect; }
00087 #endif
00088
00100 virtual void setRectOfInterest( const QRectF &rect );
00101
00102 protected:
00104 mutable QRectF d_boundingRect;
00105
00106 private:
00107 QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
00108 };
00109
00110 template <typename T>
00111 QwtSeriesData<T>::QwtSeriesData():
00112 d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
00113 {
00114 }
00115
00116 template <typename T>
00117 QwtSeriesData<T>::~QwtSeriesData()
00118 {
00119 }
00120
00121 template <typename T>
00122 void QwtSeriesData<T>::setRectOfInterest( const QRectF & )
00123 {
00124 }
00125
00132 template <typename T>
00133 class QwtArraySeriesData: public QwtSeriesData<T>
00134 {
00135 public:
00137 QwtArraySeriesData();
00138
00143 explicit QwtArraySeriesData( const QVector<T> &samples );
00144
00149 void setSamples( const QVector<T> &samples );
00150
00152 const QVector<T> samples() const;
00153
00155 virtual size_t size() const;
00156
00163 virtual T sample( size_t index ) const;
00164
00165 protected:
00167 QVector<T> d_samples;
00168 };
00169
00170 template <typename T>
00171 QwtArraySeriesData<T>::QwtArraySeriesData()
00172 {
00173 }
00174
00175 template <typename T>
00176 QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
00177 d_samples( samples )
00178 {
00179 }
00180
00181 template <typename T>
00182 void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
00183 {
00184 QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
00185 d_samples = samples;
00186 }
00187
00188 template <typename T>
00189 const QVector<T> QwtArraySeriesData<T>::samples() const
00190 {
00191 return d_samples;
00192 }
00193
00194 template <typename T>
00195 size_t QwtArraySeriesData<T>::size() const
00196 {
00197 return d_samples.size();
00198 }
00199
00200 template <typename T>
00201 T QwtArraySeriesData<T>::sample( size_t i ) const
00202 {
00203 return d_samples[ static_cast<int>( i ) ];
00204 }
00205
00207 class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF>
00208 {
00209 public:
00210 QwtPointSeriesData(
00211 const QVector<QPointF> & = QVector<QPointF>() );
00212
00213 virtual QRectF boundingRect() const;
00214 };
00215
00217 class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D>
00218 {
00219 public:
00220 QwtPoint3DSeriesData(
00221 const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
00222 virtual QRectF boundingRect() const;
00223 };
00224
00226 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
00227 {
00228 public:
00229 QwtIntervalSeriesData(
00230 const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
00231
00232 virtual QRectF boundingRect() const;
00233 };
00234
00236 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
00237 {
00238 public:
00239 QwtSetSeriesData(
00240 const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
00241
00242 virtual QRectF boundingRect() const;
00243 };
00244
00248 class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample>
00249 {
00250 public:
00251 QwtTradingChartData(
00252 const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() );
00253
00254 virtual QRectF boundingRect() const;
00255 };
00256
00257 QWT_EXPORT QRectF qwtBoundingRect(
00258 const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
00259
00260 QWT_EXPORT QRectF qwtBoundingRect(
00261 const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
00262
00263 QWT_EXPORT QRectF qwtBoundingRect(
00264 const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
00265
00266 QWT_EXPORT QRectF qwtBoundingRect(
00267 const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
00268
00269 QWT_EXPORT QRectF qwtBoundingRect(
00270 const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
00271
00272 QWT_EXPORT QRectF qwtBoundingRect(
00273 const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 );
00274
00333 template <typename T, typename LessThan>
00334 inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series,
00335 double value, LessThan lessThan )
00336 {
00337 const int indexMax = series.size() - 1;
00338
00339 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
00340 return -1;
00341
00342 int indexMin = 0;
00343 int n = indexMax;
00344
00345 while ( n > 0 )
00346 {
00347 const int half = n >> 1;
00348 const int indexMid = indexMin + half;
00349
00350 if ( lessThan( value, series.sample( indexMid ) ) )
00351 {
00352 n = half;
00353 }
00354 else
00355 {
00356 indexMin = indexMid + 1;
00357 n -= half + 1;
00358 }
00359 }
00360
00361 return indexMin;
00362 }
00363
00364 #endif