From f4d7748ea50540306d0f8e1ed3e82fa50e6dd51e Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 <0xFEEDC0DE64@gmail.com> Date: Sat, 2 Dec 2017 18:46:46 +0100 Subject: [PATCH] Added Auswertung to MainWindow --- mainwindow.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++- mainwindow.h | 3 +++ mainwindow.ui | 15 +++++++++++++ zeiterfassung.cpp | 12 +++++----- 4 files changed, 80 insertions(+), 7 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index ae89e6c..1e32bdc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include #include #include #include @@ -9,6 +10,9 @@ #include #include #include +#include +#include +#include #include #include "eventloopwithstatus.h" @@ -41,6 +45,28 @@ MainWindow::MainWindow(QSettings &settings, Zeiterfassung &erfassung, const Zeit ui->actionRefresh->setShortcut(QKeySequence::Refresh); connect(ui->actionRefresh, &QAction::triggered, this, &MainWindow::refresh); + connect(ui->actionAuswertung, &QAction::triggered, [=](){ + QTemporaryFile file(QDir::temp().absoluteFilePath("auswertungXXXXXX.pdf")); + file.setAutoRemove(false); + if(!file.open()) + { + QMessageBox::warning(this, tr("Could not open auswertung!"), tr("Auswertung could not be written:\n\n%0") + .arg(file.errorString())); + return; + } + + file.write(m_auswertung); + file.close(); + + qDebug() << file.fileName(); + + if(!QDesktopServices::openUrl(QUrl::fromLocalFile(file.fileName()))) + { + QMessageBox::warning(this, tr("Could not open auswertung!"), tr("Could not open default PDF viewer!")); + return; + } + }); + connect(ui->actionAboutMe, &QAction::triggered, [=](){ AboutMeDialog(userInfo, this).exec(); }); connect(ui->actionAboutQt, &QAction::triggered, [=](){ QMessageBox::aboutQt(this); }); @@ -76,7 +102,7 @@ MainWindow::MainWindow(QSettings &settings, Zeiterfassung &erfassung, const Zeit connect(ui->treeViewKontierungen, &QWidget::customContextMenuRequested, this, &MainWindow::contextMenuKontierung); - erfassung.doGetAuswertung(userInfo.userId, QDate::currentDate()); + updateAuswertung(); } MainWindow::~MainWindow() @@ -170,6 +196,23 @@ void MainWindow::getProjekteFinished(bool success, const QString &message, const updateComboboxes(); } +void MainWindow::getAuswertungFinished(bool success, const QString &message, const QByteArray &content) +{ + disconnect(&m_erfassung, &Zeiterfassung::getAuswertungFinished, + this, &MainWindow::getAuswertungFinished); + + if(!success) + { + QMessageBox::warning(this, tr("Could not load Auswertung!"), tr("Could not load Auswertung:\n\n%0").arg(message)); + return; + } + + ui->actionAuswertung->setEnabled(true); + m_auswertung = content; + + //TODO: parse content +} + void MainWindow::refreshBuchungenFinished(bool success, const QString &message) { disconnect(m_buchungenModel, &BuchungenModel::refreshFinished, @@ -1058,6 +1101,18 @@ void MainWindow::updateComboboxes() } } +void MainWindow::updateAuswertung() +{ + ui->actionAuswertung->setEnabled(false); + m_auswertung.clear(); + + if(m_erfassung.doGetAuswertung(m_userInfo.userId, QDate::currentDate())) + connect(&m_erfassung, &Zeiterfassung::getAuswertungFinished, + this, &MainWindow::getAuswertungFinished); + else + QMessageBox::warning(this, tr("Unknown error occured."), tr("An unknown error occured.")); +} + void MainWindow::clearStrips() { QLayoutItem *item; diff --git a/mainwindow.h b/mainwindow.h index 3eb7b8d..90b80d6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,6 +27,7 @@ public: private Q_SLOTS: void refresh(); void getProjekteFinished(bool success, const QString &message, const QVector &projekte); + void getAuswertungFinished(bool success, const QString &message, const QByteArray &content); void refreshBuchungenFinished(bool success, const QString &message); void refreshKontierungenFinished(bool success, const QString &message); void contextMenuBuchung(const QPoint &pos); @@ -39,6 +40,7 @@ private Q_SLOTS: private: void validateEntries(); void updateComboboxes(); + void updateAuswertung(); void clearStrips(); Ui::MainWindow *ui; @@ -46,6 +48,7 @@ private: Zeiterfassung &m_erfassung; const Zeiterfassung::UserInfo &m_userInfo; QVector m_projekte; + QByteArray m_auswertung; BuchungenModel *m_buchungenModel; KontierungenModel *m_kontierungenModel; diff --git a/mainwindow.ui b/mainwindow.ui index 8947b0c..e79a0c0 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -271,8 +271,15 @@ + + + &Tools + + + + @@ -324,6 +331,14 @@ &Refresh + + + false + + + &Auswertung + + diff --git a/zeiterfassung.cpp b/zeiterfassung.cpp index 106156d..7b362a7 100644 --- a/zeiterfassung.cpp +++ b/zeiterfassung.cpp @@ -841,7 +841,7 @@ void Zeiterfassung::getAuswertungRequest0Finished() { if(m_replies.getAuswertung->error() != QNetworkReply::NoError) { - Q_EMIT getAuswertungFinished(false, tr("Request error occured: %0").arg(m_replies.getProjekte->error()), QByteArray()); + Q_EMIT getAuswertungFinished(false, tr("Request error occured: %0").arg(m_replies.getAuswertung->error()), QByteArray()); m_replies.getAuswertung->deleteLater(); m_replies.getAuswertung = Q_NULLPTR; return; @@ -859,15 +859,15 @@ void Zeiterfassung::getAuswertungRequest0Finished() void Zeiterfassung::getAuswertungRequest1Finished() { - if(m_replies.getProjekte->error() != QNetworkReply::NoError) + if(m_replies.getAuswertung->error() != QNetworkReply::NoError) { - Q_EMIT getAuswertungFinished(false, tr("Request error occured: %0").arg(m_replies.getProjekte->error()), QByteArray()); + Q_EMIT getAuswertungFinished(false, tr("Request error occured: %0").arg(m_replies.getAuswertung->error()), QByteArray()); goto end; } - Q_EMIT getAuswertungFinished(true, QString(), m_replies.getProjekte->readAll()); + Q_EMIT getAuswertungFinished(true, QString(), m_replies.getAuswertung->readAll()); end: - m_replies.getProjekte->deleteLater(); - m_replies.getProjekte = Q_NULLPTR; + m_replies.getAuswertung->deleteLater(); + m_replies.getAuswertung = Q_NULLPTR; }