From 5446c17ad76a0e3b768359be73e3da08b7bc1179 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Wed, 23 Oct 2019 17:02:00 +0200 Subject: [PATCH] =?UTF-8?q?=C3=9Cberstunden=20Berechnung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cbooking.cpp | 15 +++++++++------ cmainwindow.cpp | 2 +- cmonthlybooking.cpp | 10 +++++----- cmonthlybooking.h | 6 +++--- cmonthlyview.cpp | 18 ++++++++++++------ cmonthlyview.h | 5 ++++- cmonthlyview.ui | 19 ++++++------------- common.cpp | 14 ++++++++++++-- common.h | 3 ++- 9 files changed, 54 insertions(+), 38 deletions(-) diff --git a/cbooking.cpp b/cbooking.cpp index 2c5a440..263f6e1 100644 --- a/cbooking.cpp +++ b/cbooking.cpp @@ -518,6 +518,8 @@ void cBookingList::recalculate(const QDate& date) if(i == begin()) bFirst = true; + qint32 ueberstunden = 0; + for(;i != end(); i++) { cVacation* lpVacation = m_lpVacationList->find((*i)->date()); @@ -526,12 +528,6 @@ void cBookingList::recalculate(const QDate& date) else (*i)->setVacation(oldVacation); - cMonthlyBooking* lpMonthlyBooking = m_lpMonthlyBookingList->find((*i)->date()); - qint32 ueberstunden = 0; - - if(lpMonthlyBooking) - ueberstunden = time2Secs(lpMonthlyBooking->ueberstunden()); - if(bFirst) { bFirst = false; @@ -540,6 +536,13 @@ void cBookingList::recalculate(const QDate& date) else (*i)->setPrevDiff((*(i-1))->currentDiff()-ueberstunden); + cMonthlyBooking* lpMonthlyBooking = m_lpMonthlyBookingList->find((*i)->date()); + + if(lpMonthlyBooking) + ueberstunden = lpMonthlyBooking->ueberstunden(); + else + ueberstunden = 0; + oldVacation = (*i)->vacation(); if((*i)->code() == "U") diff --git a/cmainwindow.cpp b/cmainwindow.cpp index d1158d6..6f3f59d 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -157,7 +157,7 @@ void cMainWindow::openDB() query.prepare("CREATE TABLE monthlyBooking " "( " " datum DATE PRIMARY KEY UNIQUE, " - " ueberstunden TIME " + " ueberstunden INTEGER " ");"); if(!query.exec()) diff --git a/cmonthlybooking.cpp b/cmonthlybooking.cpp index 221cc1d..21e12d9 100644 --- a/cmonthlybooking.cpp +++ b/cmonthlybooking.cpp @@ -8,7 +8,7 @@ cMonthlyBooking::cMonthlyBooking(const QDate& date, QObject *parent) : QObject(parent), m_date(date), - m_ueberstunden(QTime(0, 0, 0)) + m_ueberstunden(0) { } @@ -17,12 +17,12 @@ QDate cMonthlyBooking::date() return(m_date); } -void cMonthlyBooking::setUeberstunden(const QTime &time) +void cMonthlyBooking::setUeberstunden(qint32 ueberstunden) { - m_ueberstunden = time; + m_ueberstunden = ueberstunden; } -QTime cMonthlyBooking::ueberstunden() +qint32 cMonthlyBooking::ueberstunden() { return(m_ueberstunden); } @@ -89,7 +89,7 @@ bool cMonthlyBookingList::load() if(lpBooking) { - lpBooking->setUeberstunden(query.value("ueberstunden").toTime()); + lpBooking->setUeberstunden(query.value("ueberstunden").toInt()); } } diff --git a/cmonthlybooking.h b/cmonthlybooking.h index 6bfb17a..03af2ce 100644 --- a/cmonthlybooking.h +++ b/cmonthlybooking.h @@ -18,14 +18,14 @@ public: QDate date(); - void setUeberstunden(const QTime& time); - QTime ueberstunden(); + void setUeberstunden(qint32 ueberstunden); + qint32 ueberstunden(); bool save(); private: QDate m_date; - QTime m_ueberstunden; + qint32 m_ueberstunden; signals: diff --git a/cmonthlyview.cpp b/cmonthlyview.cpp index 3fa6039..23a231d 100644 --- a/cmonthlyview.cpp +++ b/cmonthlyview.cpp @@ -3,6 +3,7 @@ #include "common.h" +#include #include @@ -14,7 +15,8 @@ cMonthlyView::cMonthlyView(const QDate& date, cMonthlyBookingList* lpMonthlyBook m_lpPublicHoliday(lpPublicHoliday), m_lpBookingList(lpBookingList), m_date(date), - m_lpMonthlyBooking(nullptr) + m_lpMonthlyBooking(nullptr), + m_lpValidator(nullptr) { m_code.insert(" ", tr("")); m_code.insert("G", tr("Gleitzeit")); @@ -25,6 +27,10 @@ cMonthlyView::cMonthlyView(const QDate& date, cMonthlyBookingList* lpMonthlyBook ui->setupUi(this); + QRegExp rx("(?:\\d\\d\\d):(?:[0-5]\\d):(?:[0-5]\\d)"); + m_lpValidator = new QRegExpValidator(rx, this); + ui->m_lpUeberstunden->setValidator(m_lpValidator); + m_lpMonthlyListModel = new QStandardItemModel(0, 1); ui->m_lpMonthlyList->setModel(m_lpMonthlyListModel); @@ -48,7 +54,7 @@ cMonthlyView::cMonthlyView(const QDate& date, cMonthlyBookingList* lpMonthlyBook connect(static_cast(ui->m_lpMonthlyList->itemDelegate()), &cMonthlyItemDelegate::textChanged, this, &cMonthlyView::onTextChanged); connect(ui->m_lpMonth, &QDateEdit::dateChanged, this, &cMonthlyView::onDateChanged); - connect(ui->m_lpUeberstunden, &QTimeEdit::timeChanged, this, &cMonthlyView::onUeberstundenChanged); + connect(ui->m_lpUeberstunden, &QLineEdit::textChanged, this, &cMonthlyView::onUeberstundenChanged); } void cMonthlyView::setDate(const QDate& date) @@ -196,7 +202,7 @@ void cMonthlyView::setDate(const QDate& date) ui->m_lpShouldLabel->setText(QString(tr("SOLL Arbeitszeit (%1):")).arg(date.toString("MMMM yyyy"))); ui->m_lpIsLabel->setText(QString(tr("IST Arbeitszeit (%1):")).arg(date.toString("MMMM yyyy"))); ui->m_lpResturlaubLabel->setText(QString(tr("Resturlaub %1:")).arg(date.addMonths(-1).toString("MMMM yyyy"))); - ui->m_lpUeberstunden->setTime(m_lpMonthlyBooking->ueberstunden()); + ui->m_lpUeberstunden->setText(secs2String(m_lpMonthlyBooking->ueberstunden(), 3)); displaySummary(); @@ -307,9 +313,9 @@ void cMonthlyView::onDateChanged(const QDate& date) setDate(date); } -void cMonthlyView::onUeberstundenChanged(const QTime& time) +void cMonthlyView::onUeberstundenChanged(const QString& string) { - m_lpMonthlyBooking->setUeberstunden(time); + m_lpMonthlyBooking->setUeberstunden(string2Secs(string)); m_lpMonthlyBooking->save(); displaySummary(); @@ -412,7 +418,7 @@ void cMonthlyView::displaySummary() ui->m_lpShould->setText(secs2String(soll)); ui->m_lpIs->setText(secs2String(ist)); ui->m_lpSaldo->setText(secs2String(ist-soll)); - ui->m_lpUebertragNaechsterMonat->setText(secs2String(lpFirstBooking->prevDiff()+ist-soll-time2Secs(m_lpMonthlyBooking->ueberstunden()))); + ui->m_lpUebertragNaechsterMonat->setText(secs2String(lpFirstBooking->prevDiff()+ist-soll-m_lpMonthlyBooking->ueberstunden())); ui->m_lpResturlaub->setText(QString::number(lpFirstBooking->vacation())); ui->m_lpUebertragUrlaub->setText(QString::number(lpFirstBooking->vacation()-u)); diff --git a/cmonthlyview.h b/cmonthlyview.h index 8d5fcb2..7797f5a 100644 --- a/cmonthlyview.h +++ b/cmonthlyview.h @@ -13,6 +13,8 @@ #include #include +#include + namespace Ui { class cMonthlyView; @@ -37,6 +39,7 @@ private: cBookingList* m_lpBookingList; QDate m_date; cMonthlyBooking* m_lpMonthlyBooking; + QRegExpValidator* m_lpValidator; void setBackground(const int day, const QString& code); void setText(QStandardItem* lpItem, const QTime& time); @@ -48,7 +51,7 @@ private slots: void onTimeChanged(const int day, const int field, const QTime& time); void onTextChanged(const int day, const int field, const QString& text); void onDateChanged(const QDate& date); - void onUeberstundenChanged(const QTime& time); + void onUeberstundenChanged(const QString& string); }; #endif // CMONTHLYVIEW_H diff --git a/cmonthlyview.ui b/cmonthlyview.ui index 0885835..3f37748 100644 --- a/cmonthlyview.ui +++ b/cmonthlyview.ui @@ -110,19 +110,6 @@ - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - QAbstractSpinBox::NoButtons - - - HH:mm:ss - - - @@ -378,6 +365,12 @@ + + + + + + diff --git a/common.cpp b/common.cpp index 8df1cdb..c3f1a6a 100644 --- a/common.cpp +++ b/common.cpp @@ -5,9 +5,10 @@ #include "common.h" #include +#include -QString secs2String(const qint32& secs) +QString secs2String(const qint32& secs, qint8 leading) { QTime t; qint32 h = secs/3600; @@ -22,7 +23,16 @@ QString secs2String(const qint32& secs) else t = QTime(0, 0, 0).addSecs(secs); - return((neg ? "-" : "") + QString::number(h) + t.toString(":mm:ss")); + return((neg ? "-" : "") + QString::number(h).rightJustified(leading, '0') + t.toString(":mm:ss")); +} + +qint32 string2Secs(const QString& string) +{ + QStringList list = string.split(":"); + qint32 h = list[0].toInt(); + qint32 m = list[1].toInt(); + qint32 s = list[2].toInt(); + return(h*3600+m*60+s); } qint32 time2Secs(const QTime& time) diff --git a/common.h b/common.h index cc39bd8..590c366 100644 --- a/common.h +++ b/common.h @@ -40,7 +40,8 @@ #define COLOR_WEEKEND QColor(255, 165, 0) -QString secs2String(const qint32& secs); +QString secs2String(const qint32& secs, qint8 leading = 0); +qint32 string2Secs(const QString& string); qint32 time2Secs(const QTime& time);