Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_series_data.h


Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (3 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_series_data.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_SERIES_DATA_H
    11 #define QWT_SERIES_DATA_H 1
     11#define QWT_SERIES_DATA_H
    1212
    1313#include "qwt_global.h"
    1414#include "qwt_samples.h"
    1515#include "qwt_point_3d.h"
    16 #include "qwt_point_polar.h"
     16
    1717#include <qvector.h>
    1818#include <qrect.h>
     19
     20class QwtPointPolar;
    1921
    2022/*!
    … …  
    4143     but often it is possible to implement a more efficient algorithm
    4244     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 */
     48template< typename T >
    4749class QwtSeriesData
    4850{
    49 public:
     51  public:
    5052    //! Constructor
    5153    QwtSeriesData();
    … …  
    6062
    6163    /*!
    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
    6567     */
    6668    virtual T sample( size_t i ) const = 0;
    67 
    68     /*!
    69        Calculate the bounding rect of all samples
    70 
    71        The bounding rect is necessary for autoscaling and can be used
    72        for a couple of painting optimizations.
    73 
    74        qwtBoundingRect(...) offers slow implementations iterating
    75        over the samples. For large sets it is recommended to implement
    76        something faster f.e. by caching the bounding rectangle.
    77 
    78        \return Bounding rectangle
    79      */
    80     virtual QRectF boundingRect() const = 0;
    8169
    8270#else
    … …  
    8472    virtual size_t size() const { return 0; }
    8573    virtual T sample( size_t i ) const { return T(); }
    86     virtual QRectF boundingRect() const { return d_boundingRect; }
    8774#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     }
    88107
    89108    /*!
    … …  
    97116
    98117       \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:
    103122    //! 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 >& );
    108127};
    109128
    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 & )
     129template< typename T >
     130QwtSeriesData< T >::QwtSeriesData()
     131    : cachedBoundingRect( 0.0, 0.0, -1.0, -1.0 )
     132{
     133}
     134
     135template< typename T >
     136QwtSeriesData< T >::~QwtSeriesData()
     137{
     138}
     139
     140template< typename T >
     141void QwtSeriesData< T >::setRectOfInterest( const QRectF& )
    123142{
    124143}
    125144
    126145/*!
    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 */
     151template< typename T >
     152class QwtArraySeriesData : public QwtSeriesData< T >
     153{
     154  public:
    136155    //! Constructor
    137156    QwtArraySeriesData();
    … …  
    140159       Constructor
    141160       \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 );
    150169
    151170    //! \return Array of samples
    152     const QVector<T> samples() const;
     171    const QVector< T > samples() const;
    153172
    154173    //! \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:
    166185    //! Vector of samples
    167     QVector<T> d_samples;
     186    QVector< T > m_samples;
    168187};
    169188
    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() const
    190 {
    191     return d_samples;
    192 }
    193 
    194 template <typename T>
    195 size_t QwtArraySeriesData<T>::size() const
    196 {
    197     return d_samples.size();
    198 }
    199 
    200 template <typename T>
    201 T QwtArraySeriesData<T>::sample( size_t i ) const
    202 {
    203     return d_samples[ static_cast<int>( i ) ];
     189template< typename T >
     190QwtArraySeriesData< T >::QwtArraySeriesData()
     191{
     192}
     193
     194template< typename T >
     195QwtArraySeriesData< T >::QwtArraySeriesData( const QVector< T >& samples )
     196    : m_samples( samples )
     197{
     198}
     199
     200template< typename T >
     201void 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
     207template< typename T >
     208const QVector< T > QwtArraySeriesData< T >::samples() const
     209{
     210    return m_samples;
     211}
     212
     213template< typename T >
     214size_t QwtArraySeriesData< T >::size() const
     215{
     216    return m_samples.size();
     217}
     218
     219template< typename T >
     220T QwtArraySeriesData< T >::sample( size_t i ) const
     221{
     222    return m_samples[ static_cast< int >( i ) ];
    204223}
    205224
    206225//! 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 };
     226typedef QwtArraySeriesData< QPointF > QwtPointSeriesData;
    215227
    216228//! 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 };
     229typedef QwtArraySeriesData< QwtPoint3D > QwtPoint3DSeriesData;
    224230
    225231//! 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 };
     232typedef QwtArraySeriesData< QwtIntervalSample > QwtIntervalSeriesData;
    234233
    235234//! 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 );
     235typedef QwtArraySeriesData< QwtSetSample > QwtSetSeriesData;
     236
     237//! Interface for iterating over an array of vector field samples
     238typedef QwtArraySeriesData< QwtVectorFieldSample > QwtVectorFieldData;
     239
     240//!  Interface for iterating over an array of OHLC samples
     241typedef QwtArraySeriesData< QwtOHLCSample > QwtTradingChartData;
     242
     243QWT_EXPORT QRectF qwtBoundingRect(
     244    const QwtSeriesData< QPointF >&, int from = 0, int to = -1 );
     245
     246QWT_EXPORT QRectF qwtBoundingRect(
     247    const QwtSeriesData< QwtPoint3D >&, int from = 0, int to = -1 );
     248
     249QWT_EXPORT QRectF qwtBoundingRect(
     250    const QwtSeriesData< QwtPointPolar >&, int from = 0, int to = -1 );
     251
     252QWT_EXPORT QRectF qwtBoundingRect(
     253    const QwtSeriesData< QwtIntervalSample >&, int from = 0, int to = -1 );
     254
     255QWT_EXPORT QRectF qwtBoundingRect(
     256    const QwtSeriesData< QwtSetSample >&, int from = 0, int to = -1 );
     257
     258QWT_EXPORT QRectF qwtBoundingRect(
     259    const QwtSeriesData< QwtOHLCSample >&, int from = 0, int to = -1 );
     260
     261QWT_EXPORT QRectF qwtBoundingRect(
     262    const QwtSeriesData< QwtVectorFieldSample >&, int from = 0, int to = -1 );
    274263
    275264/*!
    … …  
    281270    value the return value will be -1.
    282271
    283   \par Example
     272   \par Example
    284273    The following example shows finds a point of curve from an x
    285274    coordinate
    286275    \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>
    289278
    290279      struct compareX
    … …  
    299288      {
    300289          int index = qwtUpperSampleIndex<QPointF>(
    301               *curve->data(), x, compareX() );
     290 * curve->data(), x, compareX() );
    302291
    303292          if ( index == -1 &&
    … …  
    319308
    320309    \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
    328317        by the lessThan object
    329318 */
    330 template <typename T, typename LessThan>
    331 inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series,
     319template< typename T, typename LessThan >
     320inline int qwtUpperSampleIndex( const QwtSeriesData< T >& series,
    332321    double value, LessThan lessThan  )
    333322{
    334323    const int indexMax = series.size() - 1;
    335324
    336     if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) )  )
     325    if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
    337326        return -1;
    338327
Note: See TracChangeset for help on using the changeset viewer.