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

#include <vector>

#include <QtQuick>
#include <QSet>

#include <armadillo>

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

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

signals:
    void valuesChanged(const arma::vec &values) const;
    void colorScaleChanged(const ColorScale &scale) const;
    void selectionChanged(const QSet<int> &selection) const;

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

protected:
    QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);

    void hoverEnterEvent(QHoverEvent *event);
    void hoverMoveEvent(QHoverEvent *event);
    void hoverLeaveEvent(QHoverEvent *event);

    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

private:
    QSGNode *newSceneGraph() const;
    QSGNode *newBarNode() const;

    void updateViewport(QSGNode *root) const;
    void updateBarNodeGeom(QSGNode *barNode, float x, float width, float height);
    void updateBarNodeColor(QSGNode *barNode, const QColor &color);
    void updateBars(QSGNode *node);
    void updateHoverHints(QSGNode *node);
    bool m_shouldUpdateBars;
    float m_hoverPos;

    void updateSelectionRect(QSGNode *node);
    bool m_shouldUpdateSelectionRect;
    void selectBarsInRange(float start, float end);
    float m_dragStartPos, m_dragLastPos;
    QSet<int> m_selection;

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

#endif // BARCHART_H