aboutsummaryrefslogtreecommitdiff
path: root/barchart.h
blob: 933c004f39863d1edb56734c5df730c1b87aac23 (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
#ifndef BARCHART_H
#define BARCHART_H

#include <vector>

#include <QtQuick>

#include <armadillo>

#include "scale.h"

class BarChart
    : public QQuickItem
{
    Q_OBJECT
public:
    BarChart(QQuickItem *parent = 0);
    ~BarChart();

signals:
    void valuesChanged(const arma::vec &values) const;

public slots:
    void setValues(const arma::vec &values);

protected:
    QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);
    void hoverMoveEvent(QHoverEvent *event);
    void mousePressEvent(QMouseEvent *event);

private:
    QSGNode *newBarNode() const;
    void updateBarNodeGeom(QSGNode *barNode, float x, float width, float height);
    void updateBars(QSGNode *root);
    bool m_shouldUpdateBars;

    arma::vec m_values;
    std::vector<int> m_originalIndices;
    LinearScale<float> m_scale;
};

#endif // BARCHART_H