Add support of leaves

This commit is contained in:
Aurélie Delhaie
2022-10-16 17:36:47 +02:00
parent 6a44c4afd9
commit fd4b766c4d
14 changed files with 219 additions and 77 deletions

View File

@@ -1,11 +1,9 @@
<RCC> <RCC>
<qresource prefix="/clock"> <qresource prefix="/clock">
<file>pictures/clock-8-128.png</file>
<file>pictures/sport.png</file>
<file>pictures/calendar.png</file>
<file>pictures/about.png</file> <file>pictures/about.png</file>
<file>pictures/banner.png</file> <file>pictures/banner.png</file>
<file>pictures/validate.png</file> <file>pictures/validate.png</file>
<file>pictures/warning.png</file> <file>pictures/warning.png</file>
<file>pictures/leave.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

BIN
pictures/leave.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -185,12 +185,8 @@ void MainWindow::compute_time() {
ui->thu_time_label->setText(Tools::double_to_string_time(current_week->getThu()->get_total())); 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->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())); ui->total_time_label->setText(Tools::double_to_string_time(current_week->total()));
updateStartLabel(); updateLabels();
updateBreakLabel();
updateEndLabel();
updateWeekTime(); updateWeekTime();
updateValidIcon();
updateWarningIcon();
double late = 0.0; double late = 0.0;
double overtime = 0.0; double overtime = 0.0;
@@ -199,8 +195,8 @@ void MainWindow::compute_time() {
while (i.hasNext()) { while (i.hasNext()) {
Week *w = i.next().value(); Week *w = i.next().value();
if (w->getWeekNumber() <= todayWeekNumber) { if (w->getWeekNumber() <= todayWeekNumber) {
late += (week_template->total() - w->total()) - w->getTimeDeltaInHours(); late += (week_template->total() - w->total(week_template)) - w->getTimeDeltaInHours();
overtime += (w->total() - week_template->total()) + w->getTimeDeltaInHours(); overtime += (w->total() - week_template->total(week_template)) + w->getTimeDeltaInHours();
} }
} }
late -= current_week->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)); 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() 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) { if (t > 0) {
ui->overtime_time_label_week->setText(Tools::double_to_string_time(t)); ui->overtime_time_label_week->setText(Tools::double_to_string_time(t));
ui->late_time_label_week->setText("0h"); ui->late_time_label_week->setText("0h");
@@ -240,28 +220,30 @@ void MainWindow::updateWeekTime()
} }
} }
void MainWindow::updateStartLabel() { void MainWindow::updateLabels() {
ui->monStartLabel->setText(current_week->getMon()->get_start().toString("HH:mm")); updateDayLabels(ui->monStartLabel, ui->monEndLabel, ui->monBreakLabel, ui->mondayValidate, ui->mondayWarning, ui->mondayNotWorking, current_week->getMon());
ui->tueStartLabel->setText(current_week->getTue()->get_start().toString("HH:mm")); updateDayLabels(ui->tueStartLabel, ui->tueEndLabel, ui->tueBreakLabel, ui->tuesdayValidate, ui->tuesdayWarning, ui->tuesdayNotWorking, current_week->getTue());
ui->wedStartLabel->setText(current_week->getWed()->get_start().toString("HH:mm")); updateDayLabels(ui->wedStartLabel, ui->wedEndLabel, ui->wedBreakLabel, ui->wednesdayValidate, ui->wednesdayWarning, ui->wednesdayNotWorking, current_week->getWed());
ui->thuStartLabel->setText(current_week->getThu()->get_start().toString("HH:mm")); updateDayLabels(ui->thuStartLabel, ui->thuEndLabel, ui->thuBreakLabel, ui->thurdayValidate, ui->thurdayWarning, ui->thurdayNotWorking, current_week->getThu());
ui->friStartLabel->setText(current_week->getFri()->get_start().toString("HH:mm")); updateDayLabels(ui->friStartLabel, ui->friEndLabel, ui->friBreakLabel, ui->fridayValidate, ui->fridayWarning, ui->fridayNotWorking, current_week->getFri());
} }
void MainWindow::updateBreakLabel() { void MainWindow::updateDayLabels(QLabel *start, QLabel *end, QLabel *breaks, QFrame *validate, QFrame *warning, QFrame *not_working, Day *d)
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())); not_working->setVisible(d->not_working());
ui->wedBreakLabel->setText(QString("%1 min.").arg(current_week->getWed()->get_time_break())); if (!d->not_working()) {
ui->thuBreakLabel->setText(QString("%1 min.").arg(current_week->getThu()->get_time_break())); start->setText(d->get_start().toString("HH:mm"));
ui->friBreakLabel->setText(QString("%1 min.").arg(current_week->getFri()->get_time_break())); end->setText(d->get_end().toString("HH:mm"));
} breaks->setText(QString("%1 min.").arg(d->get_time_break()));
validate->setVisible(d->get_validate());
void MainWindow::updateEndLabel() { warning->setVisible(d->has_warning());
ui->monEndLabel->setText(current_week->getMon()->get_end().toString("HH:mm")); } else {
ui->tueEndLabel->setText(current_week->getTue()->get_end().toString("HH:mm")); start->setText("--:--");
ui->wedEndLabel->setText(current_week->getWed()->get_end().toString("HH:mm")); end->setText("--:--");
ui->thuEndLabel->setText(current_week->getThu()->get_end().toString("HH:mm")); breaks->setText("0 min.");
ui->friEndLabel->setText(current_week->getFri()->get_end().toString("HH:mm")); validate->setVisible(false);
warning->setVisible(false);
}
} }
void MainWindow::edit() { void MainWindow::edit() {

View File

@@ -4,7 +4,7 @@
#define KEY_TEMPLATE "template" #define KEY_TEMPLATE "template"
#define KEY_YEARS "years" #define KEY_YEARS "years"
#define SAVE_FILENAME "data.json" #define SAVE_FILENAME "data.json"
#define SAVE_FILE_VERSION 3 #define SAVE_FILE_VERSION 4
#define KEY_SAVE_FILE_VERSION "version" #define KEY_SAVE_FILE_VERSION "version"
#include <QMouseEvent> #include <QMouseEvent>
@@ -25,7 +25,6 @@
#include "models/week.h" #include "models/week.h"
#include "models/year.h" #include "models/year.h"
#include "welcome.h" #include "welcome.h"
#include "tools.h"
#include "aboutbox.h" #include "aboutbox.h"
#include "weekoption.h" #include "weekoption.h"
@@ -52,13 +51,10 @@ private:
void panic_dialog(QString text); void panic_dialog(QString text);
// UI Update // UI Update
void updateStartLabel(); void updateLabels();
void updateBreakLabel();
void updateEndLabel();
void highlightDayOfWeek(); void highlightDayOfWeek();
void updateValidIcon();
void updateWarningIcon();
void updateWeekTime(); void updateWeekTime();
void updateDayLabels(QLabel *start, QLabel *end, QLabel *breaks, QFrame *validate, QFrame *warning, QFrame *not_working, Day *d);
QString get_save_file_path(); QString get_save_file_path();
Identifier get_identifier(QString objectName); Identifier get_identifier(QString objectName);

View File

@@ -7,6 +7,7 @@ Day::Day()
BreakPoint *lunch = new BreakPoint(QTime(12, 0, 0, 0), QTime(12, 45, 0, 0)); BreakPoint *lunch = new BreakPoint(QTime(12, 0, 0, 0), QTime(12, 45, 0, 0));
breaks.append(lunch); breaks.append(lunch);
validate = false; validate = false;
notWorking = false;
} }
Day::Day(Day *old) 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)); BreakPoint *lunch = new BreakPoint(QTime(12, 0, 0, 0), QTime(12, 45, 0, 0));
breaks.append(lunch); breaks.append(lunch);
validate = false; validate = false;
notWorking = false;
update(old); update(old);
} }
@@ -51,7 +53,7 @@ void Day::set_validate(bool value) {
validate = value; validate = value;
} }
void Day::set_working(bool value) void Day::set_not_working(bool value)
{ {
this->notWorking = value; this->notWorking = value;
} }
@@ -86,7 +88,8 @@ QJsonObject Day::to_json()
{KEY_START, start.toString(Qt::DateFormat::ISODate)}, {KEY_START, start.toString(Qt::DateFormat::ISODate)},
{KEY_END, end.toString(Qt::DateFormat::ISODate)}, {KEY_END, end.toString(Qt::DateFormat::ISODate)},
{KEY_BREAKS, arr}, {KEY_BREAKS, arr},
{KEY_VALIDATE, validate} {KEY_VALIDATE, validate},
{KEY_NOT_WORKING, notWorking}
}; };
return obj; return obj;
@@ -112,7 +115,8 @@ Day* Day::from_json(QJsonObject obj)
result->start = QTime::fromString(obj[KEY_START].toString(), Qt::DateFormat::ISODate); result->start = QTime::fromString(obj[KEY_START].toString(), Qt::DateFormat::ISODate);
result->end = QTime::fromString(obj[KEY_END].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(); result->breaks.clear();
QJsonArray arr = obj[KEY_BREAKS].toArray(); QJsonArray arr = obj[KEY_BREAKS].toArray();

View File

@@ -5,6 +5,7 @@
#define KEY_END "end" #define KEY_END "end"
#define KEY_BREAKS "breaks" #define KEY_BREAKS "breaks"
#define KEY_VALIDATE "validate" #define KEY_VALIDATE "validate"
#define KEY_NOT_WORKING "not_working"
#include <QTime> #include <QTime>
#include <QJsonObject> #include <QJsonObject>
@@ -31,7 +32,7 @@ public:
void set_start(QTime value); void set_start(QTime value);
void set_end(QTime value); void set_end(QTime value);
void set_validate(bool); void set_validate(bool);
void set_working(bool); void set_not_working(bool);
void setBreaks(QVector<BreakPoint*>); void setBreaks(QVector<BreakPoint*>);
QTime get_start(); QTime get_start();

View File

@@ -61,6 +61,37 @@ double Week::total() {
return mon->get_total() + tue->get_total() + wed->get_total() + thu->get_total() + fri->get_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() { Day* Week::getMon() {
return mon; return mon;
} }

View File

@@ -19,6 +19,7 @@ public:
Week(Week*); Week(Week*);
~Week(); ~Week();
double total(); double total();
double total(Week *wtemplate);
void setMon(Day*); void setMon(Day*);
void setTue(Day*); void setTue(Day*);

View File

@@ -22,6 +22,8 @@ SetDayDialog::~SetDayDialog()
void SetDayDialog::init() { void SetDayDialog::init() {
ui->start_edit->setTime(copy->get_start()); ui->start_edit->setTime(copy->get_start());
ui->end_edit->setTime(copy->get_end()); ui->end_edit->setTime(copy->get_end());
ui->notWorkingCheckbox->setCheckState((copy->not_working()) ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
lockControls(copy->not_working());
updateBreakList(); updateBreakList();
connect(ui->start_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time); connect(ui->start_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
connect(ui->end_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->addBreakButton, &QPushButton::clicked, this, &SetDayDialog::add_break_point);
connect(ui->removeBreakButton, &QPushButton::clicked, this, &SetDayDialog::remove_break_point); connect(ui->removeBreakButton, &QPushButton::clicked, this, &SetDayDialog::remove_break_point);
connect(ui->breakList, &QListWidget::currentRowChanged, this, &SetDayDialog::break_selected); 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())); 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() { void SetDayDialog::compute_time() {
copy->set_validate(false); copy->set_validate(false);
copy->set_start(ui->start_edit->time()); copy->set_start(ui->start_edit->time());
@@ -91,3 +105,10 @@ void SetDayDialog::break_selected(int i)
{ {
ui->removeBreakButton->setEnabled(i > -1); ui->removeBreakButton->setEnabled(i > -1);
} }
void SetDayDialog::change_not_working(int state)
{
copy->set_not_working(state != 0);
lockControls(copy->not_working());
compute_time();
}

View File

@@ -28,6 +28,7 @@ private slots:
void add_break_point(); void add_break_point();
void remove_break_point(); void remove_break_point();
void break_selected(int); void break_selected(int);
void change_not_working(int);
private: private:
Ui::SetDayDialog *ui; Ui::SetDayDialog *ui;
@@ -37,6 +38,7 @@ private:
void init(); void init();
void updateBreakList(); void updateBreakList();
void lockControls(bool);
}; };
#endif // SETDAYDIALOG_H #endif // SETDAYDIALOG_H

View File

@@ -193,6 +193,31 @@ font-size: 22px;</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QFrame" name="mondayNotWorking">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch;</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@@ -266,6 +291,31 @@ font-size: 22px;</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QFrame" name="tuesdayNotWorking">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch;</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@@ -339,6 +389,31 @@ font-size: 22px;</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QFrame" name="wednesdayNotWorking">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch;</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@@ -412,6 +487,31 @@ font-size: 22px;</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QFrame" name="thurdayNotWorking">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch;</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@@ -485,6 +585,31 @@ font-size: 22px;</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QFrame" name="fridayNotWorking">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">border-image: url(:/clock/pictures/leave.png) 0 0 0 0 stretch stretch;</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@@ -1774,25 +1899,6 @@ font-weight: bold;</string>
<zorder>label_semaine</zorder> <zorder>label_semaine</zorder>
<zorder>today_button</zorder> <zorder>today_button</zorder>
<zorder>dateEdit</zorder> <zorder>dateEdit</zorder>
<zorder>tuesdayWarning</zorder>
<zorder>tueBreakLabel</zorder>
<zorder>horizontalSpacer_6</zorder>
<zorder>horizontalSpacer_7</zorder>
<zorder>mondayWarning</zorder>
<zorder>horizontalSpacer_8</zorder>
<zorder>horizontalSpacer_9</zorder>
<zorder>wednesdayWarning</zorder>
<zorder>wedBreakLabel</zorder>
<zorder>horizontalSpacer_10</zorder>
<zorder>horizontalSpacer_11</zorder>
<zorder>thurdayWarning</zorder>
<zorder>horizontalSpacer_12</zorder>
<zorder>horizontalSpacer_13</zorder>
<zorder>thuBreakLabel</zorder>
<zorder>fridayWarning</zorder>
<zorder>horizontalSpacer_14</zorder>
<zorder>horizontalSpacer_15</zorder>
<zorder>friBreakLabel</zorder>
</widget> </widget>
</widget> </widget>
<resources/> <resources/>