Motiv
Marvelous OTF2 Traces Interactive Visualizer
Loading...
Searching...
No Matches
TimeUnitLabel.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 "TimeUnitLabel.hpp"
19
20#include "src/ui/TimeUnit.hpp"
21
22TimeUnitLabel::TimeUnitLabel(double time, QWidget *parent) : QLabel(parent), time(time) {
23 updateView();
24}
25
26void TimeUnitLabel::setTime(double t) {
27 if(t == time) return;
28 time = t;
29
30 updateView();
31}
32
33double TimeUnitLabel::getTime() const {
34 return time;
35}
36
38 QString unitStr;
39 QString timeStr = "0";
40
41 for(const auto &unit : TIME_UNITS) {
42 auto m = unit.multiplier();
43 if (this->time >= m) {
44 unitStr = unit.str();
45 timeStr = QString::number(this->time/m, 'f');
46 } else {
47 break;
48 }
49 }
50 this->setText(timeStr + unitStr);
51}
52
double getTime() const
void setTime(double time)
TimeUnitLabel(double time, QWidget *parent=nullptr)
void updateView()
Updates the view to reflect the current state.