Pointer + time delta
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#include "setdaydialog.h"
|
||||
#include "ui_setdaydialog.h"
|
||||
|
||||
SetDayDialog::SetDayDialog(Day d, bool isNotValidable, QWidget *parent) :
|
||||
SetDayDialog::SetDayDialog(Day *d, bool isNotValidable, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::SetDayDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
copy = new Day(d);
|
||||
ui->validateButton->setEnabled(!isNotValidable);
|
||||
ui->validateButton->setVisible(!isNotValidable);
|
||||
this->d = d;
|
||||
@@ -14,43 +15,47 @@ SetDayDialog::SetDayDialog(Day d, bool isNotValidable, QWidget *parent) :
|
||||
|
||||
SetDayDialog::~SetDayDialog()
|
||||
{
|
||||
delete copy;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SetDayDialog::init() {
|
||||
ui->start_edit->setTime(d.get_start());
|
||||
ui->end_edit->setTime(d.get_end());
|
||||
ui->start_edit->setTime(copy->get_start());
|
||||
ui->end_edit->setTime(copy->get_end());
|
||||
updateBreakList();
|
||||
connect(ui->start_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
connect(ui->end_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
connect(ui->validateButton, &QPushButton::clicked, this, &SetDayDialog::validate);
|
||||
connect(ui->validateButton, &QPushButton::clicked, this, &SetDayDialog::validate_and_accept);
|
||||
connect(ui->pushButton, &QPushButton::clicked, this, &SetDayDialog::accept);
|
||||
connect(ui->addBreakButton, &QPushButton::clicked, this, &SetDayDialog::add_break_point);
|
||||
connect(ui->removeBreakButton, &QPushButton::clicked, this, &SetDayDialog::remove_break_point);
|
||||
connect(ui->breakList, &QListWidget::currentRowChanged, this, &SetDayDialog::break_selected);
|
||||
ui->total_label->setText(Tools::double_to_string_time(d.get_total()));
|
||||
ui->total_label->setText(Tools::double_to_string_time(d->get_total()));
|
||||
}
|
||||
|
||||
void SetDayDialog::updateBreakList()
|
||||
{
|
||||
ui->breakList->clear();
|
||||
foreach (BreakPoint bp, d.getBreaks()) {
|
||||
ui->breakList->addItem(QString("%1 -> %2").arg(bp.getStart().toString("hh:mm"), bp.getEnd().toString("hh:mm")));
|
||||
foreach (BreakPoint *bp, copy->getBreaks()) {
|
||||
ui->breakList->addItem(QString("%1 -> %2").arg(bp->getStart().toString("hh:mm"), bp->getEnd().toString("hh:mm")));
|
||||
}
|
||||
}
|
||||
|
||||
void SetDayDialog::compute_time() {
|
||||
d.set_validate(false);
|
||||
d.set_start(ui->start_edit->time());
|
||||
d.set_end(ui->end_edit->time());
|
||||
ui->total_label->setText(Tools::double_to_string_time(d.get_total()));
|
||||
copy->set_validate(false);
|
||||
copy->set_start(ui->start_edit->time());
|
||||
copy->set_end(ui->end_edit->time());
|
||||
ui->total_label->setText(Tools::double_to_string_time(copy->get_total()));
|
||||
}
|
||||
|
||||
Day SetDayDialog::get_result() {
|
||||
return d;
|
||||
void SetDayDialog::accept()
|
||||
{
|
||||
d->update(copy);
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void SetDayDialog::validate() {
|
||||
d.set_validate(true);
|
||||
void SetDayDialog::validate_and_accept() {
|
||||
d->set_validate(true);
|
||||
accept();
|
||||
}
|
||||
|
||||
@@ -60,9 +65,9 @@ void SetDayDialog::add_break_point()
|
||||
int result = bd.exec();
|
||||
if (result == QDialog::Accepted) {
|
||||
BreakPoint bp = bd.get_result();
|
||||
auto breaks = d.getBreaks();
|
||||
breaks.append(bp);
|
||||
d.setBreaks(breaks);
|
||||
auto breaks = copy->getBreaks();
|
||||
breaks.append(new BreakPoint(bp));
|
||||
copy->setBreaks(breaks);
|
||||
updateBreakList();
|
||||
compute_time();
|
||||
}
|
||||
@@ -72,9 +77,11 @@ void SetDayDialog::remove_break_point()
|
||||
{
|
||||
int i = ui->breakList->currentRow();
|
||||
if (i > -1) {
|
||||
auto breaks = d.getBreaks();
|
||||
auto breaks = copy->getBreaks();
|
||||
BreakPoint *bp = breaks.at(i);
|
||||
breaks.removeAt(i);
|
||||
d.setBreaks(breaks);
|
||||
delete bp;
|
||||
copy->setBreaks(breaks);
|
||||
updateBreakList();
|
||||
compute_time();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user