Add support of leaves
This commit is contained in:
@@ -185,12 +185,8 @@ void MainWindow::compute_time() {
|
||||
ui->thu_time_label->setText(Tools::double_to_string_time(current_week->getThu()->get_total()));
|
||||
ui->fri_time_label->setText(Tools::double_to_string_time(current_week->getFri()->get_total()));
|
||||
ui->total_time_label->setText(Tools::double_to_string_time(current_week->total()));
|
||||
updateStartLabel();
|
||||
updateBreakLabel();
|
||||
updateEndLabel();
|
||||
updateLabels();
|
||||
updateWeekTime();
|
||||
updateValidIcon();
|
||||
updateWarningIcon();
|
||||
|
||||
double late = 0.0;
|
||||
double overtime = 0.0;
|
||||
@@ -199,8 +195,8 @@ void MainWindow::compute_time() {
|
||||
while (i.hasNext()) {
|
||||
Week *w = i.next().value();
|
||||
if (w->getWeekNumber() <= todayWeekNumber) {
|
||||
late += (week_template->total() - w->total()) - w->getTimeDeltaInHours();
|
||||
overtime += (w->total() - week_template->total()) + w->getTimeDeltaInHours();
|
||||
late += (week_template->total() - w->total(week_template)) - w->getTimeDeltaInHours();
|
||||
overtime += (w->total() - week_template->total(week_template)) + w->getTimeDeltaInHours();
|
||||
}
|
||||
}
|
||||
late -= current_week->getTimeDeltaInHours();
|
||||
@@ -209,25 +205,9 @@ void MainWindow::compute_time() {
|
||||
ui->overtime_time_label->setText(Tools::double_to_string_time((overtime > 0.0) ? overtime : 0.0));
|
||||
}
|
||||
|
||||
void MainWindow::updateValidIcon() {
|
||||
ui->mondayValidate->setVisible(current_week->getMon()->get_validate());
|
||||
ui->tuesdayValidate->setVisible(current_week->getTue()->get_validate());
|
||||
ui->wednesdayValidate->setVisible(current_week->getWed()->get_validate());
|
||||
ui->thurdayValidate->setVisible(current_week->getThu()->get_validate());
|
||||
ui->fridayValidate->setVisible(current_week->getFri()->get_validate());
|
||||
}
|
||||
|
||||
void MainWindow::updateWarningIcon() {
|
||||
ui->mondayWarning->setVisible(current_week->getMon()->has_warning());
|
||||
ui->tuesdayWarning->setVisible(current_week->getTue()->has_warning());
|
||||
ui->wednesdayWarning->setVisible(current_week->getWed()->has_warning());
|
||||
ui->thurdayWarning->setVisible(current_week->getThu()->has_warning());
|
||||
ui->fridayWarning->setVisible(current_week->getFri()->has_warning());
|
||||
}
|
||||
|
||||
void MainWindow::updateWeekTime()
|
||||
{
|
||||
double t = (current_week->total() + current_week->getTimeDeltaInHours()) - week_template->total();
|
||||
double t = (current_week->total(week_template) + current_week->getTimeDeltaInHours()) - week_template->total();
|
||||
if (t > 0) {
|
||||
ui->overtime_time_label_week->setText(Tools::double_to_string_time(t));
|
||||
ui->late_time_label_week->setText("0h");
|
||||
@@ -240,28 +220,30 @@ void MainWindow::updateWeekTime()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateStartLabel() {
|
||||
ui->monStartLabel->setText(current_week->getMon()->get_start().toString("HH:mm"));
|
||||
ui->tueStartLabel->setText(current_week->getTue()->get_start().toString("HH:mm"));
|
||||
ui->wedStartLabel->setText(current_week->getWed()->get_start().toString("HH:mm"));
|
||||
ui->thuStartLabel->setText(current_week->getThu()->get_start().toString("HH:mm"));
|
||||
ui->friStartLabel->setText(current_week->getFri()->get_start().toString("HH:mm"));
|
||||
void MainWindow::updateLabels() {
|
||||
updateDayLabels(ui->monStartLabel, ui->monEndLabel, ui->monBreakLabel, ui->mondayValidate, ui->mondayWarning, ui->mondayNotWorking, current_week->getMon());
|
||||
updateDayLabels(ui->tueStartLabel, ui->tueEndLabel, ui->tueBreakLabel, ui->tuesdayValidate, ui->tuesdayWarning, ui->tuesdayNotWorking, current_week->getTue());
|
||||
updateDayLabels(ui->wedStartLabel, ui->wedEndLabel, ui->wedBreakLabel, ui->wednesdayValidate, ui->wednesdayWarning, ui->wednesdayNotWorking, current_week->getWed());
|
||||
updateDayLabels(ui->thuStartLabel, ui->thuEndLabel, ui->thuBreakLabel, ui->thurdayValidate, ui->thurdayWarning, ui->thurdayNotWorking, current_week->getThu());
|
||||
updateDayLabels(ui->friStartLabel, ui->friEndLabel, ui->friBreakLabel, ui->fridayValidate, ui->fridayWarning, ui->fridayNotWorking, current_week->getFri());
|
||||
}
|
||||
|
||||
void MainWindow::updateBreakLabel() {
|
||||
ui->monBreakLabel->setText(QString("%1 min.").arg(current_week->getMon()->get_time_break()));
|
||||
ui->tueBreakLabel->setText(QString("%1 min.").arg(current_week->getTue()->get_time_break()));
|
||||
ui->wedBreakLabel->setText(QString("%1 min.").arg(current_week->getWed()->get_time_break()));
|
||||
ui->thuBreakLabel->setText(QString("%1 min.").arg(current_week->getThu()->get_time_break()));
|
||||
ui->friBreakLabel->setText(QString("%1 min.").arg(current_week->getFri()->get_time_break()));
|
||||
}
|
||||
|
||||
void MainWindow::updateEndLabel() {
|
||||
ui->monEndLabel->setText(current_week->getMon()->get_end().toString("HH:mm"));
|
||||
ui->tueEndLabel->setText(current_week->getTue()->get_end().toString("HH:mm"));
|
||||
ui->wedEndLabel->setText(current_week->getWed()->get_end().toString("HH:mm"));
|
||||
ui->thuEndLabel->setText(current_week->getThu()->get_end().toString("HH:mm"));
|
||||
ui->friEndLabel->setText(current_week->getFri()->get_end().toString("HH:mm"));
|
||||
void MainWindow::updateDayLabels(QLabel *start, QLabel *end, QLabel *breaks, QFrame *validate, QFrame *warning, QFrame *not_working, Day *d)
|
||||
{
|
||||
not_working->setVisible(d->not_working());
|
||||
if (!d->not_working()) {
|
||||
start->setText(d->get_start().toString("HH:mm"));
|
||||
end->setText(d->get_end().toString("HH:mm"));
|
||||
breaks->setText(QString("%1 min.").arg(d->get_time_break()));
|
||||
validate->setVisible(d->get_validate());
|
||||
warning->setVisible(d->has_warning());
|
||||
} else {
|
||||
start->setText("--:--");
|
||||
end->setText("--:--");
|
||||
breaks->setText("0 min.");
|
||||
validate->setVisible(false);
|
||||
warning->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::edit() {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define KEY_TEMPLATE "template"
|
||||
#define KEY_YEARS "years"
|
||||
#define SAVE_FILENAME "data.json"
|
||||
#define SAVE_FILE_VERSION 3
|
||||
#define SAVE_FILE_VERSION 4
|
||||
#define KEY_SAVE_FILE_VERSION "version"
|
||||
|
||||
#include <QMouseEvent>
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "models/week.h"
|
||||
#include "models/year.h"
|
||||
#include "welcome.h"
|
||||
#include "tools.h"
|
||||
#include "aboutbox.h"
|
||||
#include "weekoption.h"
|
||||
|
||||
@@ -52,13 +51,10 @@ private:
|
||||
void panic_dialog(QString text);
|
||||
|
||||
// UI Update
|
||||
void updateStartLabel();
|
||||
void updateBreakLabel();
|
||||
void updateEndLabel();
|
||||
void updateLabels();
|
||||
void highlightDayOfWeek();
|
||||
void updateValidIcon();
|
||||
void updateWarningIcon();
|
||||
void updateWeekTime();
|
||||
void updateDayLabels(QLabel *start, QLabel *end, QLabel *breaks, QFrame *validate, QFrame *warning, QFrame *not_working, Day *d);
|
||||
|
||||
QString get_save_file_path();
|
||||
Identifier get_identifier(QString objectName);
|
||||
|
||||
@@ -7,6 +7,7 @@ Day::Day()
|
||||
BreakPoint *lunch = new BreakPoint(QTime(12, 0, 0, 0), QTime(12, 45, 0, 0));
|
||||
breaks.append(lunch);
|
||||
validate = false;
|
||||
notWorking = false;
|
||||
}
|
||||
|
||||
Day::Day(Day *old)
|
||||
@@ -16,6 +17,7 @@ Day::Day(Day *old)
|
||||
BreakPoint *lunch = new BreakPoint(QTime(12, 0, 0, 0), QTime(12, 45, 0, 0));
|
||||
breaks.append(lunch);
|
||||
validate = false;
|
||||
notWorking = false;
|
||||
update(old);
|
||||
}
|
||||
|
||||
@@ -51,7 +53,7 @@ void Day::set_validate(bool value) {
|
||||
validate = value;
|
||||
}
|
||||
|
||||
void Day::set_working(bool value)
|
||||
void Day::set_not_working(bool value)
|
||||
{
|
||||
this->notWorking = value;
|
||||
}
|
||||
@@ -86,7 +88,8 @@ QJsonObject Day::to_json()
|
||||
{KEY_START, start.toString(Qt::DateFormat::ISODate)},
|
||||
{KEY_END, end.toString(Qt::DateFormat::ISODate)},
|
||||
{KEY_BREAKS, arr},
|
||||
{KEY_VALIDATE, validate}
|
||||
{KEY_VALIDATE, validate},
|
||||
{KEY_NOT_WORKING, notWorking}
|
||||
};
|
||||
|
||||
return obj;
|
||||
@@ -112,7 +115,8 @@ Day* Day::from_json(QJsonObject obj)
|
||||
|
||||
result->start = QTime::fromString(obj[KEY_START].toString(), Qt::DateFormat::ISODate);
|
||||
result->end = QTime::fromString(obj[KEY_END].toString(), Qt::DateFormat::ISODate);
|
||||
result->validate = obj[KEY_VALIDATE].toBool();
|
||||
result->validate = obj[KEY_VALIDATE].toBool(false);
|
||||
result->notWorking = obj[KEY_NOT_WORKING].toBool(false);
|
||||
|
||||
result->breaks.clear();
|
||||
QJsonArray arr = obj[KEY_BREAKS].toArray();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#define KEY_END "end"
|
||||
#define KEY_BREAKS "breaks"
|
||||
#define KEY_VALIDATE "validate"
|
||||
#define KEY_NOT_WORKING "not_working"
|
||||
|
||||
#include <QTime>
|
||||
#include <QJsonObject>
|
||||
@@ -31,7 +32,7 @@ public:
|
||||
void set_start(QTime value);
|
||||
void set_end(QTime value);
|
||||
void set_validate(bool);
|
||||
void set_working(bool);
|
||||
void set_not_working(bool);
|
||||
void setBreaks(QVector<BreakPoint*>);
|
||||
|
||||
QTime get_start();
|
||||
|
||||
@@ -61,6 +61,37 @@ double Week::total() {
|
||||
return mon->get_total() + tue->get_total() + wed->get_total() + thu->get_total() + fri->get_total();
|
||||
}
|
||||
|
||||
double Week::total(Week *wtemplate)
|
||||
{
|
||||
double t = 0.0;
|
||||
if (mon->not_working()) {
|
||||
t += wtemplate->mon->get_total();
|
||||
} else {
|
||||
t += mon->get_total();
|
||||
}
|
||||
if (tue->not_working()) {
|
||||
t += wtemplate->tue->get_total();
|
||||
} else {
|
||||
t += tue->get_total();
|
||||
}
|
||||
if (wed->not_working()) {
|
||||
t += wtemplate->wed->get_total();
|
||||
} else {
|
||||
t += wed->get_total();
|
||||
}
|
||||
if (thu->not_working()) {
|
||||
t += wtemplate->thu->get_total();
|
||||
} else {
|
||||
t += thu->get_total();
|
||||
}
|
||||
if (fri->not_working()) {
|
||||
t += wtemplate->fri->get_total();
|
||||
} else {
|
||||
t += fri->get_total();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
Day* Week::getMon() {
|
||||
return mon;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
Week(Week*);
|
||||
~Week();
|
||||
double total();
|
||||
double total(Week *wtemplate);
|
||||
|
||||
void setMon(Day*);
|
||||
void setTue(Day*);
|
||||
|
||||
@@ -22,6 +22,8 @@ SetDayDialog::~SetDayDialog()
|
||||
void SetDayDialog::init() {
|
||||
ui->start_edit->setTime(copy->get_start());
|
||||
ui->end_edit->setTime(copy->get_end());
|
||||
ui->notWorkingCheckbox->setCheckState((copy->not_working()) ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
|
||||
lockControls(copy->not_working());
|
||||
updateBreakList();
|
||||
connect(ui->start_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
connect(ui->end_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
@@ -30,6 +32,7 @@ void SetDayDialog::init() {
|
||||
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);
|
||||
connect(ui->notWorkingCheckbox, &QCheckBox::stateChanged, this, &SetDayDialog::change_not_working);
|
||||
ui->total_label->setText(Tools::double_to_string_time(d->get_total()));
|
||||
}
|
||||
|
||||
@@ -41,6 +44,17 @@ void SetDayDialog::updateBreakList()
|
||||
}
|
||||
}
|
||||
|
||||
void SetDayDialog::lockControls(bool lock)
|
||||
{
|
||||
ui->addBreakButton->setDisabled(lock);
|
||||
ui->start_edit->setDisabled(lock);
|
||||
ui->end_edit->setDisabled(lock);
|
||||
ui->breakList->setDisabled(lock);
|
||||
if (ui->breakList->currentRow() != -1) {
|
||||
ui->removeBreakButton->setDisabled(lock);
|
||||
}
|
||||
}
|
||||
|
||||
void SetDayDialog::compute_time() {
|
||||
copy->set_validate(false);
|
||||
copy->set_start(ui->start_edit->time());
|
||||
@@ -91,3 +105,10 @@ void SetDayDialog::break_selected(int i)
|
||||
{
|
||||
ui->removeBreakButton->setEnabled(i > -1);
|
||||
}
|
||||
|
||||
void SetDayDialog::change_not_working(int state)
|
||||
{
|
||||
copy->set_not_working(state != 0);
|
||||
lockControls(copy->not_working());
|
||||
compute_time();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ private slots:
|
||||
void add_break_point();
|
||||
void remove_break_point();
|
||||
void break_selected(int);
|
||||
void change_not_working(int);
|
||||
|
||||
private:
|
||||
Ui::SetDayDialog *ui;
|
||||
@@ -37,6 +38,7 @@ private:
|
||||
|
||||
void init();
|
||||
void updateBreakList();
|
||||
void lockControls(bool);
|
||||
};
|
||||
|
||||
#endif // SETDAYDIALOG_H
|
||||
|
||||
Reference in New Issue
Block a user