TimeWidget.cpp
50 lines
| 1.5 KiB
| text/x-c
|
CppLexer
r126 | #include "TimeWidget/TimeWidget.h" | |||
#include "ui_TimeWidget.h" | ||||
Alexandre Leroux
|
r451 | #include <Common/DateUtils.h> | ||
r279 | #include <SqpApplication.h> | |||
#include <Time/TimeController.h> | ||||
r178 | ||||
r126 | TimeWidget::TimeWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::TimeWidget} | |||
{ | ||||
ui->setupUi(this); | ||||
r178 | ||||
r279 | ui->applyToolButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_DialogApplyButton)); | |||
r178 | // Connection | |||
connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, | ||||
&TimeWidget::onTimeUpdateRequested); | ||||
connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, | ||||
&TimeWidget::onTimeUpdateRequested); | ||||
r279 | ||||
connect(ui->applyToolButton, &QToolButton::clicked, &sqpApp->timeController(), | ||||
&TimeController::onTimeNotify); | ||||
r281 | ||||
// Initialisation | ||||
Alexandre Leroux
|
r451 | auto endDateTime = QDateTime::currentDateTimeUtc(); | ||
auto startDateTime = endDateTime.addSecs(-3600); // one hour before | ||||
ui->startDateTimeEdit->setDateTime(startDateTime); | ||||
ui->endDateTimeEdit->setDateTime(endDateTime); | ||||
r471 | auto dateTime = SqpRange{DateUtils::secondsSinceEpoch(startDateTime), | |||
DateUtils::secondsSinceEpoch(endDateTime)}; | ||||
r281 | ||||
sqpApp->timeController().onTimeToUpdate(dateTime); | ||||
r126 | } | |||
r279 | ||||
r126 | TimeWidget::~TimeWidget() | |||
{ | ||||
delete ui; | ||||
} | ||||
r178 | ||||
void TimeWidget::onTimeUpdateRequested() | ||||
{ | ||||
r471 | auto dateTime = SqpRange{DateUtils::secondsSinceEpoch(ui->startDateTimeEdit->dateTime()), | |||
DateUtils::secondsSinceEpoch(ui->endDateTimeEdit->dateTime())}; | ||||
r178 | ||||
emit timeUpdated(std::move(dateTime)); | ||||
} | ||||