Qwt User's Guide 6.0.2

- Main Page
- Related Pages
- Classes

qwt_plot_seriesitem.h
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
21 class QWT_EXPORT QwtPlotAbstractSeriesItem: public QwtPlotItem
22 {
23 public:
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
47 virtual void drawSeries( QPainter *painter,
48 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
49 const QRectF &canvasRect, int from, int to ) const = 0;
50
51 private:
52 class PrivateData;
53 PrivateData *d_data;
54 };
55
59 template <typename T>
60 class QwtPlotSeriesItem: public QwtPlotAbstractSeriesItem
61 {
62 public:
67 explicit QwtPlotSeriesItem<T>( const QString &title = QString::null );
68
73 explicit QwtPlotSeriesItem<T>( const QwtText &title );
74
76 virtual ~QwtPlotSeriesItem<T>();
77
85 void setData( QwtSeriesData<T> * );
86
88 QwtSeriesData<T> *data();
89
91 const QwtSeriesData<T> *data() const;
92
97 size_t dataSize() const;
98
103 T sample( int index ) const;
104
111 virtual QRectF boundingRect() const;
112
121 virtual void updateScaleDiv( const QwtScaleDiv &,
122 const QwtScaleDiv & );
123
124 protected:
126 QwtSeriesData<T> *d_series;
127 };
128
129 template <typename T>
130 QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QString &title ):
131 QwtPlotAbstractSeriesItem( QwtText( title ) ),
132 d_series( NULL )
133 {
134 }
135
136 template <typename T>
137 QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QwtText &title ):
138 QwtPlotAbstractSeriesItem( title ),
139 d_series( NULL )
140 {
141 }
142
143 template <typename T>
144 QwtPlotSeriesItem<T>::~QwtPlotSeriesItem()
145 {
146 delete d_series;
147 }
148
149 template <typename T>
150 inline QwtSeriesData<T> *QwtPlotSeriesItem<T>::data()
151 {
152 return d_series;
153 }
154
155 template <typename T>
156 inline const QwtSeriesData<T> *QwtPlotSeriesItem<T>::data() const
157 {
158 return d_series;
159 }
160
161 template <typename T>
162 inline T QwtPlotSeriesItem<T>::sample( int index ) const
163 {
164 return d_series ? d_series->sample( index ) : T();
165 }
166
167 template <typename T>
168 void QwtPlotSeriesItem<T>::setData( QwtSeriesData<T> *data )
169 {
170 if ( d_series != data )
171 {
172 delete d_series;
173 d_series = data;
174 itemChanged();
175 }
176 }
177
178 template <typename T>
179 size_t QwtPlotSeriesItem<T>::dataSize() const
180 {
181 if ( d_series == NULL )
182 return 0;
183
184 return d_series->size();
185 }
186
187 template <typename T>
188 QRectF QwtPlotSeriesItem<T>::boundingRect() const
189 {
190 if ( d_series == NULL )
191 return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
192
193 return d_series->boundingRect();
194 }
195
196 template <typename T>
197 void QwtPlotSeriesItem<T>::updateScaleDiv(
198 const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv )
199 {
200 if ( d_series )
201 {
202 const QRectF rect = QRectF(
203 xScaleDiv.lowerBound(), yScaleDiv.lowerBound(),
204 xScaleDiv.range(), yScaleDiv.range() );
205
206 d_series->setRectOfInterest( rect );
207 }
208 }
209
210 #endif