qwt_series_data.h
Go to the documentation of this file.
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_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 
00057     virtual size_t size() const = 0;
00058 
00064     virtual T sample( size_t i ) const = 0;
00065 
00078     virtual QRectF boundingRect() const = 0;
00079 
00091     virtual void setRectOfInterest( const QRectF &rect );
00092 
00093 protected:
00095     mutable QRectF d_boundingRect;
00096 
00097 private:
00098     QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
00099 };
00100 
00101 template <typename T>
00102 QwtSeriesData<T>::QwtSeriesData():
00103     d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
00104 {
00105 }
00106 
00107 template <typename T>
00108 QwtSeriesData<T>::~QwtSeriesData()
00109 {
00110 }
00111 
00112 template <typename T>
00113 void QwtSeriesData<T>::setRectOfInterest( const QRectF & )
00114 {
00115 }
00116 
00123 template <typename T>
00124 class QwtArraySeriesData: public QwtSeriesData<T>
00125 {
00126 public:
00128     QwtArraySeriesData();
00129 
00134     explicit QwtArraySeriesData( const QVector<T> &samples );
00135 
00140     void setSamples( const QVector<T> &samples );
00141 
00143     const QVector<T> samples() const;
00144 
00146     virtual size_t size() const;
00147 
00154     virtual T sample( size_t index ) const;
00155 
00156 protected:
00158     QVector<T> d_samples;
00159 };
00160 
00161 template <typename T>
00162 QwtArraySeriesData<T>::QwtArraySeriesData()
00163 {
00164 }
00165 
00166 template <typename T>
00167 QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
00168     d_samples( samples )
00169 {
00170 }
00171 
00172 template <typename T>
00173 void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
00174 {
00175     QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
00176     d_samples = samples;
00177 }
00178 
00179 template <typename T>
00180 const QVector<T> QwtArraySeriesData<T>::samples() const
00181 {
00182     return d_samples;
00183 }
00184 
00185 template <typename T>
00186 size_t QwtArraySeriesData<T>::size() const
00187 {
00188     return d_samples.size();
00189 }
00190 
00191 template <typename T>
00192 T QwtArraySeriesData<T>::sample( size_t i ) const
00193 {
00194     return d_samples[ static_cast<int>( i ) ];
00195 }
00196 
00198 class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF>
00199 {
00200 public:
00201     QwtPointSeriesData(
00202         const QVector<QPointF> & = QVector<QPointF>() );
00203 
00204     virtual QRectF boundingRect() const;
00205 };
00206 
00208 class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D>
00209 {
00210 public:
00211     QwtPoint3DSeriesData(
00212         const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
00213     virtual QRectF boundingRect() const;
00214 };
00215 
00217 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
00218 {
00219 public:
00220     QwtIntervalSeriesData(
00221         const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
00222 
00223     virtual QRectF boundingRect() const;
00224 };
00225 
00227 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
00228 {
00229 public:
00230     QwtSetSeriesData(
00231         const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
00232 
00233     virtual QRectF boundingRect() const;
00234 };
00235 
00239 class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample>
00240 {
00241 public:
00242     QwtTradingChartData(
00243         const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() );
00244 
00245     virtual QRectF boundingRect() const;
00246 };
00247 
00248 QWT_EXPORT QRectF qwtBoundingRect(
00249     const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
00250 
00251 QWT_EXPORT QRectF qwtBoundingRect(
00252     const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
00253 
00254 QWT_EXPORT QRectF qwtBoundingRect(
00255     const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
00256 
00257 QWT_EXPORT QRectF qwtBoundingRect(
00258     const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
00259 
00260 QWT_EXPORT QRectF qwtBoundingRect(
00261     const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
00262 
00263 QWT_EXPORT QRectF qwtBoundingRect(
00264     const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 );
00265 
00324 template <typename T, typename LessThan>
00325 inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series,
00326     double value, LessThan lessThan  ) 
00327 {
00328     const int indexMax = series.size() - 1;
00329 
00330     if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) )  )
00331         return -1;
00332 
00333     int indexMin = 0;
00334     int n = indexMax;
00335 
00336     while ( n > 0 )
00337     {
00338         const int half = n >> 1;
00339         const int indexMid = indexMin + half;
00340 
00341         if ( lessThan( value, series.sample( indexMid ) ) )
00342         {
00343             n = half;
00344         }
00345         else
00346         {
00347             indexMin = indexMid + 1;
00348             n -= half + 1;
00349         }
00350     }
00351 
00352     return indexMin;
00353 }
00354 
00355 #endif


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:56