source: ntrip/branches/BNC_2.12/qwt/qwt_plot_seriesitem.h@ 9249

Last change on this file since 9249 was 4271, checked in by mervart, 13 years ago
File size: 4.9 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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#ifndef QWT_PLOT_SERIES_ITEM_H
11#define QWT_PLOT_SERIES_ITEM_H
12
13#include "qwt_global.h"
14#include "qwt_plot_item.h"
15#include "qwt_scale_div.h"
16#include "qwt_series_data.h"
17
18/*!
19 \brief Base class for plot items representing a series of samples
20*/
21class QWT_EXPORT QwtPlotAbstractSeriesItem: public QwtPlotItem
22{
23public:
24 explicit QwtPlotAbstractSeriesItem( const QString &title = QString::null );
25 explicit QwtPlotAbstractSeriesItem( const QwtText &title );
26
27 virtual ~QwtPlotAbstractSeriesItem();
28
29 void setOrientation( Qt::Orientation );
30 Qt::Orientation orientation() const;
31
32 virtual void draw( QPainter *p,
33 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
34 const QRectF & ) const;
35
36 /*!
37 Draw a subset of the samples
38
39 \param painter Painter
40 \param xMap Maps x-values into pixel coordinates.
41 \param yMap Maps y-values into pixel coordinates.
42 \param canvasRect Contents rect of the canvas
43 \param from Index of the first point to be painted
44 \param to Index of the last point to be painted. If to < 0 the
45 curve will be painted to its last point.
46 */
47 virtual void drawSeries( QPainter *painter,
48 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
49 const QRectF &canvasRect, int from, int to ) const = 0;
50
51private:
52 class PrivateData;
53 PrivateData *d_data;
54};
55
56/*!
57 \brief Class template for plot items representing a series of samples
58*/
59template <typename T>
60class QwtPlotSeriesItem: public QwtPlotAbstractSeriesItem
61{
62public:
63 explicit QwtPlotSeriesItem<T>( const QString &title = QString::null );
64 explicit QwtPlotSeriesItem<T>( const QwtText &title );
65
66 virtual ~QwtPlotSeriesItem<T>();
67
68 void setData( QwtSeriesData<T> * );
69
70 QwtSeriesData<T> *data();
71 const QwtSeriesData<T> *data() const;
72
73 size_t dataSize() const;
74 T sample( int index ) const;
75
76 virtual QRectF boundingRect() const;
77 virtual void updateScaleDiv( const QwtScaleDiv &,
78 const QwtScaleDiv & );
79
80protected:
81 //! Series
82 QwtSeriesData<T> *d_series;
83};
84
85/*!
86 Constructor
87 \param title Title of the series item
88*/
89template <typename T>
90QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QString &title ):
91 QwtPlotAbstractSeriesItem( QwtText( title ) ),
92 d_series( NULL )
93{
94}
95
96/*!
97 Constructor
98 \param title Title of the series item
99*/
100template <typename T>
101QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QwtText &title ):
102 QwtPlotAbstractSeriesItem( title ),
103 d_series( NULL )
104{
105}
106
107//! Destructor
108template <typename T>
109QwtPlotSeriesItem<T>::~QwtPlotSeriesItem()
110{
111 delete d_series;
112}
113
114//! \return the the curve data
115template <typename T>
116inline QwtSeriesData<T> *QwtPlotSeriesItem<T>::data()
117{
118 return d_series;
119}
120
121//! \return the the curve data
122template <typename T>
123inline const QwtSeriesData<T> *QwtPlotSeriesItem<T>::data() const
124{
125 return d_series;
126}
127
128/*!
129 \param index Index
130 \return Sample at position index
131*/
132template <typename T>
133inline T QwtPlotSeriesItem<T>::sample( int index ) const
134{
135 return d_series ? d_series->sample( index ) : T();
136}
137
138/*!
139 Assign a series of samples
140
141 \param data Data
142 \warning The item takes ownership of the data object, deleting
143 it when its not used anymore.
144*/
145template <typename T>
146void QwtPlotSeriesItem<T>::setData( QwtSeriesData<T> *data )
147{
148 if ( d_series != data )
149 {
150 delete d_series;
151 d_series = data;
152 itemChanged();
153 }
154}
155
156/*!
157 Return the size of the data arrays
158 \sa setData()
159*/
160template <typename T>
161size_t QwtPlotSeriesItem<T>::dataSize() const
162{
163 if ( d_series == NULL )
164 return 0;
165
166 return d_series->size();
167}
168
169/*!
170 \return Bounding rectangle of the data.
171 If there is no bounding rect, like for empty data the rectangle is invalid.
172
173 \sa QwtSeriesData<T>::boundingRect(), QRectF::isValid()
174*/
175template <typename T>
176QRectF QwtPlotSeriesItem<T>::boundingRect() const
177{
178 if ( d_series == NULL )
179 return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
180
181 return d_series->boundingRect();
182}
183
184/*!
185 Update the rect of interest according to the current scale ranges
186
187 \param xScaleDiv Scale division of the x-axis
188 \param yScaleDiv Scale division of the y-axis
189
190 \sa QwtSeriesData<T>::setRectOfInterest()
191*/
192template <typename T>
193void QwtPlotSeriesItem<T>::updateScaleDiv(
194 const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv )
195{
196 const QRectF rect = QRectF(
197 xScaleDiv.lowerBound(), yScaleDiv.lowerBound(),
198 xScaleDiv.range(), yScaleDiv.range() );
199
200 d_series->setRectOfInterest( rect );
201}
202
203#endif
Note: See TracBrowser for help on using the repository browser.