2017-12-02 10:50:30 +01:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
2017-12-02 18:46:46 +01:00
|
|
|
#include <QUrl>
|
2017-12-02 10:50:30 +01:00
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QStandardItem>
|
|
|
|
|
#include <QStringBuilder>
|
|
|
|
|
#include <QMenu>
|
2017-12-02 12:41:49 +01:00
|
|
|
#include <QLabel>
|
2017-12-02 18:46:46 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
|
#include <QDesktopServices>
|
2017-12-02 19:03:43 +01:00
|
|
|
#include <QRegularExpression>
|
2017-12-02 10:50:30 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2017-12-03 22:22:07 +01:00
|
|
|
#include "zeiterfassungsettings.h"
|
2017-12-02 10:50:30 +01:00
|
|
|
#include "eventloopwithstatus.h"
|
|
|
|
|
#include "dialogs/aboutmedialog.h"
|
2017-12-05 21:36:47 +01:00
|
|
|
#include "dialogs/bookingdialog.h"
|
2017-12-05 21:03:03 +01:00
|
|
|
#include "dialogs/timeassignmentdialog.h"
|
2017-12-04 20:11:11 +01:00
|
|
|
#include "dialogs/settingsdialog.h"
|
2017-12-07 00:27:39 +01:00
|
|
|
#include "dialogs/updatedialog.h"
|
2017-12-05 21:36:47 +01:00
|
|
|
#include "strips/bookingstrip.h"
|
2017-12-05 21:03:03 +01:00
|
|
|
#include "strips/timeassignmentstrip.h"
|
2017-12-05 21:36:47 +01:00
|
|
|
#include "models/bookingsmodel.h"
|
2017-12-05 21:03:03 +01:00
|
|
|
#include "models/timeassignmentsmodel.h"
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-03 22:22:07 +01:00
|
|
|
MainWindow::MainWindow(ZeiterfassungSettings &settings, Zeiterfassung &erfassung, const Zeiterfassung::UserInfo &userInfo, QWidget *parent) :
|
2017-12-02 10:50:30 +01:00
|
|
|
QMainWindow(parent),
|
|
|
|
|
ui(new Ui::MainWindow),
|
|
|
|
|
m_settings(settings),
|
|
|
|
|
m_erfassung(erfassung),
|
|
|
|
|
m_userInfo(userInfo),
|
2017-12-05 21:36:47 +01:00
|
|
|
m_bookingsModel(new BookingsModel(erfassung, this)),
|
2017-12-05 21:03:03 +01:00
|
|
|
m_timeAssignmentsModel(new TimeAssignmentsModel(erfassung, this)),
|
2017-12-02 10:50:30 +01:00
|
|
|
m_flag(false)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
2017-12-02 19:26:40 +01:00
|
|
|
setWindowTitle(tr("Zeiterfassung - %0 (%1)").arg(m_userInfo.text).arg(m_userInfo.email));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
ui->actionQuit->setShortcut(QKeySequence::Quit);
|
|
|
|
|
|
|
|
|
|
connect(ui->actionToday, &QAction::triggered, [=](){ ui->dateEditDate->setDate(QDate::currentDate()); });
|
|
|
|
|
|
|
|
|
|
ui->actionRefresh->setShortcut(QKeySequence::Refresh);
|
2017-12-04 20:25:33 +01:00
|
|
|
connect(ui->actionRefresh, &QAction::triggered, this, [=](){ refresh(true); });
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-02 18:46:46 +01:00
|
|
|
connect(ui->actionAuswertung, &QAction::triggered, [=](){
|
|
|
|
|
QTemporaryFile file(QDir::temp().absoluteFilePath("auswertungXXXXXX.pdf"));
|
|
|
|
|
file.setAutoRemove(false);
|
|
|
|
|
if(!file.open())
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not open auswertung!"), tr("Could not open auswertung!") % "\n\n" % file.errorString());
|
2017-12-02 18:46:46 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.write(m_auswertung);
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
if(!QDesktopServices::openUrl(QUrl::fromLocalFile(file.fileName())))
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not open auswertung!"), tr("Could not open default PDF viewer!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-02 10:50:30 +01:00
|
|
|
connect(ui->actionAboutMe, &QAction::triggered, [=](){ AboutMeDialog(userInfo, this).exec(); });
|
2017-12-04 20:11:11 +01:00
|
|
|
connect(ui->actionSettings, &QAction::triggered, [=](){ SettingsDialog(m_settings, this).exec(); });
|
|
|
|
|
|
2017-12-02 10:50:30 +01:00
|
|
|
connect(ui->actionAboutQt, &QAction::triggered, [=](){ QMessageBox::aboutQt(this); });
|
|
|
|
|
|
|
|
|
|
ui->dateEditDate->setDate(QDate::currentDate());
|
2017-12-04 20:25:33 +01:00
|
|
|
connect(ui->dateEditDate, &QDateTimeEdit::dateChanged, this, [=](){ refresh(); });
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-04 20:11:11 +01:00
|
|
|
connect(ui->pushButtonPrev, &QAbstractButton::pressed, [=](){ ui->dateEditDate->setDate(ui->dateEditDate->date().addDays(-1)); });
|
|
|
|
|
connect(ui->pushButtonNext, &QAbstractButton::pressed, [=](){ ui->dateEditDate->setDate(ui->dateEditDate->date().addDays(1)); });
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
ui->timeEditTime->setTime(timeNormalise(QTime::currentTime()));
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::getProjectsFinished,
|
|
|
|
|
this, &MainWindow::getProjekctsFinished);
|
|
|
|
|
erfassung.doGetProjects(userInfo.userId, QDate::currentDate());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setMaxVisibleItems(10);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxSubproject->lineEdit()->setPlaceholderText(tr("Subproject"));
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->lineEdit()->setPlaceholderText(tr("Workpackage"));
|
|
|
|
|
ui->comboBoxText->lineEdit()->setPlaceholderText(tr("Text"));
|
|
|
|
|
|
|
|
|
|
updateComboboxes();
|
|
|
|
|
|
|
|
|
|
connect(ui->pushButtonStart, &QAbstractButton::pressed, this, &MainWindow::pushButtonStartPressed);
|
|
|
|
|
connect(ui->pushButtonEnd, &QAbstractButton::pressed, this, &MainWindow::pushButtonEndPressed);
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
ui->treeViewBookings->setModel(m_bookingsModel);
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->treeViewTimeAssignments->setModel(m_timeAssignmentsModel);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(ui->treeViewBookings, &QWidget::customContextMenuRequested,
|
|
|
|
|
this, &MainWindow::contextMenuBooking);
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(ui->treeViewTimeAssignments, &QWidget::customContextMenuRequested,
|
|
|
|
|
this, &MainWindow::contextMenuTimeAssignment);
|
2017-12-02 18:25:32 +01:00
|
|
|
|
2017-12-05 20:46:41 +01:00
|
|
|
ui->statusbar->addPermanentWidget(m_workingTimeLabel = new QLabel(ui->statusbar));
|
|
|
|
|
m_workingTimeLabel->setFrameShape(QFrame::Panel);
|
|
|
|
|
m_workingTimeLabel->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
ui->statusbar->addPermanentWidget(m_balanceLabel = new QLabel(ui->statusbar));
|
|
|
|
|
m_balanceLabel->setFrameShape(QFrame::Panel);
|
|
|
|
|
m_balanceLabel->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
ui->statusbar->addPermanentWidget(m_holidaysLabel = new QLabel(ui->statusbar));
|
|
|
|
|
m_holidaysLabel->setFrameShape(QFrame::Panel);
|
|
|
|
|
m_holidaysLabel->setFrameShadow(QFrame::Sunken);
|
2017-12-02 19:03:43 +01:00
|
|
|
|
2017-12-04 20:25:33 +01:00
|
|
|
refresh(true);
|
2017-12-07 00:27:39 +01:00
|
|
|
|
|
|
|
|
if(settings.lastUpdateCheck().isNull() || settings.lastUpdateCheck() < QDate::currentDate())
|
|
|
|
|
new UpdateDialog(settings, erfassung.manager(), this);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 11:43:38 +01:00
|
|
|
int MainWindow::timeToSeconds(const QTime &time)
|
|
|
|
|
{
|
|
|
|
|
return QTime(0, 0).secsTo(time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTime MainWindow::timeBetween(const QTime &l, const QTime &r)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(l <= r);
|
|
|
|
|
return QTime(0, 0).addSecs(l.secsTo(r));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTime MainWindow::timeAdd(const QTime &l, const QTime &r)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(timeToSeconds(l) + timeToSeconds(r) < 86400);
|
|
|
|
|
return l.addSecs(QTime(0, 0).secsTo(r));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTime MainWindow::timeNormalise(const QTime &time)
|
|
|
|
|
{
|
2017-12-03 22:12:38 +01:00
|
|
|
return QTime(time.hour(), time.minute());
|
2017-12-02 11:43:38 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 20:25:33 +01:00
|
|
|
void MainWindow::refresh(bool forceAuswertung)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
|
|
|
|
ui->dateEditDate->setReadOnly(true);
|
2017-12-02 12:48:09 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->timeEditTime->setEnabled(false);
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setEnabled(false);
|
|
|
|
|
ui->comboBoxSubproject->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->setEnabled(false);
|
|
|
|
|
ui->comboBoxText->setEnabled(false);
|
|
|
|
|
ui->pushButtonStart->setEnabled(false);
|
|
|
|
|
ui->pushButtonEnd->setEnabled(false);
|
2017-12-05 21:36:47 +01:00
|
|
|
ui->treeViewBookings->setEnabled(false);
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->treeViewTimeAssignments->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
m_workingTimeLabel->setText(tr("%0: %1").arg(tr("Assigned time")).arg(tr("???")));
|
2017-12-05 20:28:12 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
auto waitForBookings = m_bookingsModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date());
|
|
|
|
|
if(waitForBookings)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(m_bookingsModel, &BookingsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshBookingsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
auto waitForTimeAssignments = m_timeAssignmentsModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date());
|
|
|
|
|
if(waitForTimeAssignments)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(m_timeAssignmentsModel, &TimeAssignmentsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshTimeAssignmentsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(!waitForBookings || !waitForTimeAssignments)
|
|
|
|
|
QMessageBox::warning(this, tr("Unknown error occured!"), tr("Unknown error occured!"));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(waitForBookings || waitForTimeAssignments)
|
|
|
|
|
m_flag = waitForBookings == waitForTimeAssignments;
|
2017-12-02 10:50:30 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(true);
|
|
|
|
|
ui->actionRefresh->setEnabled(true);
|
|
|
|
|
ui->dateEditDate->setReadOnly(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(true);
|
|
|
|
|
ui->pushButtonNext->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
2017-12-02 11:43:38 +01:00
|
|
|
|
|
|
|
|
clearStrips();
|
2017-12-04 20:25:33 +01:00
|
|
|
|
|
|
|
|
auto auswertungDate = QDate(ui->dateEditDate->date().year(), ui->dateEditDate->date().month(), 1);
|
|
|
|
|
if(forceAuswertung || m_auswertungDate != auswertungDate)
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
m_balanceLabel->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("???")));
|
|
|
|
|
m_holidaysLabel->setText(tr("%0: %1").arg(tr("Holidays")).arg(tr("???")));
|
2017-12-04 20:25:33 +01:00
|
|
|
|
|
|
|
|
ui->actionAuswertung->setEnabled(false);
|
|
|
|
|
m_auswertung.clear();
|
|
|
|
|
|
|
|
|
|
if(m_erfassung.doGetAuswertung(m_userInfo.userId, auswertungDate))
|
|
|
|
|
{
|
|
|
|
|
m_auswertungDate = auswertungDate;
|
|
|
|
|
connect(&m_erfassung, &Zeiterfassung::getAuswertungFinished,
|
|
|
|
|
this, &MainWindow::getAuswertungFinished);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_auswertungDate = QDate();
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Unknown error occured!"), tr("Unknown error occured!"));
|
2017-12-04 20:25:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
void MainWindow::getProjekctsFinished(bool success, const QString &message, const QVector<Zeiterfassung::Project> &projects)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
disconnect(&m_erfassung, &Zeiterfassung::getProjectsFinished,
|
|
|
|
|
this, &MainWindow::getProjekctsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
if(!success)
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not load bookings!"), tr("Could not load bookings!") % "\n\n" % message);
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
m_projects.clear();
|
2017-12-02 19:11:49 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
for(const auto &project : projects)
|
|
|
|
|
m_projects.insert(project.value, project.label);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
updateComboboxes();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 18:46:46 +01:00
|
|
|
void MainWindow::getAuswertungFinished(bool success, const QString &message, const QByteArray &content)
|
|
|
|
|
{
|
|
|
|
|
disconnect(&m_erfassung, &Zeiterfassung::getAuswertungFinished,
|
|
|
|
|
this, &MainWindow::getAuswertungFinished);
|
|
|
|
|
|
|
|
|
|
if(!success)
|
|
|
|
|
{
|
2017-12-04 20:25:33 +01:00
|
|
|
m_auswertungDate = QDate();
|
2017-12-05 21:03:03 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not load Auswertung!"), tr("Could not load Auswertung!") % "\n\n" % message);
|
2017-12-02 18:46:46 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->actionAuswertung->setEnabled(true);
|
|
|
|
|
m_auswertung = content;
|
|
|
|
|
|
2017-12-05 20:46:41 +01:00
|
|
|
auto urlaubsAnspruch = tr("???");
|
|
|
|
|
auto gleitzeit = tr("???");
|
2017-12-02 19:03:43 +01:00
|
|
|
|
|
|
|
|
{
|
2017-12-05 20:46:41 +01:00
|
|
|
static QRegularExpression regex(QStringLiteral("Urlaubsanspruch +([0-9]+\\.[0-9]+\\-?) +([0-9]+\\.[0-9]+\\-?)"));
|
2017-12-02 19:03:43 +01:00
|
|
|
auto match = regex.match(content);
|
|
|
|
|
if(match.hasMatch())
|
|
|
|
|
urlaubsAnspruch = match.captured(2);
|
|
|
|
|
else
|
|
|
|
|
qWarning() << "Urlaubsanspruch not found";
|
|
|
|
|
}
|
|
|
|
|
{
|
2017-12-05 20:46:41 +01:00
|
|
|
static QRegularExpression regex(QStringLiteral("Gleitzeit +([0-9]+\\:[0-9]+\\-?) +([0-9]+\\:[0-9]+\\-?)"));
|
2017-12-02 19:03:43 +01:00
|
|
|
auto match = regex.match(content);
|
|
|
|
|
if(match.hasMatch())
|
2017-12-05 21:03:03 +01:00
|
|
|
{
|
2017-12-02 19:03:43 +01:00
|
|
|
gleitzeit = match.captured(2);
|
2017-12-05 21:03:03 +01:00
|
|
|
if(gleitzeit.endsWith(QChar('-')))
|
|
|
|
|
{
|
|
|
|
|
gleitzeit.chop(1);
|
|
|
|
|
gleitzeit = QChar('-') % gleitzeit;
|
|
|
|
|
}
|
|
|
|
|
gleitzeit = tr("%0h").arg(gleitzeit);
|
|
|
|
|
}
|
2017-12-02 19:03:43 +01:00
|
|
|
else
|
|
|
|
|
qWarning() << "Gleitzeit not found";
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
m_balanceLabel->setText(tr("%0: %1").arg(tr("Balance")).arg(gleitzeit));
|
|
|
|
|
m_holidaysLabel->setText(tr("%0: %1").arg(tr("Holidays")).arg(urlaubsAnspruch));
|
2017-12-02 18:46:46 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
void MainWindow::refreshBookingsFinished(bool success, const QString &message)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
disconnect(m_bookingsModel, &BookingsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshBookingsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
if(success)
|
2017-12-05 21:36:47 +01:00
|
|
|
ui->treeViewBookings->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
if(m_flag)
|
|
|
|
|
m_flag = false;
|
|
|
|
|
else
|
|
|
|
|
validateEntries();
|
|
|
|
|
|
|
|
|
|
if(!success)
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(Q_NULLPTR, tr("Could not load bookings!"), tr("Could not load bookings!") % "\n\n" % message);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
void MainWindow::refreshTimeAssignmentsFinished(bool success, const QString &message)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
disconnect(m_timeAssignmentsModel, &TimeAssignmentsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshTimeAssignmentsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
if(success)
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->treeViewTimeAssignments->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
if(m_flag)
|
|
|
|
|
m_flag = false;
|
|
|
|
|
else
|
|
|
|
|
validateEntries();
|
|
|
|
|
|
|
|
|
|
if(!success)
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(Q_NULLPTR, tr("Could not load time assignments!"), tr("Could not load time assignments!") % "\n\n" % message);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
void MainWindow::contextMenuBooking(const QPoint &pos)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
auto index = ui->treeViewBookings->indexAt(pos);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
if(index.isValid())
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
auto booking = m_bookingsModel->getBooking(index);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
QMenu menu;
|
2017-12-05 21:36:47 +01:00
|
|
|
auto editAction = menu.addAction(tr("Edit booking"));
|
|
|
|
|
auto deleteAction = menu.addAction(tr("Delete booking"));
|
|
|
|
|
auto selectedAction = menu.exec(ui->treeViewBookings->viewport()->mapToGlobal(pos));
|
2017-12-02 10:50:30 +01:00
|
|
|
if(selectedAction == editAction)
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
BookingDialog dialog(this);
|
|
|
|
|
dialog.setTime(booking.time);
|
|
|
|
|
dialog.setTimespan(booking.timespan);
|
|
|
|
|
dialog.setType(booking.type);
|
|
|
|
|
dialog.setText(booking.text);
|
2017-12-02 10:50:30 +01:00
|
|
|
again1:
|
|
|
|
|
if(dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::updateBookingFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
m_erfassung.doUpdateBooking(booking.id, m_userInfo.userId, ui->dateEditDate->date(),
|
2017-12-02 10:50:30 +01:00
|
|
|
dialog.getTime(), dialog.getTimespan(),
|
|
|
|
|
dialog.getType(), dialog.getText());
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(eventLoop.success())
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
|
|
|
|
ui->dateEditDate->setReadOnly(true);
|
2017-12-02 12:48:09 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->timeEditTime->setEnabled(false);
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setEnabled(false);
|
|
|
|
|
ui->comboBoxSubproject->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->setEnabled(false);
|
|
|
|
|
ui->comboBoxText->setEnabled(false);
|
|
|
|
|
ui->pushButtonStart->setEnabled(false);
|
|
|
|
|
ui->pushButtonEnd->setEnabled(false);
|
2017-12-05 21:36:47 +01:00
|
|
|
ui->treeViewBookings->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-02 11:43:38 +01:00
|
|
|
clearStrips();
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(m_bookingsModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(m_bookingsModel, &BookingsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshBookingsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
m_flag = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(true);
|
|
|
|
|
ui->actionRefresh->setEnabled(true);
|
|
|
|
|
ui->dateEditDate->setReadOnly(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(true);
|
|
|
|
|
ui->pushButtonNext->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not edit booking!"), tr("Could not edit booking!") % "\n\n" % eventLoop.message());
|
2017-12-02 10:50:30 +01:00
|
|
|
goto again1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(selectedAction == deleteAction)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox msgBox;
|
2017-12-05 21:36:47 +01:00
|
|
|
msgBox.setText("Do you really want to delete the booking?");
|
2017-12-02 10:50:30 +01:00
|
|
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
|
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
|
if(msgBox.exec() == QMessageBox::Yes)
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::deleteBookingFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
m_erfassung.doDeleteBooking(booking.id);
|
2017-12-02 10:50:30 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(eventLoop.success())
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
|
|
|
|
ui->dateEditDate->setReadOnly(true);
|
2017-12-02 12:48:09 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->timeEditTime->setEnabled(false);
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setEnabled(false);
|
|
|
|
|
ui->comboBoxSubproject->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->setEnabled(false);
|
|
|
|
|
ui->comboBoxText->setEnabled(false);
|
|
|
|
|
ui->pushButtonStart->setEnabled(false);
|
|
|
|
|
ui->pushButtonEnd->setEnabled(false);
|
2017-12-05 21:36:47 +01:00
|
|
|
ui->treeViewBookings->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-02 11:43:38 +01:00
|
|
|
clearStrips();
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(m_bookingsModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(m_bookingsModel, &BookingsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshBookingsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
m_flag = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(true);
|
|
|
|
|
ui->actionRefresh->setEnabled(true);
|
|
|
|
|
ui->dateEditDate->setReadOnly(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(true);
|
|
|
|
|
ui->pushButtonNext->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not delete booking!"), tr("Could not delete booking!") % "\n\n" % eventLoop.message());
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QMenu menu;
|
2017-12-05 21:36:47 +01:00
|
|
|
auto createAction = menu.addAction(tr("Create booking"));
|
|
|
|
|
auto selectedAction = menu.exec(ui->treeViewBookings->viewport()->mapToGlobal(pos));
|
2017-12-02 10:50:30 +01:00
|
|
|
if(selectedAction == createAction)
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
BookingDialog dialog(this);
|
2017-12-03 22:12:38 +01:00
|
|
|
dialog.setTime(timeNormalise(QTime::currentTime()));
|
2017-12-02 10:50:30 +01:00
|
|
|
again2:
|
|
|
|
|
if(dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::createBookingFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
m_erfassung.doCreateBooking(m_userInfo.userId, ui->dateEditDate->date(),
|
2017-12-02 10:50:30 +01:00
|
|
|
dialog.getTime(), dialog.getTimespan(),
|
|
|
|
|
dialog.getType(), dialog.getText());
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(eventLoop.success())
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
|
|
|
|
ui->dateEditDate->setReadOnly(true);
|
2017-12-02 12:48:09 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->timeEditTime->setEnabled(false);
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setEnabled(false);
|
|
|
|
|
ui->comboBoxSubproject->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->setEnabled(false);
|
|
|
|
|
ui->comboBoxText->setEnabled(false);
|
|
|
|
|
ui->pushButtonStart->setEnabled(false);
|
|
|
|
|
ui->pushButtonEnd->setEnabled(false);
|
2017-12-05 21:36:47 +01:00
|
|
|
ui->treeViewBookings->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-02 11:43:38 +01:00
|
|
|
clearStrips();
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(m_bookingsModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(m_bookingsModel, &BookingsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshBookingsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
m_flag = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(true);
|
|
|
|
|
ui->actionRefresh->setEnabled(true);
|
|
|
|
|
ui->dateEditDate->setReadOnly(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(true);
|
|
|
|
|
ui->pushButtonNext->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not create booking!"), tr("Could not create booking!") % "\n\n" % eventLoop.message());
|
2017-12-02 10:50:30 +01:00
|
|
|
goto again2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
void MainWindow::contextMenuTimeAssignment(const QPoint &pos)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
auto index = ui->treeViewTimeAssignments->indexAt(pos);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
if(index.isValid())
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
auto timeAssignment = m_timeAssignmentsModel->getTimeAssignment(index);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
QMenu menu;
|
2017-12-05 21:36:47 +01:00
|
|
|
auto editAction = menu.addAction(tr("Edit time assignment"));
|
|
|
|
|
auto deleteAction = menu.addAction(tr("Delete time assignment"));
|
2017-12-05 21:03:03 +01:00
|
|
|
auto selectedAction = menu.exec(ui->treeViewTimeAssignments->viewport()->mapToGlobal(pos));
|
2017-12-02 10:50:30 +01:00
|
|
|
if(selectedAction == editAction)
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
TimeAssignmentDialog dialog(m_projects, m_settings, this);
|
2017-12-05 21:03:03 +01:00
|
|
|
dialog.setTime(timeAssignment.time);
|
|
|
|
|
dialog.setTimespan(timeAssignment.timespan);
|
2017-12-05 21:16:46 +01:00
|
|
|
dialog.setProject(timeAssignment.project);
|
|
|
|
|
dialog.setSubproject(timeAssignment.subproject);
|
2017-12-05 21:03:03 +01:00
|
|
|
dialog.setWorkpackage(timeAssignment.workpackage);
|
|
|
|
|
dialog.setText(timeAssignment.text);
|
2017-12-02 10:50:30 +01:00
|
|
|
again1:
|
|
|
|
|
if(dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::updateTimeAssignmentFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
m_erfassung.doUpdateTimeAssignment(timeAssignment.id, m_userInfo.userId, ui->dateEditDate->date(),
|
2017-12-02 10:50:30 +01:00
|
|
|
dialog.getTime(), dialog.getTimespan(),
|
2017-12-05 21:16:46 +01:00
|
|
|
dialog.getProject(), dialog.getSubproject(),
|
2017-12-02 10:50:30 +01:00
|
|
|
dialog.getWorkpackage(), dialog.getText());
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(eventLoop.success())
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
|
|
|
|
ui->dateEditDate->setReadOnly(true);
|
2017-12-02 12:48:09 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->timeEditTime->setEnabled(false);
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setEnabled(false);
|
|
|
|
|
ui->comboBoxSubproject->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->setEnabled(false);
|
|
|
|
|
ui->comboBoxText->setEnabled(false);
|
|
|
|
|
ui->pushButtonStart->setEnabled(false);
|
|
|
|
|
ui->pushButtonEnd->setEnabled(false);
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->treeViewTimeAssignments->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
m_settings.prependProject(dialog.getProject());
|
|
|
|
|
m_settings.prependSubproject(dialog.getSubproject());
|
2017-12-03 22:22:07 +01:00
|
|
|
m_settings.prependWorkpackage(dialog.getWorkpackage());
|
|
|
|
|
m_settings.prependText(dialog.getText());
|
2017-12-03 18:54:03 +01:00
|
|
|
|
2017-12-02 11:43:38 +01:00
|
|
|
clearStrips();
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(m_timeAssignmentsModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(m_timeAssignmentsModel, &TimeAssignmentsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshTimeAssignmentsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
m_flag = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(true);
|
|
|
|
|
ui->actionRefresh->setEnabled(true);
|
|
|
|
|
ui->dateEditDate->setReadOnly(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(true);
|
|
|
|
|
ui->pushButtonNext->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not edit time assignment!"), tr("Could not edit time assignment!") % "\n\n" % eventLoop.message());
|
2017-12-02 10:50:30 +01:00
|
|
|
goto again1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(selectedAction == deleteAction)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox msgBox;
|
2017-12-05 21:03:03 +01:00
|
|
|
msgBox.setText("Do you really want to delete the time assignment?");
|
2017-12-02 10:50:30 +01:00
|
|
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
|
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
|
if(msgBox.exec() == QMessageBox::Yes)
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::deleteTimeAssignmentFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
m_erfassung.doDeleteTimeAssignment(timeAssignment.id);
|
2017-12-02 10:50:30 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(eventLoop.success())
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
|
|
|
|
ui->dateEditDate->setReadOnly(true);
|
2017-12-02 12:48:09 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->timeEditTime->setEnabled(false);
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setEnabled(false);
|
|
|
|
|
ui->comboBoxSubproject->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->setEnabled(false);
|
|
|
|
|
ui->comboBoxText->setEnabled(false);
|
|
|
|
|
ui->pushButtonStart->setEnabled(false);
|
|
|
|
|
ui->pushButtonEnd->setEnabled(false);
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->treeViewTimeAssignments->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-02 11:43:38 +01:00
|
|
|
clearStrips();
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(m_timeAssignmentsModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(m_timeAssignmentsModel, &TimeAssignmentsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshTimeAssignmentsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
m_flag = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(true);
|
|
|
|
|
ui->actionRefresh->setEnabled(true);
|
|
|
|
|
ui->dateEditDate->setReadOnly(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(true);
|
|
|
|
|
ui->pushButtonNext->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-12-05 21:03:03 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not delete time assignment!"), tr("Could not delete time assignment!") % "\n\n" % eventLoop.message());
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QMenu menu;
|
2017-12-05 21:36:47 +01:00
|
|
|
auto createAction = menu.addAction(tr("Create time assignment"));
|
2017-12-05 21:03:03 +01:00
|
|
|
auto selectedAction = menu.exec(ui->treeViewTimeAssignments->viewport()->mapToGlobal(pos));
|
2017-12-02 10:50:30 +01:00
|
|
|
if(selectedAction == createAction)
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
TimeAssignmentDialog dialog(m_projects, m_settings, this);
|
2017-12-02 10:50:30 +01:00
|
|
|
again2:
|
|
|
|
|
if(dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::createTimeAssignmentFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
m_erfassung.doCreateTimeAssignment(m_userInfo.userId, ui->dateEditDate->date(),
|
2017-12-02 10:50:30 +01:00
|
|
|
dialog.getTime(), dialog.getTimespan(),
|
2017-12-05 21:16:46 +01:00
|
|
|
dialog.getProject(), dialog.getSubproject(),
|
2017-12-02 10:50:30 +01:00
|
|
|
dialog.getWorkpackage(), dialog.getText());
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(eventLoop.success())
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
|
|
|
|
ui->dateEditDate->setReadOnly(true);
|
2017-12-02 12:48:09 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->timeEditTime->setEnabled(false);
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setEnabled(false);
|
|
|
|
|
ui->comboBoxSubproject->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->setEnabled(false);
|
|
|
|
|
ui->comboBoxText->setEnabled(false);
|
|
|
|
|
ui->pushButtonStart->setEnabled(false);
|
|
|
|
|
ui->pushButtonEnd->setEnabled(false);
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->treeViewTimeAssignments->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
m_settings.prependProject(dialog.getProject());
|
|
|
|
|
m_settings.prependSubproject(dialog.getSubproject());
|
2017-12-03 22:22:07 +01:00
|
|
|
m_settings.prependWorkpackage(dialog.getWorkpackage());
|
|
|
|
|
m_settings.prependText(dialog.getText());
|
2017-12-03 18:54:03 +01:00
|
|
|
|
2017-12-02 11:43:38 +01:00
|
|
|
clearStrips();
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(m_timeAssignmentsModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date()))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(m_timeAssignmentsModel, &TimeAssignmentsModel::refreshFinished,
|
|
|
|
|
this, &MainWindow::refreshTimeAssignmentsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
m_flag = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(true);
|
|
|
|
|
ui->actionRefresh->setEnabled(true);
|
|
|
|
|
ui->dateEditDate->setReadOnly(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(true);
|
|
|
|
|
ui->pushButtonNext->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not create time assignment!"), tr("Could not create time assignment!") % "\n\n" % eventLoop.message());
|
2017-12-02 10:50:30 +01:00
|
|
|
goto again2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonStartPressed()
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
if(m_bookingsModel->rbegin() == m_bookingsModel->rend() ||
|
|
|
|
|
m_bookingsModel->rbegin()->type == QStringLiteral("G"))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::createBookingFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
m_erfassung.doCreateBooking(m_userInfo.userId, ui->dateEditDate->date(),
|
2017-12-02 10:50:30 +01:00
|
|
|
timeNormalise(ui->timeEditTime->time()), QTime(0, 0),
|
|
|
|
|
QStringLiteral("K"), QStringLiteral(""));
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(!eventLoop.success())
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not create booking!"), tr("Could not create booking!") % "\n\n" % eventLoop.message());
|
2017-12-04 20:25:33 +01:00
|
|
|
refresh(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(m_timeAssignmentsModel->rbegin() != m_timeAssignmentsModel->rend())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
auto timeAssignment = *m_timeAssignmentsModel->rbegin();
|
|
|
|
|
if(timeAssignment.timespan == QTime(0, 0))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::updateTimeAssignmentFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
auto timespan = timeBetween(m_lastTimeAssignmentStart, ui->timeEditTime->time());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
m_erfassung.doUpdateTimeAssignment(timeAssignment.id, m_userInfo.userId, timeAssignment.date,
|
|
|
|
|
timeAssignment.time, timespan,
|
2017-12-05 21:16:46 +01:00
|
|
|
timeAssignment.project, timeAssignment.subproject,
|
2017-12-05 21:03:03 +01:00
|
|
|
timeAssignment.workpackage, timeAssignment.text);
|
2017-12-02 10:50:30 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(eventLoop.success())
|
2017-12-05 21:03:03 +01:00
|
|
|
m_timeAssignmentTime = timeAdd(m_timeAssignmentTime, timespan);
|
2017-12-02 10:50:30 +01:00
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not edit time assignment!"), tr("Could not edit time assignment!") % "\n\n" % eventLoop.message());
|
2017-12-04 20:25:33 +01:00
|
|
|
refresh(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::createTimeAssignmentFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
m_erfassung.doCreateTimeAssignment(m_userInfo.userId, ui->dateEditDate->date(),
|
|
|
|
|
m_timeAssignmentTime, QTime(0, 0),
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->currentData().toString(), ui->comboBoxSubproject->currentText(),
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->currentText(), ui->comboBoxText->currentText());
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(!eventLoop.success())
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not create time assignment!"), tr("Could not create time assignment!") % "\n\n" % eventLoop.message());
|
2017-12-04 20:25:33 +01:00
|
|
|
refresh(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
m_settings.prependProject(ui->comboBoxProject->currentData().toString());
|
|
|
|
|
m_settings.prependSubproject(ui->comboBoxSubproject->currentText());
|
2017-12-03 22:22:07 +01:00
|
|
|
m_settings.prependWorkpackage(ui->comboBoxWorkpackage->currentText());
|
|
|
|
|
m_settings.prependText(ui->comboBoxText->currentText());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
updateComboboxes();
|
|
|
|
|
|
2017-12-04 20:25:33 +01:00
|
|
|
refresh(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonEndPressed()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:36:47 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::createBookingFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
m_erfassung.doCreateBooking(m_userInfo.userId, ui->dateEditDate->date(),
|
2017-12-02 10:50:30 +01:00
|
|
|
timeNormalise(ui->timeEditTime->time()), QTime(0, 0),
|
|
|
|
|
QStringLiteral("G"), QStringLiteral(""));
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(!eventLoop.success())
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not create booking!"), tr("Could not create booking!") % "\n\n" % eventLoop.message());
|
2017-12-04 20:25:33 +01:00
|
|
|
refresh(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
auto timeAssignment = *m_timeAssignmentsModel->rbegin();
|
|
|
|
|
Q_ASSERT(timeAssignment.timespan == QTime(0, 0));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
2017-12-05 21:03:03 +01:00
|
|
|
connect(&m_erfassung, &Zeiterfassung::updateTimeAssignmentFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
auto timespan = timeBetween(m_lastTimeAssignmentStart, ui->timeEditTime->time());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
m_erfassung.doUpdateTimeAssignment(timeAssignment.id, m_userInfo.userId, timeAssignment.date,
|
|
|
|
|
timeAssignment.time, timespan,
|
2017-12-05 21:16:46 +01:00
|
|
|
timeAssignment.project, timeAssignment.subproject,
|
2017-12-05 21:03:03 +01:00
|
|
|
timeAssignment.workpackage, timeAssignment.text);
|
2017-12-02 10:50:30 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(eventLoop.success())
|
2017-12-05 21:03:03 +01:00
|
|
|
m_timeAssignmentTime = timeAdd(m_timeAssignmentTime, timespan);
|
2017-12-02 10:50:30 +01:00
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not edit time assignment!"), tr("Could not edit time assignment!") % "\n\n" % eventLoop.message());
|
2017-12-04 20:25:33 +01:00
|
|
|
refresh(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 20:25:33 +01:00
|
|
|
refresh(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::validateEntries()
|
|
|
|
|
{
|
2017-12-02 21:37:26 +01:00
|
|
|
ui->timeEditTime->setMinimumTime(QTime(0, 0));
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->actionToday->setEnabled(true);
|
|
|
|
|
ui->actionRefresh->setEnabled(true);
|
|
|
|
|
ui->dateEditDate->setReadOnly(false);
|
2017-12-02 13:03:19 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(true);
|
|
|
|
|
ui->pushButtonNext->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->pushButtonStart->setText(tr("Start"));
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(!ui->treeViewBookings->isEnabled())
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(!ui->treeViewTimeAssignments->isEnabled())
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
auto bookingsIter = m_bookingsModel->constBegin();
|
2017-12-05 21:03:03 +01:00
|
|
|
auto timeAssignmentsIter = m_timeAssignmentsModel->constBegin();
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
m_timeAssignmentTime = QTime(0, 0);
|
2017-12-05 21:36:47 +01:00
|
|
|
auto bookingTimespan = QTime(0, 0);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
const Zeiterfassung::Booking *lastBooking = Q_NULLPTR;
|
2017-12-05 21:03:03 +01:00
|
|
|
const Zeiterfassung::TimeAssignment *lastTimeAssignment = Q_NULLPTR;
|
2017-12-05 20:28:12 +01:00
|
|
|
|
2017-12-02 12:41:49 +01:00
|
|
|
QString errorMessage;
|
|
|
|
|
|
2017-12-02 10:50:30 +01:00
|
|
|
while(true)
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
if(bookingsIter == m_bookingsModel->constEnd() &&
|
2017-12-05 21:03:03 +01:00
|
|
|
timeAssignmentsIter == m_timeAssignmentsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-02 19:26:40 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(bookingsIter == m_bookingsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
errorMessage = tr("Missing booking!");
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
auto startBooking = *bookingsIter++;
|
|
|
|
|
if(startBooking.type != QStringLiteral("K"))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
errorMessage = tr("Expected start booking, instead got type %0\nBooking ID: %1")
|
|
|
|
|
.arg(startBooking.type)
|
|
|
|
|
.arg(startBooking.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(lastBooking)
|
2017-12-05 20:28:12 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
auto label = new QLabel(tr("%0: %1")
|
|
|
|
|
.arg(tr("Break"))
|
2017-12-05 21:36:47 +01:00
|
|
|
.arg(tr("%0h").arg(timeBetween(lastBooking->time, startBooking.time).toString(QStringLiteral("HH:mm")))),
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->scrollAreaWidgetContents);
|
2017-12-05 20:28:12 +01:00
|
|
|
ui->verticalLayout2->addWidget(label);
|
|
|
|
|
label->setMinimumHeight(20);
|
|
|
|
|
label->setMaximumHeight(20);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
lastBooking = &startBooking;
|
2017-12-05 20:28:12 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
m_lastTimeAssignmentStart = startBooking.time;
|
|
|
|
|
ui->verticalLayout2->addWidget(new BookingStrip(startBooking.id, startBooking.time, startBooking.type, m_settings, ui->scrollAreaWidgetContents));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignmentsIter == m_timeAssignmentsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
errorMessage = tr("Missing time assignment!");
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
auto timeAssignment = *timeAssignmentsIter++;
|
|
|
|
|
if(timeAssignment.time != m_timeAssignmentTime)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
errorMessage = tr("Expected %0 but received %1 in time assignment.\nTime assignment ID: %2")
|
|
|
|
|
.arg(m_timeAssignmentTime.toString("HH:mm:ss"))
|
|
|
|
|
.arg(timeAssignment.time.toString("HH:mm:ss"))
|
|
|
|
|
.arg(timeAssignment.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
lastTimeAssignment = &timeAssignment;
|
2017-12-05 20:28:12 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->verticalLayout2->addWidget(new TimeAssignmentStrip(timeAssignment.id, timeAssignment.timespan, buildProjectString(timeAssignment.project),
|
|
|
|
|
timeAssignment.subproject, timeAssignment.workpackage, timeAssignment.text,
|
2017-12-03 22:47:36 +01:00
|
|
|
m_settings, ui->scrollAreaWidgetContents));
|
2017-12-02 11:43:38 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignment.timespan == QTime(0, 0))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
if(bookingsIter != m_bookingsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
errorMessage = tr("There is another booking after an unfinished time assignment.\nBooking ID: %0\nTime assignment ID: %1")
|
|
|
|
|
.arg(bookingsIter->id)
|
2017-12-05 21:03:03 +01:00
|
|
|
.arg(timeAssignment.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignmentsIter != m_timeAssignmentsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
errorMessage = tr("There is another time assignment after an unfinished time assignment.\nTime assignment ID: %0\nTime assignment ID: %1")
|
|
|
|
|
.arg(timeAssignmentsIter->id)
|
|
|
|
|
.arg(timeAssignment.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->timeEditTime->setMinimumTime(timeAdd(m_lastTimeAssignmentStart, QTime(0, 1)));
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->pushButtonStart->setText(tr("Switch"));
|
|
|
|
|
ui->pushButtonEnd->setEnabled(true);
|
|
|
|
|
goto after;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
m_timeAssignmentTime = timeAdd(m_timeAssignmentTime, timeAssignment.timespan);
|
|
|
|
|
m_lastTimeAssignmentStart = timeAdd(m_lastTimeAssignmentStart, timeAssignment.timespan);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(bookingsIter == m_bookingsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
|
|
|
|
while(true)
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignmentsIter == m_timeAssignmentsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
errorMessage = tr("The last time assignment is finished without end booking\nTime assignment ID: %0")
|
2017-12-05 21:03:03 +01:00
|
|
|
.arg(timeAssignment.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
timeAssignment = *timeAssignmentsIter++;
|
|
|
|
|
if(timeAssignment.time != m_timeAssignmentTime)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
errorMessage = tr("Expected %0 but received %1 in time assignment.\nTime assignment ID: %2")
|
|
|
|
|
.arg(m_timeAssignmentTime.toString("HH:mm:ss"))
|
|
|
|
|
.arg(timeAssignment.time.toString("HH:mm:ss"))
|
|
|
|
|
.arg(timeAssignment.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
lastTimeAssignment = &timeAssignment;
|
2017-12-05 20:28:12 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->verticalLayout2->addWidget(new TimeAssignmentStrip(timeAssignment.id, timeAssignment.timespan, buildProjectString(timeAssignment.project),
|
|
|
|
|
timeAssignment.subproject, timeAssignment.workpackage, timeAssignment.text,
|
2017-12-03 22:47:36 +01:00
|
|
|
m_settings, ui->scrollAreaWidgetContents));
|
2017-12-02 12:41:49 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignment.timespan == QTime(0, 0))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignmentsIter != m_timeAssignmentsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
errorMessage = tr("There is another time assignment after an unfinished time assignment.\n"
|
|
|
|
|
"Time assignment ID: %0\nTime assignment ID: %1")
|
|
|
|
|
.arg(timeAssignment.id)
|
|
|
|
|
.arg(timeAssignmentsIter->id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->timeEditTime->setMinimumTime(timeAdd(m_lastTimeAssignmentStart, QTime(0, 1)));
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->pushButtonStart->setText(tr("Switch"));
|
|
|
|
|
ui->pushButtonEnd->setEnabled(true);
|
|
|
|
|
goto after;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
m_timeAssignmentTime = timeAdd(m_timeAssignmentTime, timeAssignment.timespan);
|
|
|
|
|
m_lastTimeAssignmentStart = timeAdd(m_lastTimeAssignmentStart, timeAssignment.timespan);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
auto endBooking = *bookingsIter++;
|
|
|
|
|
if(endBooking.type != QStringLiteral("G"))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
errorMessage = tr("Expected end booking, instead got type %0\nBooking ID: %1")
|
|
|
|
|
.arg(endBooking.type)
|
|
|
|
|
.arg(endBooking.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
lastBooking = &endBooking;
|
2017-12-05 20:28:12 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
bookingTimespan = timeAdd(bookingTimespan, timeBetween(startBooking.time, endBooking.time));
|
|
|
|
|
ui->timeEditTime->setMinimumTime(timeAdd(endBooking.time, QTime(0, 1)));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
while(m_timeAssignmentTime < bookingTimespan)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignmentsIter == m_timeAssignmentsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
errorMessage = tr("Missing time assignment! Missing: %0h")
|
|
|
|
|
.arg(timeBetween(m_timeAssignmentTime, bookingTimespan).toString("HH:mm:ss"));
|
2017-12-05 09:06:13 +01:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto label = new QLabel(errorMessage, ui->scrollAreaWidgetContents);
|
|
|
|
|
ui->verticalLayout2->addWidget(label);
|
|
|
|
|
label->setMinimumHeight(20);
|
|
|
|
|
label->setMaximumHeight(20);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
ui->verticalLayout2->addWidget(new BookingStrip(endBooking.id, endBooking.time, endBooking.type, m_settings, ui->scrollAreaWidgetContents));
|
2017-12-05 09:06:13 +01:00
|
|
|
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
timeAssignment = *timeAssignmentsIter++;
|
|
|
|
|
if(timeAssignment.time != m_timeAssignmentTime)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
errorMessage = tr("Expected %0 but received %1 in time assignment.\nTime assignment ID: %2")
|
|
|
|
|
.arg(m_timeAssignmentTime.toString("HH:mm:ss"))
|
|
|
|
|
.arg(timeAssignment.time.toString("HH:mm:ss"))
|
|
|
|
|
.arg(timeAssignment.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
lastTimeAssignment = &timeAssignment;
|
2017-12-05 20:28:12 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->verticalLayout2->addWidget(new TimeAssignmentStrip(timeAssignment.id, timeAssignment.timespan, buildProjectString(timeAssignment.project),
|
|
|
|
|
timeAssignment.subproject, timeAssignment.workpackage, timeAssignment.text,
|
2017-12-03 22:47:36 +01:00
|
|
|
m_settings, ui->scrollAreaWidgetContents));
|
2017-12-02 12:41:49 +01:00
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignment.timespan == QTime(0, 0))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
if(bookingsIter != m_bookingsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
errorMessage = tr("There is another booking after an unfinished time assignment.\n"
|
|
|
|
|
"Booking ID: %0\nTime assignment ID: %1")
|
|
|
|
|
.arg(bookingsIter->id)
|
2017-12-05 21:03:03 +01:00
|
|
|
.arg(timeAssignment.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignmentsIter != m_timeAssignmentsModel->constEnd())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
errorMessage = tr("There is another time assignment after an unfinished time assignment.\nTime assignment ID: %0\nTime assignment ID: %1")
|
|
|
|
|
.arg(timeAssignmentsIter->id)
|
|
|
|
|
.arg(timeAssignment.id);
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
ui->timeEditTime->setMinimumTime(timeAdd(m_lastTimeAssignmentStart, QTime(0, 1)));
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->pushButtonStart->setText(tr("Switch"));
|
|
|
|
|
ui->pushButtonEnd->setEnabled(true);
|
|
|
|
|
goto after;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
m_timeAssignmentTime = timeAdd(m_timeAssignmentTime, timeAssignment.timespan);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-02 11:43:38 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(m_timeAssignmentTime > bookingTimespan)
|
2017-12-02 12:41:49 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
errorMessage = tr("Time assignment time longer than booking time! Time assignment: %0 Booking: %1")
|
2017-12-05 21:03:03 +01:00
|
|
|
.arg(m_timeAssignmentTime.toString("HH:mm:ss"))
|
2017-12-05 21:36:47 +01:00
|
|
|
.arg(bookingTimespan.toString("HH:mm:ss"));
|
2017-12-05 09:06:13 +01:00
|
|
|
|
|
|
|
|
auto label = new QLabel(errorMessage, ui->scrollAreaWidgetContents);
|
2017-12-02 12:48:09 +01:00
|
|
|
ui->verticalLayout2->addWidget(label);
|
2017-12-02 12:41:49 +01:00
|
|
|
label->setMinimumHeight(20);
|
|
|
|
|
label->setMaximumHeight(20);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
ui->verticalLayout2->addWidget(new BookingStrip(endBooking.id, endBooking.time, endBooking.type, m_settings, ui->scrollAreaWidgetContents));
|
2017-12-02 12:41:49 +01:00
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
if(m_timeAssignmentTime > bookingTimespan)
|
2017-12-02 12:41:49 +01:00
|
|
|
goto after;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 12:48:09 +01:00
|
|
|
after:
|
2017-12-05 20:28:12 +01:00
|
|
|
if(errorMessage.isEmpty())
|
2017-12-05 21:16:46 +01:00
|
|
|
m_workingTimeLabel->setText(tr("%0: %1").arg(tr("Assigned time")).arg(tr("%0h").arg(m_timeAssignmentTime.toString(QStringLiteral("HH:mm")))));
|
2017-12-05 20:28:12 +01:00
|
|
|
else
|
2017-12-02 12:41:49 +01:00
|
|
|
{
|
2017-12-02 12:48:09 +01:00
|
|
|
auto label = new QLabel(tr("Strip rendering aborted due error."), ui->scrollAreaWidgetContents);
|
|
|
|
|
ui->verticalLayout2->addWidget(label);
|
2017-12-02 12:41:49 +01:00
|
|
|
label->setMinimumHeight(20);
|
|
|
|
|
label->setMaximumHeight(20);
|
|
|
|
|
}
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-02 12:41:49 +01:00
|
|
|
ui->verticalLayout2->addStretch(1);
|
|
|
|
|
|
|
|
|
|
if(!errorMessage.isEmpty())
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
QMessageBox::warning(this, tr("Illegal state!"), tr("Your bookings and time assignments for this day are in an illegal state!") % "\n\n" % errorMessage);
|
2017-12-02 12:41:49 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
ui->timeEditTime->setEnabled(true);
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setEnabled(true);
|
|
|
|
|
ui->comboBoxSubproject->setEnabled(true);
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->setEnabled(true);
|
|
|
|
|
ui->comboBoxText->setEnabled(true);
|
|
|
|
|
ui->pushButtonStart->setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateComboboxes()
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->clear();
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
auto preferedProjects = m_settings.projects();
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
for(const auto &preferedProject : preferedProjects)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
if(!m_projects.contains(preferedProject))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
qWarning() << "cannot find project" << preferedProject;
|
2017-12-02 19:11:49 +01:00
|
|
|
continue;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
2017-12-02 19:11:49 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->addItem(m_projects.value(preferedProject) % " (" % preferedProject % ')', preferedProject);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
if(preferedProjects.count())
|
|
|
|
|
ui->comboBoxProject->insertSeparator(ui->comboBoxProject->count());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
for(auto iter = m_projects.constBegin(); iter != m_projects.constEnd(); iter++)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
if(!preferedProjects.contains(iter.key()))
|
|
|
|
|
ui->comboBoxProject->addItem(iter.value() % " (" % iter.key() % ')', iter.key());
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxSubproject->clear();
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
auto subprojects = m_settings.subprojects();
|
|
|
|
|
for(const auto &subproject : subprojects)
|
|
|
|
|
ui->comboBoxSubproject->addItem(subproject);
|
|
|
|
|
if(subprojects.count())
|
|
|
|
|
ui->comboBoxSubproject->setCurrentText(QString());
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->comboBoxWorkpackage->clear();
|
|
|
|
|
|
|
|
|
|
{
|
2017-12-03 22:22:07 +01:00
|
|
|
auto workpackages = m_settings.workpackages();
|
2017-12-02 10:50:30 +01:00
|
|
|
for(const auto &workpackage : workpackages)
|
|
|
|
|
ui->comboBoxWorkpackage->addItem(workpackage);
|
|
|
|
|
if(workpackages.count())
|
|
|
|
|
ui->comboBoxWorkpackage->setCurrentText(QString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->comboBoxText->clear();
|
|
|
|
|
|
|
|
|
|
{
|
2017-12-03 22:22:07 +01:00
|
|
|
auto texte = m_settings.texte();
|
2017-12-02 10:50:30 +01:00
|
|
|
for(const auto &text : texte)
|
|
|
|
|
ui->comboBoxText->addItem(text);
|
|
|
|
|
if(texte.count())
|
|
|
|
|
ui->comboBoxText->setCurrentText(QString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 11:43:38 +01:00
|
|
|
void MainWindow::clearStrips()
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-02 11:43:38 +01:00
|
|
|
QLayoutItem *item;
|
|
|
|
|
while(item = ui->verticalLayout2->takeAt(0))
|
|
|
|
|
{
|
2017-12-02 21:37:26 +01:00
|
|
|
delete item->widget();
|
2017-12-02 11:43:38 +01:00
|
|
|
delete item;
|
|
|
|
|
}
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
2017-12-02 19:17:10 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
QString MainWindow::buildProjectString(const QString &project)
|
2017-12-02 19:17:10 +01:00
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
if(m_projects.contains(project))
|
|
|
|
|
return m_projects.value(project) % " (" % project % ")";
|
2017-12-02 19:17:10 +01:00
|
|
|
else
|
2017-12-04 20:25:33 +01:00
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
qWarning() << "could not find project" << project;
|
|
|
|
|
return project;
|
2017-12-04 20:25:33 +01:00
|
|
|
}
|
2017-12-02 19:17:10 +01:00
|
|
|
}
|