File: timeaxiswidget.cpp

package info (click to toggle)
apitrace 7.1%2Bgit20170623.d38a69d6%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,992 kB
  • sloc: cpp: 179,347; ansic: 62,439; python: 33,058; java: 377; makefile: 105; sh: 26; xml: 26
file content (80 lines) | stat: -rw-r--r-- 2,544 bytes parent folder | download | duplicates (5)
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
#include "timeaxiswidget.h"
#include "profiling.h"

#include <qmath.h>
#include <QPainter>

TimeAxisWidget::TimeAxisWidget(QWidget* parent) :
    GraphAxisWidget(parent)
{
}

void TimeAxisWidget::paintEvent(QPaintEvent *)
{
    /* TODO: Support selections? */
    /* TODO: Vertical scrolling? */

    QPainter painter(this);
    painter.setPen(Qt::black);
    painter.setBrush(Qt::lightGray);
    painter.drawRect(0, 0, width() - 1, height() - 1);

    if (m_orientation == GraphAxisWidget::Vertical) {
        int axisHeight = height() - 1;
        int fontHeight = painter.fontMetrics().height();
        int ticks     = axisHeight / (fontHeight * 2);

        double range  = m_valueMax - m_valueMin;
        double step   = range / (double)ticks;
        double step10 = qPow(10.0, qFloor(qLn(step) / qLn(10.0)));
        step = qFloor((step / step10) * 2) * (step10 / 2);

        if (step <= 0) {
            return;
        }

        painter.resetTransform();

        for (double tick = 0; tick <= range; tick += step) {
            int y = axisHeight - ((tick / range) * axisHeight);

            painter.drawLine(width() - 8, y, width(), y);

            painter.drawText(0,
                             qBound(0, y - fontHeight / 2, axisHeight - fontHeight),
                             width() - 10,
                             fontHeight,
                             Qt::AlignRight | Qt::AlignVCenter,
                             Profiling::getTimeString(tick, m_valueMax));
        }
    } else {
        int axisWidth = width() - 1;
        int fontWidth = painter.fontMetrics().width("0.000 ns");
        int fontHeight= painter.fontMetrics().height();
        int ticks     = axisWidth / (fontWidth * 2);

        double range  = m_valueMax - m_valueMin;
        double step   = range / (double)ticks;
        double step10 = qPow(10.0, qFloor(qLn(step) / qLn(10.0)));
        step = qFloor((step / step10) * 2) * (step10 / 2);

        if (step <= 0) {
            return;
        }

        painter.resetTransform();

        for (double tick = 0; tick <= range; tick += step) {
            int x = (tick / range) * axisWidth;

            painter.drawLine(x, 0, x, 8);

            painter.drawText(qBound(0, x - fontWidth / 2, axisWidth - fontWidth),
                             8,
                             fontWidth,
                             fontHeight,
                             Qt::AlignHCenter | Qt::AlignTop,
                             Profiling::getTimeString(tick, m_valueMax));
        }
    }
}