Reports plugin #34

Merged
0xFEEDC0DE64 merged 7 commits from reports-plugin into devel 2017-12-19 00:18:52 +01:00
33 changed files with 369 additions and 202 deletions
Showing only changes of commit a14a108830 - Show all commits

View File

@@ -2,7 +2,6 @@
#include <QDebug>
#include "mainwindow.h"
#include "presencewidget.h"
PresencePlugin::PresencePlugin(QObject *parent) :

View File

@@ -13,6 +13,7 @@ class MainWindow;
class PresenceWidget : public QWidget
{
Q_OBJECT
public:
explicit PresenceWidget(MainWindow &mainWindow);

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@@ -2,6 +2,8 @@
#include <QDebug>
#include "reportswidget.h"
ReportsPlugin::ReportsPlugin(QObject *parent) :
ZeiterfassungPlugin(parent)
{
@@ -10,4 +12,5 @@ ReportsPlugin::ReportsPlugin(QObject *parent) :
void ReportsPlugin::attachTo(MainWindow &mainWindow)
{
new ReportsWidget(mainWindow);
}

View File

@@ -14,13 +14,15 @@ DEPENDPATH += $$PWD/../../zeiterfassunglib
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT
HEADERS += reportsplugin.h
HEADERS += reportsplugin.h \
reportswidget.h
SOURCES += reportsplugin.cpp
SOURCES += reportsplugin.cpp \
reportswidget.cpp
FORMS +=
RESOURCES +=
RESOURCES += reportsplugin_resources.qrc
TRANSLATIONS +=

View File

@@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/zeiterfassung/plugins/reportsplugin">
<file>images/refresh.png</file>
<file>images/report.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,145 @@
#include "reportswidget.h"
#include <QLabel>
#include <QStatusBar>
#include <QMenu>
#include <QToolBar>
#include <QMessageBox>
#include <QStringBuilder>
#include <QRegularExpression>
#include <QTemporaryFile>
#include <QDir>
#include <QDesktopServices>
#include "mainwindow.h"
#include "zeiterfassungapi.h"
ReportsWidget::ReportsWidget(MainWindow &mainWindow) :
QWidget(&mainWindow),
m_mainWindow(mainWindow)
{
m_labelBalance = new QLabel(this);
m_labelBalance->setFrameShape(QFrame::Panel);
m_labelBalance->setFrameShadow(QFrame::Sunken);
m_mainWindow.statusBar()->addPermanentWidget(m_labelBalance);
m_labelHolidays = new QLabel(this);
m_labelHolidays->setFrameShape(QFrame::Panel);
m_labelHolidays->setFrameShadow(QFrame::Sunken);
m_mainWindow.statusBar()->addPermanentWidget(m_labelHolidays);
m_actionRefreshReport = m_mainWindow.menuView()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/reportsplugin/images/refresh.png")),
tr("Refresh report"), this, &ReportsWidget::refresh);
m_actionOpenReport = m_mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/reportsplugin/images/report.png")),
tr("Open report"), this, &ReportsWidget::openReport);
m_mainWindow.toolBar()->addAction(m_actionOpenReport);
dateChanged(m_mainWindow.date());
}
void ReportsWidget::dateChanged(const QDate &date)
{
if(!date.isValid())
{
qWarning() << "invalid date" << date;
return;
}
auto monthBegin = QDate(date.year(), date.month(), 1);
if(monthBegin != m_date)
{
m_date = monthBegin;
refresh();
}
}
void ReportsWidget::refresh()
{
if(!m_date.isValid())
{
qWarning() << "invalid date" << m_date;
return;
}
m_actionRefreshReport->setEnabled(false);
m_actionOpenReport->setEnabled(false);
m_labelBalance->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("???")));
m_labelHolidays->setText(tr("%0: %1").arg(tr("Holidays")).arg(tr("???")));
m_reply = m_mainWindow.erfassung().doGetAuswertung(m_mainWindow.userInfo().userId, m_date);
connect(m_reply.get(), &ZeiterfassungReply::finished, this, &ReportsWidget::finished);
}
void ReportsWidget::finished()
{
if(!m_reply->success())
{
m_date = QDate();
QMessageBox::warning(this, tr("Could not load report!"), tr("Could not load report!") % "\n\n" % m_reply->message());
goto after;
}
{
auto content = m_reply->auswertung();
{
static QRegularExpression regex(QStringLiteral("Gleitzeit +([0-9]+\\:[0-9]+\\-?) +([0-9]+\\:[0-9]+\\-?)"));
auto match = regex.match(content);
if(match.hasMatch())
{
auto balance = match.captured(2);
if(balance.endsWith(QChar('-')))
{
balance.chop(1);
balance = QChar('-') % balance;
}
m_labelBalance->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("%0h").arg(balance)));
}
else
{
m_labelBalance->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("n/a")));
qWarning() << "balance not found in PDF";
}
}
{
static QRegularExpression regex(QStringLiteral("Urlaubsanspruch +([0-9]+\\.[0-9]+\\-?) +([0-9]+\\.[0-9]+\\-?)"));
auto match = regex.match(content);
if(match.hasMatch())
m_labelHolidays->setText(tr("%0: %1").arg(tr("Holidays")).arg(match.captured(2)));
else
{
m_labelHolidays->setText(tr("%0: %1").arg(tr("Holidays")).arg(tr("n/a")));
qWarning() << "holidays not found in PDF";
}
}
{
QTemporaryFile file(QDir::temp().absoluteFilePath(QStringLiteral("auswertungXXXXXX.pdf")));
file.setAutoRemove(false);
if(!file.open())
{
QMessageBox::warning(this, tr("Could not write report!"), tr("Could not write report!") % "\n\n" % file.errorString());
goto after;
}
file.write(content);
m_url = QUrl::fromLocalFile(file.fileName());
}
}
m_actionOpenReport->setEnabled(true);
after:
m_actionRefreshReport->setEnabled(true);
m_reply = Q_NULLPTR;
}
void ReportsWidget::openReport()
{
if(!QDesktopServices::openUrl(m_url))
QMessageBox::warning(this, tr("Could not launch your default PDF viewer!"), tr("Could not launch your default PDF viewer!"));
}

