aboutsummaryrefslogtreecommitdiff
path: root/scatterplot.h
blob: a1157558b88be23b3726d6152b673d9c5495249f (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
#ifndef SCATTERPLOT_H
#define SCATTERPLOT_H

#include <armadillo>
#include <QtQuick>

#include "colorscale.h"

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

    void setColorScale(const ColorScale &colorScale);

signals:
    void xyChanged(const arma::mat &XY);
    void colorDataChanged(const arma::vec &colorData);

public slots:
    void setXY(const arma::mat &xy);
    void setColorData(const arma::vec &colorData);

protected:
    QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

private:
    QSGNode *createGlyphNodeTree();
    bool selectGlyphs(bool mergeSelection);

    float fromDataXToScreenX(float x);
    float fromDataYToScreenY(float y);

    void applyManipulation();

    void updateGeometry();
    void updateMaterials();

    arma::mat m_xy;
    float m_xmin, m_xmax, m_ymin, m_ymax;

    enum InteractionState {
        INTERACTION_NONE,
        INTERACTION_SELECTING,
        INTERACTION_SELECTED,
        INTERACTION_MOVING
    } m_currentInteractionState;

    QPointF m_dragOriginPos, m_dragCurrentPos;

    QSet<int> m_selectedGlyphs;

    bool m_shouldUpdateGeometry, m_shouldUpdateMaterials;

    arma::vec m_colorData;

    ColorScale m_colorScale;
};

#endif // SCATTERPLOT_H