aboutsummaryrefslogtreecommitdiff
path: root/lineplot.h
blob: 060171defddf80e299c9bdd66df31aeef5d47840 (plain)
1
2
3
4
5
6
7
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef LINEPLOT_H
#define LINEPLOT_H

#include <memory>
#include <vector>

#include <QQuickFramebufferObject>

#include <armadillo>

// From CUBu
#include "gdrawing.h"

#include "colorscale.h"
#include "scale.h"

class LinePlot
    : public QQuickFramebufferObject
{
    Q_OBJECT
public:
    static const int PADDING = 20;

    LinePlot(QQuickItem *parent = 0);

    void setColorScale(const ColorScale *colorScale);
    void setAutoScale(bool autoScale);

    const GraphDrawing *graphDrawing() const { return m_gdPtr.get(); }
    const std::vector<float> &values() const { return m_values; }
    LinearScale<float> scaleX() const { return m_sx; }
    LinearScale<float> scaleY() const { return m_sy; }

    Renderer *createRenderer() const;

    bool xyChanged() const         { return m_xyChanged; }
    bool valuesChanged() const     { return m_valuesChanged; }
    bool colorScaleChanged() const { return m_colorScaleChanged; }

    void setXYChanged(bool xyChanged) {
        m_xyChanged = xyChanged;
    }
    void setValuesChanged(bool valuesChanged) {
        m_valuesChanged = valuesChanged;
    }
    void setColorScaleChanged(bool colorScaleChanged) {
        m_colorScaleChanged = colorScaleChanged;
    }

signals:
    void xyChanged(const arma::mat &xy);
    void valuesChanged(const arma::vec &values) const;
    void scaleChanged(const LinearScale<float> &sx,
                      const LinearScale<float> &sy) const;

public slots:
    void setXY(const arma::mat &xy);
    void setValues(const arma::vec &values);
    void setScale(const LinearScale<float> &sx,
                  const LinearScale<float> &sy);

private:
    void bundle();

    // Data
    arma::mat m_xy;
    std::vector<float> m_values;

    // Visuals
    const ColorScale *m_colorScale;

    void autoScale();
    bool m_autoScale;
    LinearScale<float> m_sx, m_sy;

    std::unique_ptr<GraphDrawing> m_gdPtr;

    // Internal state
    bool m_xyChanged, m_valuesChanged, m_colorScaleChanged;
    bool m_bundleGPU;
};

#endif // LINEPLOT_H