View File

@@ -0,0 +1,43 @@
#ifndef REPORTSWIDGET_H
#define REPORTSWIDGET_H
#include <QWidget>
#include <QDate>
#include <QUrl>
#include "replies/getauswertungreply.h"
class QLabel;
class QAction;
class MainWindow;
class ReportsWidget : public QWidget
{
Q_OBJECT
public:
explicit ReportsWidget(MainWindow &mainWindow);
private Q_SLOTS:
void dateChanged(const QDate &date);
void refresh();
void finished();
void openReport();
private:
MainWindow &m_mainWindow;
QLabel *m_labelBalance;
QLabel *m_labelHolidays;
QAction *m_actionOpenReport;
QAction *m_actionRefreshReport;
QDate m_date;
QUrl m_url;
std::unique_ptr<GetAuswertungReply> m_reply;
};
#endif // REPORTSWIDGET_H

View File

@@ -22,7 +22,6 @@
#include "dialogs/aboutmedialog.h"
#include "dialogs/settingsdialog.h"
#include "replies/getprojectsreply.h"
#include "replies/getauswertungreply.h"
#include "replies/createbookingreply.h"
#include "replies/createtimeassignmentreply.h"
#include "replies/updatetimeassignmentreply.h"
@@ -35,8 +34,6 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass
m_erfassung(erfassung),
m_userInfo(userInfo),
m_stripFactory(stripFactory),
m_getProjectsReply(Q_NULLPTR),
m_getAuswertungReply(Q_NULLPTR),
m_currentStripWidget(Q_NULLPTR)
{
ui->setupUi(this);
@@ -57,8 +54,6 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass
ui->actionRefresh->setShortcut(QKeySequence::Refresh);
connect(ui->actionRefresh, &QAction::triggered, this, [=](){ dateChanged(true); });
connect(ui->actionAuswertung, &QAction::triggered, this, &MainWindow::openAuswertung);
connect(ui->actionAboutMe, &QAction::triggered, [=](){ AboutMeDialog(userInfo, this).exec(); });
connect(ui->actionSettings, &QAction::triggered, [=](){ SettingsDialog(m_settings, this).exec(); });
@@ -88,13 +83,6 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass
connect(ui->pushButtonStart, &QAbstractButton::pressed, this, &MainWindow::pushButtonStartPressed);
connect(ui->pushButtonEnd, &QAbstractButton::pressed, this, &MainWindow::pushButtonEndPressed);
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);
dateChanged();
}
@@ -123,6 +111,11 @@ QMenu *MainWindow::menuAbout() const
return ui->menuAbout;
}
QToolBar *MainWindow::toolBar() const
{
return ui->mainToolBar;
}
ZeiterfassungSettings &MainWindow::settings() const
{
return m_settings;
@@ -143,6 +136,11 @@ StripFactory &MainWindow::stripFactory() const
return m_stripFactory;
}
QDate MainWindow::date() const
{
return ui->dateEditDate->date();
}
const QMap<QString, QString> &MainWindow::projects() const
{
return m_projects;
@@ -171,66 +169,6 @@ void MainWindow::getProjectsFinished()
m_getProjectsReply = Q_NULLPTR;
}
void MainWindow::getAuswertungFinished()
{
if(std::none_of(std::begin(m_stripsWidgets), std::end(m_stripsWidgets), [](StripsWidget *stripsWidget){
return stripsWidget->refreshing();
}))
{
ui->actionToday->setEnabled(true);
ui->actionRefresh->setEnabled(true);
ui->dateEditDate->setReadOnly(false);
ui->pushButtonPrev->setEnabled(true);
ui->pushButtonNext->setEnabled(true);
}
if(!m_getAuswertungReply->success())
{
m_auswertungDate = QDate();
QMessageBox::warning(this, tr("Could not load Auswertung!"), tr("Could not load Auswertung!") % "\n\n" % m_getAuswertungReply->message());
m_getAuswertungReply = Q_NULLPTR;
return;
}
ui->actionAuswertung->setEnabled(true);
m_auswertung = m_getAuswertungReply->auswertung();
auto urlaubsAnspruch = tr("n/a");
{
static QRegularExpression regex(QStringLiteral("Urlaubsanspruch +([0-9]+\\.[0-9]+\\-?) +([0-9]+\\.[0-9]+\\-?)"));
auto match = regex.match(m_auswertung);
if(match.hasMatch())
urlaubsAnspruch = match.captured(2);
else
qWarning() << "Urlaubsanspruch not found";
}
auto gleitzeit = tr("n/a");
{
static QRegularExpression regex(QStringLiteral("Gleitzeit +([0-9]+\\:[0-9]+\\-?) +([0-9]+\\:[0-9]+\\-?)"));
auto match = regex.match(m_auswertung);
if(match.hasMatch())
{
gleitzeit = match.captured(2);
if(gleitzeit.endsWith(QChar('-')))
{
gleitzeit.chop(1);
gleitzeit = QChar('-') % gleitzeit;
}
gleitzeit = tr("%0h").arg(gleitzeit);
}
else
qWarning() << "Gleitzeit not found";
}
m_balanceLabel->setText(tr("%0: %1").arg(tr("Balance")).arg(gleitzeit));
m_holidaysLabel->setText(tr("%0: %1").arg(tr("Holidays")).arg(urlaubsAnspruch));
m_getAuswertungReply = Q_NULLPTR;
}
void MainWindow::pushButtonStartPressed()
{
auto bookingsChanged = false;
@@ -307,8 +245,7 @@ void MainWindow::pushButtonStartPressed()
if(bookingsChanged)
{
m_currentStripWidget->refresh();
refreshAuswertung();
//refreshAuswertung();
}
else
m_currentStripWidget->refreshTimeAssignments();
@@ -359,7 +296,7 @@ void MainWindow::pushButtonEndPressed()
}
m_currentStripWidget->refresh();
refreshAuswertung();
//refreshAuswertung();
ui->actionToday->setEnabled(false);
ui->actionRefresh->setEnabled(false);
@@ -400,12 +337,9 @@ void MainWindow::dateChanged(bool force)
}
}
if(force || m_auswertungDate != QDate(ui->dateEditDate->date().year(), ui->dateEditDate->date().month(), 1))
refreshAuswertung();
if(std::any_of(std::begin(m_stripsWidgets), std::end(m_stripsWidgets), [](StripsWidget *stripsWidget) {
return stripsWidget->refreshing();
}) || m_getAuswertungReply)
}))
{
ui->actionToday->setEnabled(false);
ui->actionRefresh->setEnabled(false);
@@ -415,26 +349,6 @@ void MainWindow::dateChanged(bool force)
}
}
void MainWindow::openAuswertung()
{
QTemporaryFile file(QDir::temp().absoluteFilePath(QStringLiteral("auswertungXXXXXX.pdf")));
file.setAutoRemove(false);
if(!file.open())
{
QMessageBox::warning(this, tr("Could not open auswertung!"), tr("Could not open auswertung!") % "\n\n" % file.errorString());
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;
}
}
void MainWindow::minimumTimeChanged()
{
ui->timeEditTime->setMinimumTime(m_currentStripWidget->minimumTime());
@@ -442,9 +356,6 @@ void MainWindow::minimumTimeChanged()
void MainWindow::refreshingChanged()
{
if(m_getAuswertungReply)
return;
{
auto allFinished = std::none_of(std::begin(m_stripsWidgets), std::end(m_stripsWidgets), [](StripsWidget *stripsWidget){
return stripsWidget->refreshing();
@@ -487,19 +398,6 @@ void MainWindow::endEnabledChanged()
ui->pushButtonEnd->setEnabled(endEnabled);
}
void MainWindow::refreshAuswertung()
{
m_balanceLabel->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("???")));
m_holidaysLabel->setText(tr("%0: %1").arg(tr("Holidays")).arg(tr("???")));
ui->actionAuswertung->setEnabled(false);
m_auswertung.clear();
m_auswertungDate = QDate(ui->dateEditDate->date().year(), ui->dateEditDate->date().month(), 1);
m_getAuswertungReply = m_erfassung.doGetAuswertung(m_userInfo.userId, m_auswertungDate);
connect(m_getAuswertungReply.get(), &ZeiterfassungReply::finished, this, &MainWindow::getAuswertungFinished);
}
void MainWindow::updateComboboxes()
{
ui->comboBoxProject->clear();

View File

@@ -9,9 +9,10 @@
#include "zeiterfassunglib_global.h"
#include "replies/getuserinforeply.h"
#include "replies/getprojectsreply.h"
#include "replies/getauswertungreply.h"
#include "replies/getpresencestatusreply.h"
class QMenu;
class QToolBar;
class QLabel;
class QBoxLayout;
@@ -33,22 +34,23 @@ public:
QMenu *menuView() const;
QMenu *menuTools() const;
QMenu *menuAbout() const;
QToolBar *toolBar() const;
ZeiterfassungSettings &settings() const;
ZeiterfassungApi &erfassung() const;
const GetUserInfoReply::UserInfo &userInfo() const;
StripFactory &stripFactory() const;
QDate date() const;
const QMap<QString, QString> &projects() const;
const std::array<StripsWidget*, 7> &stripsWidgets() const;
private Q_SLOTS:
void getProjectsFinished();
void getAuswertungFinished();
void pushButtonStartPressed();
void pushButtonEndPressed();
void dateChanged(bool force = false);
void openAuswertung();
void minimumTimeChanged();
void refreshingChanged();
@@ -56,7 +58,6 @@ private Q_SLOTS:
void endEnabledChanged();
private:
void refreshAuswertung();
void updateComboboxes();
Ui::MainWindow *ui;
@@ -66,16 +67,9 @@ private:
StripFactory &m_stripFactory;
std::unique_ptr<GetProjectsReply> m_getProjectsReply;
std::unique_ptr<GetAuswertungReply> m_getAuswertungReply;
QMap<QString, QString> m_projects;
QDate m_auswertungDate;
QByteArray m_auswertung;
QLabel *m_balanceLabel;
QLabel *m_holidaysLabel;
std::array<StripsWidget*, 7> m_stripsWidgets;
StripsWidget *m_currentStripWidget;
};

View File

@@ -229,7 +229,6 @@
<property name="title">
<string>&amp;Tools</string>
</property>
<addaction name="actionAuswertung"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuView"/>
@@ -245,8 +244,6 @@
</attribute>
<addaction name="actionToday"/>
<addaction name="actionRefresh"/>
<addaction name="actionAuswertung"/>
<addaction name="actionSettings"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionQuit">
@@ -299,15 +296,6 @@
<string>&amp;Refresh everything</string>
</property>
</action>
<action name="actionAuswertung">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/zeiterfassunglib/images/auswertung.png</normaloff>:/zeiterfassunglib/images/auswertung.png</iconset>
</property>
<property name="text">
<string>&amp;Auswertung</string>
</property>
</action>
<action name="actionSettings">
<property name="icon">
<iconset resource="resources.qrc">

View File

@@ -1,7 +1,6 @@
<RCC>
<qresource prefix="/zeiterfassunglib">
<file>images/about.png</file>
<file>images/auswertung.png</file>
<file>images/authentication.png</file>
<file>images/help.png</file>
<file>images/icon.png</file>