Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_series_data.h
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_series_data.h (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_series_data.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_SERIES_DATA_H 11 #define QWT_SERIES_DATA_H 111 #define QWT_SERIES_DATA_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_samples.h" 15 15 #include "qwt_point_3d.h" 16 #include "qwt_point_polar.h" 16 17 17 #include <qvector.h> 18 18 #include <qrect.h> 19 20 class QwtPointPolar; 19 21 20 22 /*! … … 41 43 but often it is possible to implement a more efficient algorithm 42 44 depending on the characteristics of the series. 43 The member d_boundingRect is intended for caching the calculated rectangle.44 45 */ 46 template <typename T>45 The member cachedBoundingRect is intended for caching the calculated rectangle. 46 47 */ 48 template< typename T > 47 49 class QwtSeriesData 48 50 { 49 public: 51 public: 50 52 //! Constructor 51 53 QwtSeriesData(); … … 60 62 61 63 /*! 62 Return a sample 63 \param i Index 64 \return Sample at position i 64 Return a sample 65 \param i Index 66 \return Sample at position i 65 67 */ 66 68 virtual T sample( size_t i ) const = 0; 67 68 /*!69 Calculate the bounding rect of all samples70 71 The bounding rect is necessary for autoscaling and can be used72 for a couple of painting optimizations.73 74 qwtBoundingRect(...) offers slow implementations iterating75 over the samples. For large sets it is recommended to implement76 something faster f.e. by caching the bounding rectangle.77 78 \return Bounding rectangle79 */80 virtual QRectF boundingRect() const = 0;81 69 82 70 #else … … 84 72 virtual size_t size() const { return 0; } 85 73 virtual T sample( size_t i ) const { return T(); } 86 virtual QRectF boundingRect() const { return d_boundingRect; }87 74 #endif 75 76 /*! 77 Returns the first sample in the list. 78 \warning This function assumes that the list isn't empty. 79 */ 80 inline T firstSample() const { return sample( 0 ); } 81 82 /*! 83 Returns the first sample in the list. 84 \warning This function assumes that the list isn't empty. 85 */ 86 inline T lastSample() const { return sample( size() - 1 ); } 87 88 /*! 89 Calculate the bounding rect of all samples 90 91 The bounding rect is necessary for autoscaling and can be used 92 for a couple of painting optimizations. 93 94 qwtBoundingRect(...) offers slow implementations iterating 95 over the samples. For large sets it is recommended to implement 96 something faster. 97 98 \return Bounding rectangle 99 */ 100 virtual QRectF boundingRect() const 101 { 102 if ( cachedBoundingRect.width() < 0.0 ) 103 cachedBoundingRect = qwtBoundingRect( *this ); 104 105 return cachedBoundingRect; 106 } 88 107 89 108 /*! … … 97 116 98 117 \param rect Rectangle of interest 99 */ 100 virtual void setRectOfInterest( const QRectF &rect );101 102 protected: 118 */ 119 virtual void setRectOfInterest( const QRectF& rect ); 120 121 protected: 103 122 //! Can be used to cache a calculated bounding rectangle 104 mutable QRectF d_boundingRect;105 106 private: 107 QwtSeriesData< T> &operator=( const QwtSeriesData<T>& );123 mutable QRectF cachedBoundingRect; 124 125 private: 126 QwtSeriesData< T >& operator=( const QwtSeriesData< T >& ); 108 127 }; 109 128 110 template <typename T>111 QwtSeriesData< T>::QwtSeriesData():112 d_boundingRect( 0.0, 0.0, -1.0, -1.0 )113 { 114 } 115 116 template <typename T>117 QwtSeriesData< T>::~QwtSeriesData()118 { 119 } 120 121 template <typename T>122 void QwtSeriesData< T>::setRectOfInterest( const QRectF& )129 template< typename T > 130 QwtSeriesData< T >::QwtSeriesData() 131 : cachedBoundingRect( 0.0, 0.0, -1.0, -1.0 ) 132 { 133 } 134 135 template< typename T > 136 QwtSeriesData< T >::~QwtSeriesData() 137 { 138 } 139 140 template< typename T > 141 void QwtSeriesData< T >::setRectOfInterest( const QRectF& ) 123 142 { 124 143 } 125 144 126 145 /*! 127 \brief Template class for data, that is organized as QVector 128 129 QVector uses implicit data sharing and can be 130 passed around as argument efficiently. 131 */ 132 template <typename T>133 class QwtArraySeriesData: public QwtSeriesData< T>134 { 135 public: 146 \brief Template class for data, that is organized as QVector 147 148 QVector uses implicit data sharing and can be 149 passed around as argument efficiently. 150 */ 151 template< typename T > 152 class QwtArraySeriesData : public QwtSeriesData< T > 153 { 154 public: 136 155 //! Constructor 137 156 QwtArraySeriesData(); … … 140 159 Constructor 141 160 \param samples Array of samples 142 */ 143 QwtArraySeriesData( const QVector< T> &samples );144 145 /*! 146 Assign an array of samples 147 \param samples Array of samples 148 */ 149 void setSamples( const QVector< T> &samples );161 */ 162 explicit QwtArraySeriesData( const QVector< T >& samples ); 163 164 /*! 165 Assign an array of samples 166 \param samples Array of samples 167 */ 168 void setSamples( const QVector< T >& samples ); 150 169 151 170 //! \return Array of samples 152 const QVector< T> samples() const;171 const QVector< T > samples() const; 153 172 154 173 //! \return Number of samples 155 virtual size_t size() const; 156 157 /*! 158 \return Sample at a specific position 159 160 \param index Index 161 \return Sample at position index 162 */ 163 virtual T sample( size_t index ) const; 164 165 protected: 174 virtual size_t size() const QWT_OVERRIDE; 175 176 /*! 177 \return Sample at a specific position 178 179 \param index Index 180 \return Sample at position index 181 */ 182 virtual T sample( size_t index ) const QWT_OVERRIDE; 183 184 protected: 166 185 //! Vector of samples 167 QVector< T> d_samples;186 QVector< T > m_samples; 168 187 }; 169 188 170 template <typename T>171 QwtArraySeriesData< T>::QwtArraySeriesData()172 { 173 } 174 175 template <typename T>176 QwtArraySeriesData< T>::QwtArraySeriesData( const QVector<T> &samples ):177 d_samples( samples )178 { 179 } 180 181 template <typename T>182 void QwtArraySeriesData< T>::setSamples( const QVector<T> &samples )183 { 184 QwtSeriesData< T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );185 d_samples = samples;186 } 187 188 template <typename T>189 const QVector< T> QwtArraySeriesData<T>::samples() const190 { 191 return d_samples;192 } 193 194 template <typename T>195 size_t QwtArraySeriesData< T>::size() const196 { 197 return d_samples.size();198 } 199 200 template <typename T>201 T QwtArraySeriesData< T>::sample( size_t i ) const202 { 203 return d_samples[ static_cast<int>( i ) ];189 template< typename T > 190 QwtArraySeriesData< T >::QwtArraySeriesData() 191 { 192 } 193 194 template< typename T > 195 QwtArraySeriesData< T >::QwtArraySeriesData( const QVector< T >& samples ) 196 : m_samples( samples ) 197 { 198 } 199 200 template< typename T > 201 void QwtArraySeriesData< T >::setSamples( const QVector< T >& samples ) 202 { 203 QwtSeriesData< T >::cachedBoundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 ); 204 m_samples = samples; 205 } 206 207 template< typename T > 208 const QVector< T > QwtArraySeriesData< T >::samples() const 209 { 210 return m_samples; 211 } 212 213 template< typename T > 214 size_t QwtArraySeriesData< T >::size() const 215 { 216 return m_samples.size(); 217 } 218 219 template< typename T > 220 T QwtArraySeriesData< T >::sample( size_t i ) const 221 { 222 return m_samples[ static_cast< int >( i ) ]; 204 223 } 205 224 206 225 //! Interface for iterating over an array of points 207 class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF> 208 { 209 public: 210 QwtPointSeriesData( 211 const QVector<QPointF> & = QVector<QPointF>() ); 212 213 virtual QRectF boundingRect() const; 214 }; 226 typedef QwtArraySeriesData< QPointF > QwtPointSeriesData; 215 227 216 228 //! Interface for iterating over an array of 3D points 217 class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D> 218 { 219 public: 220 QwtPoint3DSeriesData( 221 const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() ); 222 virtual QRectF boundingRect() const; 223 }; 229 typedef QwtArraySeriesData< QwtPoint3D > QwtPoint3DSeriesData; 224 230 225 231 //! Interface for iterating over an array of intervals 226 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample> 227 { 228 public: 229 QwtIntervalSeriesData( 230 const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() ); 231 232 virtual QRectF boundingRect() const; 233 }; 232 typedef QwtArraySeriesData< QwtIntervalSample > QwtIntervalSeriesData; 234 233 235 234 //! Interface for iterating over an array of samples 236 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample> 237 { 238 public: 239 QwtSetSeriesData( 240 const QVector<QwtSetSample> & = QVector<QwtSetSample>() ); 241 242 virtual QRectF boundingRect() const; 243 }; 244 245 /*! 246 Interface for iterating over an array of OHLC samples 247 */ 248 class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample> 249 { 250 public: 251 QwtTradingChartData( 252 const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() ); 253 254 virtual QRectF boundingRect() const; 255 }; 256 257 QWT_EXPORT QRectF qwtBoundingRect( 258 const QwtSeriesData<QPointF> &, int from = 0, int to = -1 ); 259 260 QWT_EXPORT QRectF qwtBoundingRect( 261 const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 ); 262 263 QWT_EXPORT QRectF qwtBoundingRect( 264 const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 ); 265 266 QWT_EXPORT QRectF qwtBoundingRect( 267 const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 ); 268 269 QWT_EXPORT QRectF qwtBoundingRect( 270 const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 ); 271 272 QWT_EXPORT QRectF qwtBoundingRect( 273 const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 ); 235 typedef QwtArraySeriesData< QwtSetSample > QwtSetSeriesData; 236 237 //! Interface for iterating over an array of vector field samples 238 typedef QwtArraySeriesData< QwtVectorFieldSample > QwtVectorFieldData; 239 240 //! Interface for iterating over an array of OHLC samples 241 typedef QwtArraySeriesData< QwtOHLCSample > QwtTradingChartData; 242 243 QWT_EXPORT QRectF qwtBoundingRect( 244 const QwtSeriesData< QPointF >&, int from = 0, int to = -1 ); 245 246 QWT_EXPORT QRectF qwtBoundingRect( 247 const QwtSeriesData< QwtPoint3D >&, int from = 0, int to = -1 ); 248 249 QWT_EXPORT QRectF qwtBoundingRect( 250 const QwtSeriesData< QwtPointPolar >&, int from = 0, int to = -1 ); 251 252 QWT_EXPORT QRectF qwtBoundingRect( 253 const QwtSeriesData< QwtIntervalSample >&, int from = 0, int to = -1 ); 254 255 QWT_EXPORT QRectF qwtBoundingRect( 256 const QwtSeriesData< QwtSetSample >&, int from = 0, int to = -1 ); 257 258 QWT_EXPORT QRectF qwtBoundingRect( 259 const QwtSeriesData< QwtOHLCSample >&, int from = 0, int to = -1 ); 260 261 QWT_EXPORT QRectF qwtBoundingRect( 262 const QwtSeriesData< QwtVectorFieldSample >&, int from = 0, int to = -1 ); 274 263 275 264 /*! … … 281 270 value the return value will be -1. 282 271 283 \par Example 272 \par Example 284 273 The following example shows finds a point of curve from an x 285 274 coordinate 286 275 \code 287 #include <qwt_series_data.h>288 #include <qwt_plot_curve.h>276 #include <qwt_series_data.h> 277 #include <qwt_plot_curve.h> 289 278 290 279 struct compareX … … 299 288 { 300 289 int index = qwtUpperSampleIndex<QPointF>( 301 *curve->data(), x, compareX() );290 * curve->data(), x, compareX() ); 302 291 303 292 if ( index == -1 && … … 319 308 320 309 \endcode 321 \endpar 322 323 \param series Series of samples 324 \param value Value 325 \param lessThan Compare operation 326 327 \note The samples must be sorted according to the order specified 310 \endpar 311 312 \param series Series of samples 313 \param value Value 314 \param lessThan Compare operation 315 316 \note The samples must be sorted according to the order specified 328 317 by the lessThan object 329 318 */ 330 template <typename T, typename LessThan>331 inline int qwtUpperSampleIndex( const QwtSeriesData< T> &series,319 template< typename T, typename LessThan > 320 inline int qwtUpperSampleIndex( const QwtSeriesData< T >& series, 332 321 double value, LessThan lessThan ) 333 322 { 334 323 const int indexMax = series.size() - 1; 335 324 336 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )325 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) ) 337 326 return -1; 338 327
Note:
See TracChangeset
for help on using the changeset viewer.
