Added Auswertung to MainWindow
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
@@ -9,6 +10,9 @@
|
||||
#include <QStringBuilder>
|
||||
#include <QMenu>
|
||||
#include <QLabel>
|
||||
#include <QDir>
|
||||
#include <QTemporaryFile>
|
||||
#include <QDesktopServices>
|
||||
#include <QDebug>
|
||||
|
||||
#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;
|
||||
|
@@ -27,6 +27,7 @@ public:
|
||||
private Q_SLOTS:
|
||||
void refresh();
|
||||
void getProjekteFinished(bool success, const QString &message, const QVector<Zeiterfassung::Projekt> &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<Zeiterfassung::Projekt> m_projekte;
|
||||
QByteArray m_auswertung;
|
||||
|
||||
BuchungenModel *m_buchungenModel;
|
||||
KontierungenModel *m_kontierungenModel;
|
||||
|
@@ -271,8 +271,15 @@
|
||||
<addaction name="actionToday"/>
|
||||
<addaction name="actionRefresh"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Tools">
|
||||
<property name="title">
|
||||
<string>&Tools</string>
|
||||
</property>
|
||||
<addaction name="actionAuswertung"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menu_View"/>
|
||||
<addaction name="menu_Tools"/>
|
||||
<addaction name="menu_About"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
@@ -324,6 +331,14 @@
|
||||
<string>&Refresh</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAuswertung">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Auswertung</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user