Call to save updater, confirm final input of a day

This commit is contained in:
Alexis Delhaie
2020-09-24 10:53:33 +02:00
parent 257bc67f61
commit 4308d9e93a
15 changed files with 404 additions and 48 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.12.4, 2020-08-28T14:45:30. -->
<!-- Written by QtCreator 4.12.4, 2020-09-24T10:51:57. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@@ -77,7 +77,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.15.0 MSVC2019 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.15.0 MSVC2019 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5150.win64_msvc2019_64_kit</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
@@ -320,7 +320,7 @@
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Release</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Debug</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>

BIN
icon.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 125 KiB

View File

@@ -5,5 +5,6 @@
<file>pictures/calendar.png</file>
<file>pictures/about.png</file>
<file>pictures/banner.png</file>
<file>pictures/validate.png</file>
</qresource>
</RCC>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 50 KiB

BIN
pictures/validate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -28,6 +28,10 @@ void Day::set_time_break(double value)
time_break = value;
}
void Day::set_validate(bool value) {
validate = value;
}
QTime Day::get_start()
{
return start;
@@ -48,7 +52,8 @@ QJsonObject Day::to_json()
QJsonObject obj{
{KEY_START, start.toString(Qt::DateFormat::ISODate)},
{KEY_END, end.toString(Qt::DateFormat::ISODate)},
{KEY_BREAK, time_break}
{KEY_BREAK, time_break},
{KEY_VALIDATE, validate}
};
return obj;
@@ -61,6 +66,11 @@ 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.time_break = obj[KEY_BREAK].toDouble();
result.validate = obj[KEY_VALIDATE].toBool();
return result;
}
bool Day::get_validate() {
return validate;
}

View File

@@ -4,6 +4,7 @@
#define KEY_START "start"
#define KEY_END "end"
#define KEY_BREAK "break"
#define KEY_VALIDATE "validate"
#include <QTime>
#include <QJsonObject>
@@ -16,6 +17,7 @@ private:
QTime start;
QTime end;
double time_break;
bool validate;
public:
Day();
@@ -23,10 +25,12 @@ public:
void set_start(QTime value);
void set_end(QTime value);
void set_time_break(double value);
void set_validate(bool);
QTime get_start();
QTime get_end();
double get_time_break();
bool get_validate();
QJsonObject to_json();
double get_total();

View File

