summaryrefslogtreecommitdiff
path: root/gui/graphing/heatmapview.h
blob: 86d8848d82563e7c7b60671c62ad0c5a45a778d1 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once

#include "graphview.h"

/**
 * The heatmap iterator will only return data when there is something to draw,
 * this allows much faster access to the data in the case where the view is
 * zoomed out to the point of where there is multiple calls in one pixel,
 * it automagically calculates the heat for that pixel.
 */
class HeatmapRowIterator {
public:
    virtual ~HeatmapRowIterator(){}

    /* Go to the next visible heat map */
    virtual bool next() = 0;

    /* Is the current value GPU or CPU heat */
    virtual bool isGpu() const = 0;

    /* Current step (normally x coordinate) */
    virtual int step() const = 0;

    /* Current width (in steps) */
    virtual int width() const = 0;

    /* Current heat */
    virtual float heat() const = 0;

    /* Heat value for selected calls */
    virtual float selectedHeat() const = 0;

    /* Label only used when there is a single call in this heat */
    virtual QString label() const = 0;
};


/**
 * Data provider for the whole heatmap
 */
class HeatmapDataProvider {
public:
    virtual ~HeatmapDataProvider(){}

    /* The start and end values (time on x-axis) for the heatmap */
    virtual qint64 start() const = 0;
    virtual qint64 end() const = 0;

    /*
     * Header rows (fixed at top of heatmap view)
     */

    /* Header row count */
    virtual unsigned headerRows() const = 0;

    /* Label to be used in the vertical axis */
    virtual QString headerLabel(unsigned row) const = 0;

    /* Get identifier (program no) for row */
    virtual qint64 headerRowAt(unsigned row) const = 0;

    /* Get item at row and time */
    virtual qint64 headerItemAt(unsigned row, qint64 time) const = 0;

    /* Get iterator for a row between start and end time for steps */
    virtual HeatmapRowIterator* headerRowIterator(int row, qint64 start, qint64 end, int steps) const = 0;

    /*
     * Data rows (scrollable in heatmap view)
     */

    /* Data row count */
    virtual unsigned dataRows() const = 0;

    /* Label to be used in the vertical axis */
    virtual QString dataLabel(unsigned row) const = 0;

    /* Get identifier (program no) for row */
    virtual qint64 dataRowAt(unsigned row) const = 0;

    /* Get item at row and time */
    virtual qint64 dataItemAt(unsigned row, qint64 time) const = 0;

    /* Get iterator for a row between start and end time for steps */
    virtual HeatmapRowIterator* dataRowIterator(int row, qint64 start, qint64 end, int steps) const = 0;

    /* Handle double click on item */
    virtual void itemDoubleClicked(qint64 index) const = 0;

    /* Get mouse over tooltip for item */
    virtual QString itemTooltip(qint64 index) const = 0;

    /* Set the selection */
    virtual void setSelectionState(SelectionState* state) = 0;
};


/**
 * A not very generic heatmap for row based data
 */
class HeatmapView : public GraphView {
public:
    HeatmapView(QWidget* parent);

    void setDataProvider(HeatmapDataProvider* data);
    void setSelectionState(SelectionState* state);

    virtual void mouseMoveEvent(QMouseEvent *e);
    virtual void mouseDoubleClickEvent(QMouseEvent *e);

    virtual void paintEvent(QPaintEvent *e);
    virtual void paintRow(QPainter& painter, HeatmapRowIterator* itr);


protected:
    qint64 itemAtPosition(QPoint pos);

protected:
    int m_rowHeight;
    HeatmapDataProvider* m_data;
};