Qwt User's Guide: qwt_point_data.cpp Source File

Qwt User's Guide 6.2.0

qwt_point_data.cpp
1 /******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10 #include "qwt_point_data.h"
11
20 QwtSyntheticPointData::QwtSyntheticPointData(
21 size_t size, const QwtInterval& interval )
22 : m_size( size )
23 , m_interval( interval )
24 {
25 }
26
33 void QwtSyntheticPointData::setSize( size_t size )
34 {
35 m_size = size;
36 }
37
42 size_t QwtSyntheticPointData::size() const
43 {
44 return m_size;
45 }
46
53 void QwtSyntheticPointData::setInterval( const QwtInterval& interval )
54 {
55 m_interval = interval.normalized();
56 }
57
62 QwtInterval QwtSyntheticPointData::interval() const
63 {
64 return m_interval;
65 }
66
78 void QwtSyntheticPointData::setRectOfInterest( const QRectF& rect )
79 {
80 m_rectOfInterest = rect;
81 m_intervalOfInterest = QwtInterval(
82 rect.left(), rect.right() ).normalized();
83 }
84
89 QRectF QwtSyntheticPointData::rectOfInterest() const
90 {
91 return m_rectOfInterest;
92 }
93
105 QRectF QwtSyntheticPointData::boundingRect() const
106 {
107 if ( m_size == 0 ||
108 !( m_interval.isValid() || m_intervalOfInterest.isValid() ) )
109 {
110 return QRectF( 1.0, 1.0, -2.0, -2.0 ); // something invalid
111 }
112
113 return qwtBoundingRect( *this );
114 }
115
125 QPointF QwtSyntheticPointData::sample( size_t index ) const
126 {
127 if ( index >= m_size )
128 return QPointF( 0, 0 );
129
130 const double xValue = x( index );
131 const double yValue = y( xValue );
132
133 return QPointF( xValue, yValue );
134 }
135
148 double QwtSyntheticPointData::x( uint index ) const
149 {
150 const QwtInterval& interval = m_interval.isValid() ?
151 m_interval : m_intervalOfInterest;
152
153 if ( !interval.isValid() )
154 return 0.0;
155
156 if ( m_size <= 1 )
157 return interval.minValue();
158
159 const double dx = interval.width() / ( m_size - 1 );
160 return interval.minValue() + index * dx;
161 }
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:23
QwtInterval::minValue
double minValue() const
Definition: qwt_interval.h:192
QwtInterval::normalized
QwtInterval normalized() const
Normalize the limits of the interval.
Definition: qwt_interval.cpp:29
QwtInterval::width
double width() const
Return the width of an interval.
Definition: qwt_interval.h:227
QwtInterval::isValid
bool isValid() const
Definition: qwt_interval.h:210
QwtSyntheticPointData::setInterval
void setInterval(const QwtInterval &)
Definition: qwt_point_data.cpp:53
QwtSyntheticPointData::sample
virtual QPointF sample(size_t index) const override
Definition: qwt_point_data.cpp:125
QwtSyntheticPointData::interval
QwtInterval interval() const
Definition: qwt_point_data.cpp:62
QwtSyntheticPointData::setSize
void setSize(size_t size)
Definition: qwt_point_data.cpp:33
QwtSyntheticPointData::rectOfInterest
QRectF rectOfInterest() const
Definition: qwt_point_data.cpp:89
QwtSyntheticPointData::x
virtual double x(uint index) const
Definition: qwt_point_data.cpp:148
QwtSyntheticPointData::size
virtual size_t size() const override
Definition: qwt_point_data.cpp:42
QwtSyntheticPointData::QwtSyntheticPointData
QwtSyntheticPointData(size_t size, const QwtInterval &=QwtInterval())
Definition: qwt_point_data.cpp:20
QwtSyntheticPointData::boundingRect
virtual QRectF boundingRect() const override
Calculate the bounding rectangle.
Definition: qwt_point_data.cpp:105
QwtSyntheticPointData::y
virtual double y(double x) const =0
QwtSyntheticPointData::setRectOfInterest
virtual void setRectOfInterest(const QRectF &) override
Definition: qwt_point_data.cpp:78