qwt_series_data.cpp
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 #include "qwt_series_data.h"
00011 #include "qwt_math.h"
00012 
00013 static inline QRectF qwtBoundingRect( const QPointF &sample )
00014 {
00015     return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
00016 }
00017 
00018 static inline QRectF qwtBoundingRect( const QwtPoint3D &sample )
00019 {
00020     return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
00021 }
00022 
00023 static inline QRectF qwtBoundingRect( const QwtPointPolar &sample )
00024 {
00025     return QRectF( sample.azimuth(), sample.radius(), 0.0, 0.0 );
00026 }
00027 
00028 static inline QRectF qwtBoundingRect( const QwtIntervalSample &sample )
00029 {
00030     return QRectF( sample.interval.minValue(), sample.value,
00031         sample.interval.maxValue() - sample.interval.minValue(), 0.0 );
00032 }
00033 
00034 static inline QRectF qwtBoundingRect( const QwtSetSample &sample )
00035 {
00036     double minY = sample.set[0];
00037     double maxY = sample.set[0];
00038 
00039     for ( int i = 1; i < sample.set.size(); i++ )
00040     {
00041         if ( sample.set[i] < minY )
00042             minY = sample.set[i];
00043         if ( sample.set[i] > maxY )
00044             maxY = sample.set[i];
00045     }
00046 
00047     double minX = sample.value;
00048     double maxX = sample.value;
00049 
00050     return QRectF( minX, minY, maxX - minX, maxY - minY );
00051 }
00052 
00053 static inline QRectF qwtBoundingRect( const QwtOHLCSample &sample )
00054 {
00055     const QwtInterval interval = sample.boundingInterval();
00056     return QRectF( interval.minValue(), sample.time, interval.width(), 0.0 );
00057 }
00058 
00071 template <class T>
00072 QRectF qwtBoundingRectT(
00073     const QwtSeriesData<T>& series, int from, int to )
00074 {
00075     QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
00076 
00077     if ( from < 0 )
00078         from = 0;
00079 
00080     if ( to < 0 )
00081         to = series.size() - 1;
00082 
00083     if ( to < from )
00084         return boundingRect;
00085 
00086     int i;
00087     for ( i = from; i <= to; i++ )
00088     {
00089         const QRectF rect = qwtBoundingRect( series.sample( i ) );
00090         if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
00091         {
00092             boundingRect = rect;
00093             i++;
00094             break;
00095         }
00096     }
00097 
00098     for ( ; i <= to; i++ )
00099     {
00100         const QRectF rect = qwtBoundingRect( series.sample( i ) );
00101         if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
00102         {
00103             boundingRect.setLeft( qMin( boundingRect.left(), rect.left() ) );
00104             boundingRect.setRight( qMax( boundingRect.right(), rect.right() ) );
00105             boundingRect.setTop( qMin( boundingRect.top(), rect.top() ) );
00106             boundingRect.setBottom( qMax( boundingRect.bottom(), rect.bottom() ) );
00107         }
00108     }
00109 
00110     return boundingRect;
00111 }
00112 
00124 QRectF qwtBoundingRect(
00125     const QwtSeriesData<QPointF> &series, int from, int to )
00126 {
00127     return qwtBoundingRectT<QPointF>( series, from, to );
00128 }
00129 
00141 QRectF qwtBoundingRect(
00142     const QwtSeriesData<QwtPoint3D> &series, int from, int to )
00143 {
00144     return qwtBoundingRectT<QwtPoint3D>( series, from, to );
00145 }
00146 
00161 QRectF qwtBoundingRect(
00162     const QwtSeriesData<QwtPointPolar> &series, int from, int to )
00163 {
00164     return qwtBoundingRectT<QwtPointPolar>( series, from, to );
00165 }
00166 
00178 QRectF qwtBoundingRect(
00179     const QwtSeriesData<QwtIntervalSample>& series, int from, int to )
00180 {
00181     return qwtBoundingRectT<QwtIntervalSample>( series, from, to );
00182 }
00183 
00195 QRectF qwtBoundingRect(
00196     const QwtSeriesData<QwtOHLCSample>& series, int from, int to )
00197 {
00198     return qwtBoundingRectT<QwtOHLCSample>( series, from, to );
00199 }
00200 
00212 QRectF qwtBoundingRect(
00213     const QwtSeriesData<QwtSetSample>& series, int from, int to )
00214 {
00215     return qwtBoundingRectT<QwtSetSample>( series, from, to );
00216 }
00217 
00222 QwtPointSeriesData::QwtPointSeriesData(
00223         const QVector<QPointF> &samples ):
00224     QwtArraySeriesData<QPointF>( samples )
00225 {
00226 }
00227 
00236 QRectF QwtPointSeriesData::boundingRect() const
00237 {
00238     if ( d_boundingRect.width() < 0.0 )
00239         d_boundingRect = qwtBoundingRect( *this );
00240 
00241     return d_boundingRect;
00242 }
00243 
00248 QwtPoint3DSeriesData::QwtPoint3DSeriesData(
00249         const QVector<QwtPoint3D> &samples ):
00250     QwtArraySeriesData<QwtPoint3D>( samples )
00251 {
00252 }
00253 
00262 QRectF QwtPoint3DSeriesData::boundingRect() const
00263 {
00264     if ( d_boundingRect.width() < 0.0 )
00265         d_boundingRect = qwtBoundingRect( *this );
00266 
00267     return d_boundingRect;
00268 }
00269 
00274 QwtIntervalSeriesData::QwtIntervalSeriesData(
00275         const QVector<QwtIntervalSample> &samples ):
00276     QwtArraySeriesData<QwtIntervalSample>( samples )
00277 {
00278 }
00279 
00288 QRectF QwtIntervalSeriesData::boundingRect() const
00289 {
00290     if ( d_boundingRect.width() < 0.0 )
00291         d_boundingRect = qwtBoundingRect( *this );
00292 
00293     return d_boundingRect;
00294 }
00295 
00300 QwtSetSeriesData::QwtSetSeriesData(
00301         const QVector<QwtSetSample> &samples ):
00302     QwtArraySeriesData<QwtSetSample>( samples )
00303 {
00304 }
00305 
00314 QRectF QwtSetSeriesData::boundingRect() const
00315 {
00316     if ( d_boundingRect.width() < 0.0 )
00317         d_boundingRect = qwtBoundingRect( *this );
00318 
00319     return d_boundingRect;
00320 }
00321 
00326 QwtTradingChartData::QwtTradingChartData(
00327         const QVector<QwtOHLCSample> &samples ):
00328     QwtArraySeriesData<QwtOHLCSample>( samples )
00329 {
00330 }
00331 
00340 QRectF QwtTradingChartData::boundingRect() const
00341 {
00342     if ( d_boundingRect.width() < 0.0 )
00343         d_boundingRect = qwtBoundingRect( *this );
00344 
00345     return d_boundingRect;
00346 }


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