@@ -67,8 +67,9 @@ void MainWindow::init() {
connect(ui->wed_button, &QPushButton::clicked, this, &MainWindow::edit);
connect(ui->thu_button, &QPushButton::clicked, this, &MainWindow::edit);
connect(ui->fri_button, &QPushButton::clicked, this, &MainWindow::edit);
highlightDayOfWeek();
todayWeekNumber = QDate::currentDate().weekNumber();
dayOfWeek = QDate::currentDate().dayOfWeek();
saveLoaded = false;
if (QFile::exists(get_save_file_path())) {
open_save();
@@ -77,12 +78,19 @@ void MainWindow::init() {
w.exec();
week_template = w.get_result();
}
if (saveLoaded) {
set_date_to_now();
compute_time();
}
}
void MainWindow::highlightDayOfWeek() {
int dayOfWeek = QDate::currentDate().dayOfWeek();
ui->monLabel->setText("Lundi");
ui->tueLabel->setText("Mardi");
ui->wedLabel->setText("Mercredi");
ui->thuLabel->setText("Jeudi");
ui->friLabel->setText("Friday");
if (todayWeekNumber == current_week.getWeekNumber()) {
switch (dayOfWeek) {
case 1: {
ui->monLabel->setText(QString("> %1 <").arg(ui->monLabel->text()));
@@ -107,6 +115,7 @@ void MainWindow::highlightDayOfWeek() {
default: break;
}
}
}
void MainWindow::set_date_to_now() {
auto date = QDate::currentDate();
@@ -127,16 +136,28 @@ void MainWindow::open_save() {
for (QJsonValue val : arr) {
weeks[val.toObject()["weekNumber"].toInt()] = Week::from_json(val.toObject());
}
saveLoaded = true;
} else if (obj[KEY_SAVE_FILE_VERSION].toInt() < SAVE_FILE_VERSION) {
QString updater = QCoreApplication::applicationDirPath() + "/save-updater.exe";
if (QFile::exists(updater)) {
QProcess* process = new QProcess(this);
process->execute(updater, QStringList({"update"}));
delete process;
open_save();
} else {
QMessageBox msgBox;
msgBox.setText("Le fichier de sauvegarde n'est pas à jour, "
"des changements ont été apporté a la structure du fichier lors de la dernière mise à jour");
msgBox.setInformativeText("Mettez à jour votre fichier de sauvegarde puis relancez l'application");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
QTimer::singleShot(0, this, &MainWindow::close);
panic_dialog("Cette application n'a pas pu démarrer car save-updater.exe est introuvable.\n"
"La réinstallation de cette application peut corriger ce problème");
}
} else {
panic_dialog("Votre fichier de sauvegarde a été enregistré depuis une version plus récente de Chronos\n"
"Mettez à jour Chronos pour pouvoir utiliser ce fichier");
}
}
void MainWindow::panic_dialog(QString text) {
QMessageBox::critical(this, tr("Chronos"), text,
QMessageBox::Ok, QMessageBox::Ok);
QTimer::singleShot(0, this, &MainWindow::close);
}
void MainWindow::save_to_file() {
@@ -178,6 +199,7 @@ void MainWindow::compute_week_number(const QDateTime &dt) {
save_to_file();
}
compute_time();
highlightDayOfWeek();
}
void MainWindow::compute_time() {
@@ -190,6 +212,7 @@ void MainWindow::compute_time() {
updateStartLabel();
updateBreakLabel();
updateEndLabel();
updateValidIcon();
double late = 0.0;
double overtime = 0.0;
@@ -205,6 +228,14 @@ 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::updateStartLabel() {
ui->monStartLabel->setText(current_week.getMon().get_start().toString("HH:mm"));
ui->tueStartLabel->setText(current_week.getTue().get_start().toString("HH:mm"));
@@ -254,7 +285,8 @@ void MainWindow::edit() {
}
Day MainWindow::modify_value(Day d) {
SetDayDialog sdd(d, this);
bool isNotValidable = (current_week.getWeekNumber() > todayWeekNumber);
SetDayDialog sdd(d, isNotValidable, this);
int result = sdd.exec();
if (result == QDialog::Accepted) {
return sdd.get_result();

View File

@@ -4,7 +4,7 @@
#define KEY_TEMPLATE "template"
#define KEY_WEEKS "weeks"
#define SAVE_FILENAME "data.json"
#define SAVE_FILE_VERSION 1
#define SAVE_FILE_VERSION 2
#define KEY_SAVE_FILE_VERSION "version"
#include <QMouseEvent>
@@ -19,6 +19,8 @@
#include <QMapIterator>
#include <QMessageBox>
#include <QTimer>
#include <QProcess>
#include <QDir>
#include "week.h"
#include "welcome.h"
@@ -45,12 +47,14 @@ private:
void init();
void open_save();
void save_to_file();
void panic_dialog(QString text);
// UI Update
void updateStartLabel();
void updateBreakLabel();
void updateEndLabel();
void highlightDayOfWeek();
void updateValidIcon();
QString get_save_file_path();
Identifier get_identifier(QString objectName);
@@ -60,6 +64,9 @@ private:
Week current_week;
QMap<int, Week> weeks;
QMap<QString, Identifier> objectId;
int todayWeekNumber;
int dayOfWeek;
bool saveLoaded;
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);

View File

@@ -1,11 +1,12 @@
#include "setdaydialog.h"
#include "ui_setdaydialog.h"
SetDayDialog::SetDayDialog(Day d, QWidget *parent) :
SetDayDialog::SetDayDialog(Day d, bool isNotValidable, QWidget *parent) :
QDialog(parent),
ui(new Ui::SetDayDialog)
{
ui->setupUi(this);
ui->validateButton->setEnabled(!isNotValidable);
this->d = d;
init();
}
@@ -21,6 +22,7 @@ void SetDayDialog::init() {
ui->break_edit->setValue(d.get_time_break());
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->break_edit, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &SetDayDialog::compute_time);
ui->total_label->setText(Tools::double_to_string_time(d.get_total()));
}
@@ -35,3 +37,8 @@ void SetDayDialog::compute_time() {
Day SetDayDialog::get_result() {
return d;
}
void SetDayDialog::validate() {
d.set_validate(true);
accept();
}

View File

@@ -15,13 +15,14 @@ class SetDayDialog : public QDialog
Q_OBJECT
public:
explicit SetDayDialog(Day d, QWidget *parent = nullptr);
explicit SetDayDialog(Day d, bool isNotValidable, QWidget *parent = nullptr);
~SetDayDialog();
Day get_result();
public slots:
void compute_time();
void validate();
private:
Ui::SetDayDialog *ui;

View File

@@ -65,7 +65,7 @@ void Welcome::edit() {
}
Day Welcome::modify_value(Day d) {
SetDayDialog sdd(d, this);
SetDayDialog sdd(d, true, this);
int result = sdd.exec();
if (result == QDialog::Accepted) {
return sdd.get_result();

View File

@@ -91,7 +91,7 @@
<string notr="true">font-size: 12px;</string>
</property>
<property name="text">
<string>Version: 1.0.0 (Beta 4)</string>
<string>Version: 1.0.0 (Beta 5)</string>
</property>
</widget>
<widget class="QLabel" name="label_3">

View File

@@ -394,6 +394,61 @@ color: white;</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_21">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="mondayValidate">
<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/validate.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>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_8">
<property name="orientation">
@@ -592,6 +647,61 @@ color: white;</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_22">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="tuesdayValidate">
<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/validate.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>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_19">
<property name="orientation">
@@ -790,6 +900,61 @@ color: white;</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_23">
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="wednesdayValidate">
<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/validate.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>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_20">
<property name="orientation">
@@ -988,6 +1153,61 @@ color: white;</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_24">
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="thurdayValidate">
<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/validate.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>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_21">
<property name="orientation">
@@ -1186,6 +1406,61 @@ color: white;</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="fridayValidate">
<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/validate.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>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_22">
<property name="orientation">

View File

@@ -34,14 +34,17 @@
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>320</x>
<y>140</y>
<width>75</width>
<x>214</x>
<y>110</y>
<width>181</width>
<height>23</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size: 12px</string>
</property>
<property name="text">
<string>Valider</string>
<string>Enregistrer la modification</string>
</property>
</widget>
<widget class="QTimeEdit" name="start_edit">
@@ -219,6 +222,22 @@ color: white;</string>
</item>
</layout>
</widget>
<widget class="QPushButton" name="validateButton">
<property name="geometry">
<rect>
<x>214</x>
<y>140</y>
<width>181</width>
<height>23</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font-size: 12px</string>
</property>
<property name="text">
<string>Définir l'horaire comme valide</string>
</property>
</widget>
</widget>
<resources/>
<connections>