18#include "TimeInputField.hpp"
26 : QWidget(parent), text(std::move(text)), resolution(resolution), time(0) {
28 this->textLabel =
new QLabel(this->text,
this);
30 this->lineEdit =
new QLineEdit(QString::number(this->time.count()),
this);
31 this->lineEdit->setValidator(
new QDoubleValidator(
this));
33 this->comboBox =
new QComboBox(
this);
34 for (
const auto &unit : TIME_UNITS) {
35 this->comboBox->addItem(unit.str());
37 this->comboBox->setCurrentText(resolution.
str());
39 auto layout =
new QHBoxLayout(
this);
40 layout->addWidget(this->textLabel);
41 layout->addWidget(this->lineEdit);
42 layout->addWidget(this->comboBox);
43 this->setLayout(layout);
45 connect(this->comboBox, &QComboBox::currentTextChanged, [
this] (
const auto &newValue) {
46 this->resolution =
TimeUnit(newValue);
47 double newTextValue =
static_cast<double>(time.count()) / this->resolution.
multiplier();
48 this->lineEdit->setText(QString::number(newTextValue));
51 connect(this->lineEdit, &QLineEdit::returnPressed, [
this] {
52 double newValue = this->lineEdit->text().toDouble();
53 auto newTotalValue =
static_cast<u_int64_t
>(newValue * this->resolution.
multiplier());
54 this->
setTime(types::TraceTime(newTotalValue));
61 this->updateFunction = std::move(newUpdateFunction);
67 if (this->updateFunction) {
68 this->updateFunction(this->time);
71 double newTextValue =
static_cast<double>(time.count()) / this->resolution.
multiplier();
72 this->lineEdit->setText(QString::number(newTextValue));
Represents possible units on the time scale.
double multiplier() const