Qwt User's Guide 6.0.1

- Main Page
- Related Pages
- Classes
- Files

- File List

# qwt_plot_seriesitem.h

    00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
    00002  * Qwt Widget Library
    00003  * Copyright (C) 1997   Josef Wilgen
    00004  * Copyright (C) 2002   Uwe Rathmann
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the Qwt License, Version 1.0
    00008  *****************************************************************************/
    00009
    00010 #ifndef QWT_PLOT_SERIES_ITEM_H
    00011 #define QWT_PLOT_SERIES_ITEM_H
    00012
    00013 #include "qwt_global.h"
    00014 #include "qwt_plot_item.h"
    00015 #include "qwt_scale_div.h"
    00016 #include "qwt_series_data.h"
    00017
    00021 class QWT_EXPORT QwtPlotAbstractSeriesItem: public QwtPlotItem
    00022 {
    00023 public:
    00024     explicit QwtPlotAbstractSeriesItem( const QString &title = QString::null );
    00025     explicit QwtPlotAbstractSeriesItem( const QwtText &title );
    00026
    00027     virtual ~QwtPlotAbstractSeriesItem();
    00028
    00029     void setOrientation( Qt::Orientation );
    00030     Qt::Orientation orientation() const;
    00031
    00032     virtual void draw( QPainter *p,
    00033         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    00034         const QRectF & ) const;
    00035
    00047     virtual void drawSeries( QPainter *painter,
    00048         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    00049         const QRectF &canvasRect, int from, int to ) const = 0;
    00050
    00051 private:
    00052     class PrivateData;
    00053     PrivateData *d_data;
    00054 };
    00055
    00059 template <typename T>
    00060 class QwtPlotSeriesItem: public QwtPlotAbstractSeriesItem
    00061 {
    00062 public:
    00063     explicit QwtPlotSeriesItem<T>( const QString &title = QString::null );
    00064     explicit QwtPlotSeriesItem<T>( const QwtText &title );
    00065
    00066     virtual ~QwtPlotSeriesItem<T>();
    00067
    00068     void setData( QwtSeriesData<T> * );
    00069
    00070     QwtSeriesData<T> *data();
    00071     const QwtSeriesData<T> *data() const;
    00072
    00073     size_t dataSize() const;
    00074     T sample( int index ) const;
    00075
    00076     virtual QRectF boundingRect() const;
    00077     virtual void updateScaleDiv( const QwtScaleDiv &,
    00078                                  const QwtScaleDiv & );
    00079
    00080 protected:
    00082     QwtSeriesData<T> *d_series;
    00083 };
    00084
    00089 template <typename T>
    00090 QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QString &title ):
    00091     QwtPlotAbstractSeriesItem( QwtText( title ) ),
    00092     d_series( NULL )
    00093 {
    00094 }
    00095
    00100 template <typename T>
    00101 QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QwtText &title ):
    00102     QwtPlotAbstractSeriesItem( title ),
    00103     d_series( NULL )
    00104 {
    00105 }
    00106
    00108 template <typename T>
    00109 QwtPlotSeriesItem<T>::~QwtPlotSeriesItem()
    00110 {
    00111     delete d_series;
    00112 }
    00113
    00115 template <typename T>
    00116 inline QwtSeriesData<T> *QwtPlotSeriesItem<T>::data()
    00117 {
    00118     return d_series;
    00119 }
    00120
    00122 template <typename T>
    00123 inline const QwtSeriesData<T> *QwtPlotSeriesItem<T>::data() const
    00124 {
    00125     return d_series;
    00126 }
    00127
    00132 template <typename T>
    00133 inline T QwtPlotSeriesItem<T>::sample( int index ) const
    00134 {
    00135     return d_series ? d_series->sample( index ) : T();
    00136 }
    00137
    00145 template <typename T>
    00146 void QwtPlotSeriesItem<T>::setData( QwtSeriesData<T> *data )
    00147 {
    00148     if ( d_series != data )
    00149     {
    00150         delete d_series;
    00151         d_series = data;
    00152         itemChanged();
    00153     }
    00154 }
    00155
    00160 template <typename T>
    00161 size_t QwtPlotSeriesItem<T>::dataSize() const
    00162 {
    00163     if ( d_series == NULL )
    00164         return 0;
    00165
    00166     return d_series->size();
    00167 }
    00168
    00175 template <typename T>
    00176 QRectF QwtPlotSeriesItem<T>::boundingRect() const
    00177 {
    00178     if ( d_series == NULL )
    00179         return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
    00180
    00181     return d_series->boundingRect();
    00182 }
    00183
    00192 template <typename T>
    00193 void QwtPlotSeriesItem<T>::updateScaleDiv(
    00194     const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv )
    00195 {
    00196     const QRectF rect = QRectF(
    00197         xScaleDiv.lowerBound(), yScaleDiv.lowerBound(),
    00198         xScaleDiv.range(), yScaleDiv.range() );
    00199
    00200     d_series->setRectOfInterest( rect );
    00201 }
    00202
    00203 #endif