beta 2
This commit is contained in:
14
sources/aboutbox.cpp
Normal file
14
sources/aboutbox.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "aboutbox.h"
|
||||
#include "ui_aboutbox.h"
|
||||
|
||||
AboutBox::AboutBox(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::AboutBox)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
AboutBox::~AboutBox()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
23
sources/aboutbox.h
Normal file
23
sources/aboutbox.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef ABOUTBOX_H
|
||||
#define ABOUTBOX_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <iostream>
|
||||
|
||||
namespace Ui {
|
||||
class AboutBox;
|
||||
}
|
||||
|
||||
class AboutBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AboutBox(QWidget *parent = nullptr);
|
||||
~AboutBox();
|
||||
|
||||
private:
|
||||
Ui::AboutBox *ui;
|
||||
};
|
||||
|
||||
#endif // ABOUTBOX_H
|
||||
66
sources/day.cpp
Normal file
66
sources/day.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "day.h"
|
||||
|
||||
Day::Day()
|
||||
{
|
||||
start = QTime(9, 0, 0, 0);
|
||||
end = QTime(17, 15, 0, 0);
|
||||
time_break = 45.0;
|
||||
}
|
||||
|
||||
double Day::get_total() {
|
||||
int sec = start.secsTo(end);
|
||||
int minutes = sec / 60;
|
||||
return (minutes - time_break) / 60;
|
||||
}
|
||||
|
||||
void Day::set_start(QTime value)
|
||||
{
|
||||
start = value;
|
||||
}
|
||||
|
||||
void Day::set_end(QTime value)
|
||||
{
|
||||
end = value;
|
||||
}
|
||||
|
||||
void Day::set_time_break(double value)
|
||||
{
|
||||
time_break = value;
|
||||
}
|
||||
|
||||
QTime Day::get_start()
|
||||
{
|
||||
return start;
|
||||
}
|
||||
|
||||
QTime Day::get_end()
|
||||
{
|
||||
return end;
|
||||
}
|
||||
|
||||
double Day::get_time_break()
|
||||
{
|
||||
return time_break;
|
||||
}
|
||||
|
||||
QJsonObject Day::to_json()
|
||||
{
|
||||
QJsonObject obj{
|
||||
{KEY_START, start.toString(Qt::DateFormat::ISODate)},
|
||||
{KEY_END, end.toString(Qt::DateFormat::ISODate)},
|
||||
{KEY_BREAK, time_break}
|
||||
};
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
Day Day::from_json(QJsonObject obj)
|
||||
{
|
||||
Day result;
|
||||
|
||||
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();
|
||||
|
||||
return result;
|
||||
}
|
||||
37
sources/day.h
Normal file
37
sources/day.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef DAY_H
|
||||
#define DAY_H
|
||||
|
||||
#define KEY_START "start"
|
||||
#define KEY_END "end"
|
||||
#define KEY_BREAK "break"
|
||||
|
||||
#include <QTime>
|
||||
#include <QJsonObject>
|
||||
#include <math.h>
|
||||
|
||||
class Day
|
||||
{
|
||||
|
||||
private:
|
||||
QTime start;
|
||||
QTime end;
|
||||
double time_break;
|
||||
|
||||
public:
|
||||
Day();
|
||||
|
||||
void set_start(QTime value);
|
||||
void set_end(QTime value);
|
||||
void set_time_break(double value);
|
||||
|
||||
QTime get_start();
|
||||
QTime get_end();
|
||||
double get_time_break();
|
||||
QJsonObject to_json();
|
||||
|
||||
double get_total();
|
||||
|
||||
static Day from_json(QJsonObject);
|
||||
};
|
||||
|
||||
#endif // DAY_H
|
||||
17
sources/main.cpp
Normal file
17
sources/main.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
QFile styleFile(":/stylesheets/stylesheets/style.qss");
|
||||
styleFile.open(QFile::ReadOnly);
|
||||
QString style(styleFile.readAll());
|
||||
a.setStyleSheet(style);
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
199
sources/mainwindow.cpp
Normal file
199
sources/mainwindow.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
init();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString MainWindow::get_save_file_path() {
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
if (!QDir(path).exists()) {
|
||||
QDir().mkpath(path);
|
||||
}
|
||||
path += "/data/";
|
||||
if (!QDir(path).exists()) {
|
||||
QDir().mkpath(path);
|
||||
}
|
||||
path += SAVE_FILENAME;
|
||||
return path;
|
||||
}
|
||||
|
||||
void MainWindow::init() {
|
||||
objectId.insert(ui->mon_button->objectName(), Identifier::mon);
|
||||
objectId.insert(ui->tue_button->objectName(), Identifier::tue);
|
||||
objectId.insert(ui->wed_button->objectName(), Identifier::wed);
|
||||
objectId.insert(ui->thu_button->objectName(), Identifier::thu);
|
||||
objectId.insert(ui->fri_button->objectName(), Identifier::fri);
|
||||
connect(ui->aboutButton, &QPushButton::clicked, this, &MainWindow::open_about);
|
||||
connect(ui->template_settings_button, &QPushButton::clicked, this, &MainWindow::edit_template);
|
||||
connect(ui->dateEdit, &QDateEdit::dateTimeChanged, this, &MainWindow::compute_week_number);
|
||||
connect(ui->mon_button, &QPushButton::clicked, this, &MainWindow::edit);
|
||||
connect(ui->tue_button, &QPushButton::clicked, this, &MainWindow::edit);
|
||||
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);
|
||||
if (QFile::exists(get_save_file_path())) {
|
||||
open_save();
|
||||
} else {
|
||||
Welcome w(week_template);
|
||||
w.exec();
|
||||
week_template = w.get_result();
|
||||
}
|
||||
set_date_to_now();
|
||||
compute_time();
|
||||
}
|
||||
|
||||
void MainWindow::set_date_to_now() {
|
||||
auto date = QDate::currentDate();
|
||||
ui->dateEdit->setDate(date);
|
||||
}
|
||||
|
||||
void MainWindow::open_save() {
|
||||
QFile* file = new QFile(get_save_file_path());
|
||||
file->open(QIODevice::ReadOnly);
|
||||
auto json = QString(file->readAll());
|
||||
file->close();
|
||||
delete file;
|
||||
|
||||
QJsonObject obj = QJsonDocument::fromJson(json.toUtf8()).object();
|
||||
if (obj[KEY_SAVE_FILE_VERSION].toInt() == SAVE_FILE_VERSION) {
|
||||
week_template = Week::from_json(obj[KEY_TEMPLATE].toObject());
|
||||
QJsonArray arr = obj[KEY_WEEKS].toArray();
|
||||
for (QJsonValue val : arr) {
|
||||
weeks[val.toObject()["weekNumber"].toInt()] = Week::from_json(val.toObject());
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::save_to_file() {
|
||||
QJsonArray arr;
|
||||
for (Week w : weeks) {
|
||||
arr.append(w.to_json());
|
||||
}
|
||||
QJsonObject obj {
|
||||
{KEY_TEMPLATE, week_template.to_json()},
|
||||
{KEY_WEEKS, arr},
|
||||
{KEY_SAVE_FILE_VERSION, SAVE_FILE_VERSION}
|
||||
};
|
||||
QJsonDocument doc(obj);
|
||||
QFile *f = new QFile(get_save_file_path());
|
||||
if (f->open(QIODevice::WriteOnly)) {
|
||||
f->write(doc.toJson());
|
||||
f->close();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::compute_week_number(const QDateTime &dt) {
|
||||
int n = dt.date().weekNumber();
|
||||
ui->label_semaine->setText(QString("Semaine : %1").arg(QString::number(n)));
|
||||
QMapIterator<int, Week> it(weeks);
|
||||
bool working = true;
|
||||
bool found = false;
|
||||
while (it.hasNext() && working) {
|
||||
Week w = it.next().value();
|
||||
if (w.getWeekNumber() == n) {
|
||||
current_week = w;
|
||||
working = false;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
current_week = Week(week_template);
|
||||
current_week.setWeekNumber(n);
|
||||
weeks.insert(n, current_week);
|
||||
save_to_file();
|
||||
}
|
||||
compute_time();
|
||||
}
|
||||
|
||||
void MainWindow::compute_time() {
|
||||
ui->mon_time_label->setText(Tools::double_to_string_time(current_week.getMon().get_total()));
|
||||
ui->tue_time_label->setText(Tools::double_to_string_time(current_week.getTue().get_total()));
|
||||
ui->wed_time_label->setText(Tools::double_to_string_time(current_week.getWed().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->total_time_label->setText(Tools::double_to_string_time(current_week.total()));
|
||||
|
||||
double late = 0.0;
|
||||
double overtime = 0.0;
|
||||
int todayWeekNumber = QDate::currentDate().weekNumber();
|
||||
for (Week w : weeks) {
|
||||
if (w.getWeekNumber() <= todayWeekNumber) {
|
||||
late += (week_template.total() - w.total());
|
||||
overtime += (w.total() - week_template.total());
|
||||
}
|
||||
}
|
||||
|
||||
ui->late_time_label->setText(Tools::double_to_string_time((late > 0.0) ? late : 0.0));
|
||||
ui->overtime_time_label->setText(Tools::double_to_string_time((overtime > 0.0) ? overtime : 0.0));
|
||||
}
|
||||
|
||||
void MainWindow::edit() {
|
||||
QString name = QObject::sender()->objectName();
|
||||
switch (get_identifier(name)) {
|
||||
case mon:
|
||||
current_week.setMon(modify_value(current_week.getMon()));
|
||||
break;
|
||||
case tue:
|
||||
current_week.setTue(modify_value(current_week.getTue()));
|
||||
break;
|
||||
case wed:
|
||||
current_week.setWed(modify_value(current_week.getWed()));
|
||||
break;
|
||||
case thu:
|
||||
current_week.setThu(modify_value(current_week.getThu()));
|
||||
break;
|
||||
case fri:
|
||||
current_week.setFri(modify_value(current_week.getFri()));
|
||||
break;
|
||||
}
|
||||
weeks[current_week.getWeekNumber()] = current_week;
|
||||
save_to_file();
|
||||
compute_time();
|
||||
}
|
||||
|
||||
Day MainWindow::modify_value(Day d) {
|
||||
SetDayDialog sdd(d, this);
|
||||
int result = sdd.exec();
|
||||
if (result == QDialog::Accepted) {
|
||||
return sdd.get_result();
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
Identifier MainWindow::get_identifier(QString objectName) {
|
||||
return objectId[objectName];
|
||||
}
|
||||
|
||||
void MainWindow::edit_template() {
|
||||
Welcome w(week_template);
|
||||
int res = w.exec();
|
||||
if (res == QDialog::Accepted) {
|
||||
week_template = w.get_result();
|
||||
save_to_file();
|
||||
compute_time();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::open_about() {
|
||||
AboutBox a(this);
|
||||
a.exec();
|
||||
}
|
||||
63
sources/mainwindow.h
Normal file
63
sources/mainwindow.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#define KEY_TEMPLATE "template"
|
||||
#define KEY_WEEKS "weeks"
|
||||
#define SAVE_FILENAME "data.json"
|
||||
#define SAVE_FILE_VERSION 1
|
||||
#define KEY_SAVE_FILE_VERSION "version"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QMainWindow>
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QMap>
|
||||
#include <QMapIterator>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
#include "week.h"
|
||||
#include "welcome.h"
|
||||
#include "tools.h"
|
||||
#include "aboutbox.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
signals:
|
||||
void correctly_started();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
void init();
|
||||
void open_save();
|
||||
void save_to_file();
|
||||
QString get_save_file_path();
|
||||
Identifier get_identifier(QString objectName);
|
||||
Day modify_value(Day);
|
||||
|
||||
Week week_template;
|
||||
Week current_week;
|
||||
QMap<int, Week> weeks;
|
||||
QMap<QString, Identifier> objectId;
|
||||
|
||||
public slots:
|
||||
void compute_week_number(const QDateTime &dt);
|
||||
void compute_time();
|
||||
void set_date_to_now();
|
||||
void edit();
|
||||
void edit_template();
|
||||
void open_about();
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
37
sources/setdaydialog.cpp
Normal file
37
sources/setdaydialog.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "setdaydialog.h"
|
||||
#include "ui_setdaydialog.h"
|
||||
|
||||
SetDayDialog::SetDayDialog(Day d, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::SetDayDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->d = d;
|
||||
init();
|
||||
}
|
||||
|
||||
SetDayDialog::~SetDayDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SetDayDialog::init() {
|
||||
ui->start_edit->setTime(d.get_start());
|
||||
ui->end_edit->setTime(d.get_end());
|
||||
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->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()));
|
||||
}
|
||||
|
||||
void SetDayDialog::compute_time() {
|
||||
d.set_start(ui->start_edit->time());
|
||||
d.set_end(ui->end_edit->time());
|
||||
d.set_time_break(ui->break_edit->value());
|
||||
ui->total_label->setText(Tools::double_to_string_time(d.get_total()));
|
||||
}
|
||||
|
||||
Day SetDayDialog::get_result() {
|
||||
return d;
|
||||
}
|
||||
34
sources/setdaydialog.h
Normal file
34
sources/setdaydialog.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef SETDAYDIALOG_H
|
||||
#define SETDAYDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "day.h"
|
||||
#include "tools.h"
|
||||
|
||||
namespace Ui {
|
||||
class SetDayDialog;
|
||||
}
|
||||
|
||||
class SetDayDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SetDayDialog(Day d, QWidget *parent = nullptr);
|
||||
~SetDayDialog();
|
||||
|
||||
Day get_result();
|
||||
|
||||
public slots:
|
||||
void compute_time();
|
||||
|
||||
private:
|
||||
Ui::SetDayDialog *ui;
|
||||
|
||||
Day d;
|
||||
|
||||
void init();
|
||||
};
|
||||
|
||||
#endif // SETDAYDIALOG_H
|
||||
14
sources/tools.cpp
Normal file
14
sources/tools.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "tools.h"
|
||||
|
||||
QString Tools::double_to_string_time(double value) {
|
||||
const int h = floor(value);
|
||||
value -= h;
|
||||
value = value * 60;
|
||||
if (value == 0.0) {
|
||||
return QString("%1h").arg(QString::number(h));
|
||||
} else if (value < 10.0) {
|
||||
return QString("%1h0%2").arg(QString::number(h), QString::number(round(value)));
|
||||
}
|
||||
|
||||
return QString("%1h%2").arg(QString::number(h), QString::number(round(value)));
|
||||
}
|
||||
13
sources/tools.h
Normal file
13
sources/tools.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef TOOLS_H
|
||||
#define TOOLS_H
|
||||
|
||||
#include <math.h>
|
||||
#include <QString>
|
||||
|
||||
class Tools
|
||||
{
|
||||
public:
|
||||
static QString double_to_string_time(double value);
|
||||
};
|
||||
|
||||
#endif // TOOLS_H
|
||||
86
sources/week.cpp
Normal file
86
sources/week.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "week.h"
|
||||
|
||||
Week::Week()
|
||||
{
|
||||
mon = Day();
|
||||
tue = Day();
|
||||
wed = Day();
|
||||
thu = Day();
|
||||
fri = Day();
|
||||
week_number = 0;
|
||||
}
|
||||
|
||||
Week Week::from_json(QJsonObject obj) {
|
||||
Week w;
|
||||
w.mon = Day::from_json(obj[MONDAY].toObject());
|
||||
w.tue = Day::from_json(obj[TUESDAY].toObject());
|
||||
w.wed = Day::from_json(obj[WEDNESDAY].toObject());
|
||||
w.thu = Day::from_json(obj[THURDAY].toObject());
|
||||
w.fri = Day::from_json(obj[FRIDAY].toObject());
|
||||
w.week_number = obj[WEEK_NUMBER].toInt();
|
||||
return w;
|
||||
}
|
||||
|
||||
QJsonObject Week::to_json() {
|
||||
QJsonObject obj {
|
||||
{MONDAY, mon.to_json()},
|
||||
{TUESDAY, tue.to_json()},
|
||||
{WEDNESDAY, wed.to_json()},
|
||||
{THURDAY, thu.to_json()},
|
||||
{FRIDAY, fri.to_json()},
|
||||
{WEEK_NUMBER, week_number}
|
||||
};
|
||||
return obj;
|
||||
}
|
||||
|
||||
double Week::total() {
|
||||
return mon.get_total() + tue.get_total() + wed.get_total() + thu.get_total() + fri.get_total();
|
||||
}
|
||||
|
||||
Day Week::getMon() {
|
||||
return mon;
|
||||
}
|
||||
|
||||
Day Week::getTue() {
|
||||
return tue;
|
||||
}
|
||||
|
||||
Day Week::getWed() {
|
||||
return wed;
|
||||
}
|
||||
|
||||
Day Week::getThu() {
|
||||
return thu;
|
||||
}
|
||||
|
||||
Day Week::getFri() {
|
||||
return fri;
|
||||
}
|
||||
|
||||
int Week::getWeekNumber() {
|
||||
return week_number;
|
||||
}
|
||||
|
||||
void Week::setMon(Day value) {
|
||||
mon = value;
|
||||
}
|
||||
|
||||
void Week::setTue(Day value) {
|
||||
tue = value;
|
||||
}
|
||||
|
||||
void Week::setWed(Day value) {
|
||||
wed = value;
|
||||
}
|
||||
|
||||
void Week::setThu(Day value) {
|
||||
thu = value;
|
||||
}
|
||||
|
||||
void Week::setFri(Day value) {
|
||||
fri = value;
|
||||
}
|
||||
|
||||
void Week::setWeekNumber(int value) {
|
||||
week_number = value;
|
||||
}
|
||||
46
sources/week.h
Normal file
46
sources/week.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef WEEK_H
|
||||
#define WEEK_H
|
||||
|
||||
#define MONDAY "monday"
|
||||
#define TUESDAY "tuesday"
|
||||
#define WEDNESDAY "wednesday"
|
||||
#define THURDAY "thurday"
|
||||
#define FRIDAY "friday"
|
||||
#define WEEK_NUMBER "weekNumber"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include "day.h"
|
||||
|
||||
class Week
|
||||
{
|
||||
public:
|
||||
Week();
|
||||
double total();
|
||||
|
||||
void setMon(Day);
|
||||
void setTue(Day);
|
||||
void setWed(Day);
|
||||
void setThu(Day);
|
||||
void setFri(Day);
|
||||
void setWeekNumber(int);
|
||||
|
||||
Day getMon();
|
||||
Day getTue();
|
||||
Day getWed();
|
||||
Day getThu();
|
||||
Day getFri();
|
||||
int getWeekNumber();
|
||||
|
||||
static Week from_json(QJsonObject);
|
||||
QJsonObject to_json();
|
||||
|
||||
private:
|
||||
Day mon;
|
||||
Day tue;
|
||||
Day wed;
|
||||
Day thu;
|
||||
Day fri;
|
||||
int week_number;
|
||||
};
|
||||
|
||||
#endif // WEEK_H
|
||||
79
sources/welcome.cpp
Normal file
79
sources/welcome.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "welcome.h"
|
||||
#include "ui_welcome.h"
|
||||
|
||||
Welcome::Welcome(Week wtemplate, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::Welcome)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
w = wtemplate;
|
||||
init();
|
||||
}
|
||||
|
||||
Welcome::~Welcome()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Welcome::init() {
|
||||
set_value_to_widget();
|
||||
objectId.insert(ui->mon_button->objectName(), Identifier::mon);
|
||||
objectId.insert(ui->tue_button->objectName(), Identifier::tue);
|
||||
objectId.insert(ui->wed_button->objectName(), Identifier::wed);
|
||||
objectId.insert(ui->thu_button->objectName(), Identifier::thu);
|
||||
objectId.insert(ui->fri_button->objectName(), Identifier::fri);
|
||||
connect(ui->mon_button, &QPushButton::clicked, this, &Welcome::edit);
|
||||
connect(ui->tue_button, &QPushButton::clicked, this, &Welcome::edit);
|
||||
connect(ui->wed_button, &QPushButton::clicked, this, &Welcome::edit);
|
||||
connect(ui->thu_button, &QPushButton::clicked, this, &Welcome::edit);
|
||||
connect(ui->fri_button, &QPushButton::clicked, this, &Welcome::edit);
|
||||
}
|
||||
|
||||
Week Welcome::get_result() {
|
||||
return w;
|
||||
}
|
||||
|
||||
void Welcome::set_value_to_widget() {
|
||||
ui->mon_time_label->setText(Tools::double_to_string_time(w.getMon().get_total()));
|
||||
ui->tue_time_label->setText(Tools::double_to_string_time(w.getTue().get_total()));
|
||||
ui->wed_time_label->setText(Tools::double_to_string_time(w.getWed().get_total()));
|
||||
ui->thu_time_label->setText(Tools::double_to_string_time(w.getThu().get_total()));
|
||||
ui->fri_time_label->setText(Tools::double_to_string_time(w.getFri().get_total()));
|
||||
ui->total->setText(Tools::double_to_string_time(w.total()));
|
||||
}
|
||||
|
||||
void Welcome::edit() {
|
||||
QString name = QObject::sender()->objectName();
|
||||
switch (get_identifier(name)) {
|
||||
case mon:
|
||||
w.setMon(modify_value(w.getMon()));
|
||||
break;
|
||||
case tue:
|
||||
w.setTue(modify_value(w.getTue()));
|
||||
break;
|
||||
case wed:
|
||||
w.setWed(modify_value(w.getWed()));
|
||||
break;
|
||||
case thu:
|
||||
w.setThu(modify_value(w.getThu()));
|
||||
break;
|
||||
case fri:
|
||||
w.setFri(modify_value(w.getFri()));
|
||||
break;
|
||||
}
|
||||
set_value_to_widget();
|
||||
}
|
||||
|
||||
Day Welcome::modify_value(Day d) {
|
||||
SetDayDialog sdd(d, this);
|
||||
int result = sdd.exec();
|
||||
if (result == QDialog::Accepted) {
|
||||
return sdd.get_result();
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
Identifier Welcome::get_identifier(QString objectName) {
|
||||
return objectId[objectName];
|
||||
}
|
||||
|
||||
50
sources/welcome.h
Normal file
50
sources/welcome.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef WELCOME_H
|
||||
#define WELCOME_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <math.h>
|
||||
|
||||
#include "week.h"
|
||||
#include "day.h"
|
||||
#include "tools.h"
|
||||
#include "setdaydialog.h"
|
||||
|
||||
enum Identifier {
|
||||
mon = 1,
|
||||
tue = 2,
|
||||
wed = 3,
|
||||
thu = 4,
|
||||
fri = 5
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class Welcome;
|
||||
}
|
||||
|
||||
class Welcome : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Welcome(Week tpl, QWidget *parent = nullptr);
|
||||
~Welcome();
|
||||
|
||||
Week get_result();
|
||||
|
||||
private:
|
||||
Ui::Welcome *ui;
|
||||
|
||||
Week w;
|
||||
QMap<QString, Identifier> objectId;
|
||||
|
||||
void init();
|
||||
void set_value_to_widget();
|
||||
Identifier get_identifier(QString objectName);
|
||||
Day modify_value(Day);
|
||||
|
||||
public slots:
|
||||
void edit();
|
||||
};
|
||||
|
||||
#endif // WELCOME_H
|
||||
Reference in New Issue
Block a user