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

Last change on this file since 10386 was 9383, checked in by stoecker, 4 years ago

update to qwt verion 6.1.1 to fix build with newer Qt5

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