qwt_point_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_point_data.h"
00011 #include "qwt_math.h"
00012 #include <string.h>
00013 
00022 QwtPointArrayData::QwtPointArrayData(
00023         const QVector<double> &x, const QVector<double> &y ):
00024     d_x( x ),
00025     d_y( y )
00026 {
00027 }
00028 
00037 QwtPointArrayData::QwtPointArrayData( const double *x,
00038         const double *y, size_t size )
00039 {
00040     d_x.resize( size );
00041     ::memcpy( d_x.data(), x, size * sizeof( double ) );
00042 
00043     d_y.resize( size );
00044     ::memcpy( d_y.data(), y, size * sizeof( double ) );
00045 }
00046 
00055 QRectF QwtPointArrayData::boundingRect() const
00056 {
00057     if ( d_boundingRect.width() < 0 )
00058         d_boundingRect = qwtBoundingRect( *this );
00059 
00060     return d_boundingRect;
00061 }
00062 
00064 size_t QwtPointArrayData::size() const
00065 {
00066     return qMin( d_x.size(), d_y.size() );
00067 }
00068 
00075 QPointF QwtPointArrayData::sample( size_t index ) const
00076 {
00077     return QPointF( d_x[int( index )], d_y[int( index )] );
00078 }
00079 
00081 const QVector<double> &QwtPointArrayData::xData() const
00082 {
00083     return d_x;
00084 }
00085 
00087 const QVector<double> &QwtPointArrayData::yData() const
00088 {
00089     return d_y;
00090 }
00091 
00105 QwtCPointerData::QwtCPointerData(
00106         const double *x, const double *y, size_t size ):
00107     d_x( x ),
00108     d_y( y ),
00109     d_size( size )
00110 {
00111 }
00112 
00121 QRectF QwtCPointerData::boundingRect() const
00122 {
00123     if ( d_boundingRect.width() < 0 )
00124         d_boundingRect = qwtBoundingRect( *this );
00125 
00126     return d_boundingRect;
00127 }
00128 
00130 size_t QwtCPointerData::size() const
00131 {
00132     return d_size;
00133 }
00134 
00141 QPointF QwtCPointerData::sample( size_t index ) const
00142 {
00143     return QPointF( d_x[int( index )], d_y[int( index )] );
00144 }
00145 
00147 const double *QwtCPointerData::xData() const
00148 {
00149     return d_x;
00150 }
00151 
00153 const double *QwtCPointerData::yData() const
00154 {
00155     return d_y;
00156 }
00157 
00166 QwtSyntheticPointData::QwtSyntheticPointData(
00167         size_t size, const QwtInterval &interval ):
00168     d_size( size ),
00169     d_interval( interval )
00170 {
00171 }
00172 
00179 void QwtSyntheticPointData::setSize( size_t size )
00180 {
00181     d_size = size;
00182 }
00183 
00188 size_t QwtSyntheticPointData::size() const
00189 {
00190     return d_size;
00191 }
00192 
00199 void QwtSyntheticPointData::setInterval( const QwtInterval &interval )
00200 {
00201     d_interval = interval.normalized();
00202 }
00203 
00208 QwtInterval QwtSyntheticPointData::interval() const
00209 {
00210     return d_interval;
00211 }
00212 
00224 void QwtSyntheticPointData::setRectOfInterest( const QRectF &rect )
00225 {
00226     d_rectOfInterest = rect;
00227     d_intervalOfInterest = QwtInterval(
00228         rect.left(), rect.right() ).normalized();
00229 }
00230 
00235 QRectF QwtSyntheticPointData::rectOfInterest() const
00236 {
00237     return d_rectOfInterest;
00238 }
00239 
00251 QRectF QwtSyntheticPointData::boundingRect() const
00252 {
00253     if ( d_size == 0 ||
00254         !( d_interval.isValid() || d_intervalOfInterest.isValid() ) )
00255     {
00256         return QRectF( 1.0, 1.0, -2.0, -2.0 ); // something invalid
00257     }
00258 
00259     return qwtBoundingRect( *this );
00260 }
00261 
00271 QPointF QwtSyntheticPointData::sample( size_t index ) const
00272 {
00273     if ( index >= d_size )
00274         return QPointF( 0, 0 );
00275 
00276     const double xValue = x( index );
00277     const double yValue = y( xValue );
00278 
00279     return QPointF( xValue, yValue );
00280 }
00281 
00294 double QwtSyntheticPointData::x( uint index ) const
00295 {
00296     const QwtInterval &interval = d_interval.isValid() ?
00297         d_interval : d_intervalOfInterest;
00298 
00299     if ( !interval.isValid() ) 
00300         return 0.0;
00301 
00302     if ( d_size <= 1 )
00303         return interval.minValue();
00304 
00305     const double dx = interval.width() / ( d_size - 1 );
00306     return interval.minValue() + index * dx;
00307 }


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