source: ntrip/trunk/BNC/qwt/qwt_series_store.h@ 8330

Last change on this file since 8330 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 4.7 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_SERIES_STORE_H
11#define QWT_SERIES_STORE_H
12
13#include "qwt_global.h"
14#include "qwt_series_data.h"
15
16/*!
17 \brief Bridge between QwtSeriesStore and QwtPlotSeriesItem
18
19 QwtAbstractSeriesStore is an abstract interface only
20 to make it possible to isolate the template based methods ( QwtSeriesStore )
21 from the regular methods ( QwtPlotSeriesItem ) to make it possible
22 to derive from QwtPlotSeriesItem without any hassle with templates.
23*/
24class QwtAbstractSeriesStore
25{
26protected:
27 //! Destructor
28 virtual ~QwtAbstractSeriesStore() {}
29
30 //! dataChanged() indicates, that the series has been changed.
31 virtual void dataChanged() = 0;
32
33 /*!
34 Set a the "rectangle of interest" for the stored series
35 \sa QwtSeriesData<T>::setRectOfInterest()
36 */
37 virtual void setRectOfInterest( const QRectF & ) = 0;
38
39 //! \return Bounding rectangle of the stored series
40 virtual QRectF dataRect() const = 0;
41
42 //! \return Number of samples
43 virtual size_t dataSize() const = 0;
44};
45
46/*!
47 \brief Class storing a QwtSeriesData object
48
49 QwtSeriesStore and QwtPlotSeriesItem are intended as base classes for all
50 plot items iterating over a series of samples. Both classes share
51 a virtual base class ( QwtAbstractSeriesStore ) to bridge between them.
52
53 QwtSeriesStore offers the template based part for the plot item API, so
54 that QwtPlotSeriesItem can be derived without any hassle with templates.
55 */
56template <typename T>
57class QwtSeriesStore: public virtual QwtAbstractSeriesStore
58{
59public:
60 /*!
61 \brief Constructor
62 The store contains no series
63 */
64 explicit QwtSeriesStore<T>();
65
66 //! Destructor
67 ~QwtSeriesStore<T>();
68
69 /*!
70 Assign a series of samples
71
72 \param series Data
73 \warning The item takes ownership of the data object, deleting
74 it when its not used anymore.
75 */
76 void setData( QwtSeriesData<T> *series );
77
78 //! \return the the series data
79 QwtSeriesData<T> *data();
80
81 //! \return the the series data
82 const QwtSeriesData<T> *data() const;
83
84 /*!
85 \param index Index
86 \return Sample at position index
87 */
88 T sample( int index ) const;
89
90 /*!
91 \return Number of samples of the series
92 \sa setData(), QwtSeriesData<T>::size()
93 */
94 virtual size_t dataSize() const;
95
96 /*!
97 \return Bounding rectangle of the series
98 or an invalid rectangle, when no series is stored
99
100 \sa QwtSeriesData<T>::boundingRect()
101 */
102 virtual QRectF dataRect() const;
103
104 /*!
105 Set a the "rect of interest" for the series
106
107 \param rect Rectangle of interest
108 \sa QwtSeriesData<T>::setRectOfInterest()
109 */
110 virtual void setRectOfInterest( const QRectF &rect );
111
112 /*!
113 Replace a series without deleting the previous one
114
115 \param series New series
116 \return Previously assigned series
117 */
118 QwtSeriesData<T> *swapData( QwtSeriesData<T> *series );
119
120private:
121 QwtSeriesData<T> *d_series;
122};
123
124template <typename T>
125QwtSeriesStore<T>::QwtSeriesStore():
126 d_series( NULL )
127{
128}
129
130template <typename T>
131QwtSeriesStore<T>::~QwtSeriesStore()
132{
133 delete d_series;
134}
135
136template <typename T>
137inline QwtSeriesData<T> *QwtSeriesStore<T>::data()
138{
139 return d_series;
140}
141
142template <typename T>
143inline const QwtSeriesData<T> *QwtSeriesStore<T>::data() const
144{
145 return d_series;
146}
147
148template <typename T>
149inline T QwtSeriesStore<T>::sample( int index ) const
150{
151 return d_series ? d_series->sample( index ) : T();
152}
153
154template <typename T>
155void QwtSeriesStore<T>::setData( QwtSeriesData<T> *series )
156{
157 if ( d_series != series )
158 {
159 delete d_series;
160 d_series = series;
161 dataChanged();
162 }
163}
164
165template <typename T>
166size_t QwtSeriesStore<T>::dataSize() const
167{
168 if ( d_series == NULL )
169 return 0;
170
171 return d_series->size();
172}
173
174template <typename T>
175QRectF QwtSeriesStore<T>::dataRect() const
176{
177 if ( d_series == NULL )
178 return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
179
180 return d_series->boundingRect();
181}
182
183template <typename T>
184void QwtSeriesStore<T>::setRectOfInterest( const QRectF &rect )
185{
186 if ( d_series )
187 d_series->setRectOfInterest( rect );
188}
189
190template <typename T>
191QwtSeriesData<T>* QwtSeriesStore<T>::swapData( QwtSeriesData<T> *series )
192{
193 QwtSeriesData<T> * swappedSeries = d_series;
194 d_series = series;
195
196 return swappedSeries;
197}
198
199#endif
Note: See TracBrowser for help on using the repository browser.