Motiv
Marvelous OTF2 Traces Interactive Visualizer
Loading...
Searching...
No Matches
TimelineHeader.cpp
1/*
2 * Marvelous OTF2 Traces Interactive Visualizer (MOTIV)
3 * Copyright (C) 2023 Florian Gallrein, Björn Gehrke
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include "TimelineHeader.hpp"
19
20#include <QHBoxLayout>
21#include <QLabel>
22
23#include "TimeUnitLabel.hpp"
24#include "src/utils.hpp"
25
26TimelineHeader::TimelineHeader(TraceDataProxy *data, QWidget *parent) : QWidget(parent), data(data) {
27 this->setLayout(new QHBoxLayout(this));
28 this->updateView();
29
30 // @formatter:off
31 connect(this->data, SIGNAL(selectionChanged(types::TraceTime,types::TraceTime)), this, SLOT(updateView()));
32 // @formatter:on
33}
34
36 auto layout = this->layout();
37 auto selection = this->data->getSelection();
38 auto runtime = static_cast<double>(selection->getRuntime().count());
39 auto begin = static_cast<double>(selection->getStartTime().count());
40
41 resetLayout(layout);
42
43 int marks = 4;
44 for (int i = 0; i <= marks; i++) {
45 double num = begin + static_cast<double>(i)/marks * runtime;
46 auto label = new TimeUnitLabel(num, this);
47 layout->addWidget(label);
48 if (i != marks) {
49 dynamic_cast<QHBoxLayout *>(layout)->addStretch();
50 }
51 }
52}
TimeUnitLabel constructs a QLabel from a double value that represents a time point.
void updateView()
Updates the view.
TimelineHeader(TraceDataProxy *data, QWidget *parent=nullptr)
Creates a new instance of the TimelineHeader class.
Model class providing access to data and pub/sub architecture of change events.
Trace * getSelection() const
Returns the current selection.