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