IncrementalPlot.h 1.54 KB
Newer Older
1 2 3 4 5 6
#ifndef INCREMENTALPLOT_H
#define INCREMENTALPLOT_H

#include <QTimer>
#include <qwt_array.h>
#include <qwt_plot.h>
7
#include <qwt_legend.h>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#include <QMap>
#include "ScrollZoomer.h"

class QwtPlotCurve;

class CurveData
{
    // A container class for growing data
public:

    CurveData();

    void append(double *x, double *y, int count);

    int count() const;
    int size() const;
    const double *x() const;
    const double *y() const;

private:
    int d_count;
    QwtArray<double> d_x;
    QwtArray<double> d_y;
    QTimer *d_timer;
    int d_timerCount;
};

class IncrementalPlot : public QwtPlot
{
    Q_OBJECT
public:
    IncrementalPlot(QWidget *parent = NULL);
    virtual ~IncrementalPlot();

    /** @brief Get color map of this plot */
lm's avatar
lm committed
43
    QList<QColor> getColorMap();
44
    /** @brief Get next color of color map */
lm's avatar
lm committed
45
    QColor getNextColor();
46
    /** @brief Get color for curve id */
lm's avatar
lm committed
47
    QColor getColorForCurve(QString id);
48

49 50 51 52 53 54 55 56 57 58 59
public slots:
    void appendData(QString key, double x, double y);
    void appendData(QString key, double *x, double *y, int size);

    void resetScaling();
    void removeData();
    /** @brief Show the plot legend */
    void showLegend(bool show);
    /** @brief Set new plot style */
    void setStyleText(QString style);

60 61 62 63
protected:
    QList<QColor> colors;
    int nextColor;
    ScrollZoomer* zoomer;
64
    QwtLegend* legend;
65 66 67 68 69 70 71 72 73 74 75
    double xmin;
    double xmax;
    double ymin;
    double ymax;

private:
    QMap<QString, CurveData* > d_data;
    QMap<QString, QwtPlotCurve* > d_curve;
};

#endif /* INCREMENTALPLOT_H */