From 5c6b68b4f387aa0d5a1f9d3d0deb83665fcf40e2 Mon Sep 17 00:00:00 2001 From: birkeh Date: Tue, 15 Oct 2019 21:05:57 +0200 Subject: [PATCH] recalculate --- cbooking.cpp | 34 +++++++++++++++++++++++++++++----- cbooking.h | 5 ++++- cdailyworking.cpp | 8 ++++---- cmainwindow.cpp | 14 ++++++++++---- cmainwindow.h | 5 ++++- cmonthlyview.cpp | 14 +++++++++----- cmonthlyview.h | 4 ++-- 7 files changed, 62 insertions(+), 22 deletions(-) diff --git a/cbooking.cpp b/cbooking.cpp index ed1c837..1846b48 100644 --- a/cbooking.cpp +++ b/cbooking.cpp @@ -1,3 +1,4 @@ +#include "common.h" #include "cbooking.h" #include @@ -197,6 +198,11 @@ void cBooking::setSoll(const QTime& time) QTime cBooking::soll() { + if(code() == "G" || + code() == "K" || + code() == "U" || + code() == "SU") + return(QTime(0, 0, 0)); return(m_soll); } @@ -364,9 +370,14 @@ int cBooking::totalPause() return(geht1().secsTo(kommt2()) + geht2().secsTo(kommt3()) + geht3().secsTo(kommt4()) + geht4().secsTo(kommt5())); } -bool cBookingList::load(cDailyWorkingList* lpDailyWorkingList) +cBookingList::cBookingList(cPublicHoliday* lpPublicHoliday, cDailyWorkingList* lpDailyWorkingList) : + m_lpPublicHoliday(lpPublicHoliday), + m_lpDailyWorkingList(lpDailyWorkingList) +{ +} + +bool cBookingList::load() { - m_lpDailyWorkingList = lpDailyWorkingList; QSqlQuery query; query.prepare("SELECT datum, " @@ -391,10 +402,18 @@ bool cBookingList::load(cDailyWorkingList* lpDailyWorkingList) return(false); } + qint16 year = 0; + while(query.next()) { cBooking* lpBooking = add(query.value("datum").toDate()); + if(year != lpBooking->date().year()) + { + year = static_cast(lpBooking->date().year()); + m_lpPublicHoliday->setYear(year); + } + if(lpBooking) { lpBooking->setKommt1(query.value("kommt1").toTime()); @@ -410,9 +429,14 @@ bool cBookingList::load(cDailyWorkingList* lpDailyWorkingList) lpBooking->setCode(query.value("code").toString()); lpBooking->setInformation(query.value("information").toString()); - cDailyWorking* lpDailyWorking = m_lpDailyWorkingList->get(lpBooking->date()); - if(lpDailyWorking) - lpBooking->setSoll(lpDailyWorking->soll(lpBooking->date().dayOfWeek())); + if(!m_lpPublicHoliday->isPublicHoliday(lpBooking->date())) + { + cDailyWorking* lpDailyWorking = m_lpDailyWorkingList->get(lpBooking->date()); + if(lpDailyWorking) + lpBooking->setSoll(lpDailyWorking->soll(static_cast(lpBooking->date().dayOfWeek()))); + } + else + lpBooking->setSoll(QTime(0, 0, 0)); } } diff --git a/cbooking.h b/cbooking.h index 7ca190d..89494ec 100644 --- a/cbooking.h +++ b/cbooking.h @@ -2,6 +2,7 @@ #define CBOOKING_H +#include "cpublicholiday.h" #include "cdailyworking.h" #include @@ -107,11 +108,13 @@ Q_DECLARE_METATYPE(cBooking*) class cBookingList : public QList { public: - bool load(cDailyWorkingList* m_dailyWorkingList); + explicit cBookingList(cPublicHoliday* lpPublicHoliday, cDailyWorkingList* lpDailyWorkingList); + bool load(); cBooking* add(const QDate& date); cBooking* find(const QDate& date); private: + cPublicHoliday* m_lpPublicHoliday; cDailyWorkingList* m_lpDailyWorkingList; }; diff --git a/cdailyworking.cpp b/cdailyworking.cpp index 61a5392..82d3119 100644 --- a/cdailyworking.cpp +++ b/cdailyworking.cpp @@ -121,8 +121,8 @@ bool cDailyWorkingList::load() { QSqlQuery query; - query.prepare("SELECT datum, " - " montag," + query.prepare("SELECT ab, " + " montag, " " dienstag, " " mittwoch, " " donnerstag, " @@ -130,7 +130,7 @@ bool cDailyWorkingList::load() " samstag, " " sonntag " "FROM dailyWorking " - "ORDER BY datum;"); + "ORDER BY ab;"); if(!query.exec()) { @@ -140,7 +140,7 @@ bool cDailyWorkingList::load() while(query.next()) { - cDailyWorking* lpWorking = add(query.value("datum").toDate()); + cDailyWorking* lpWorking = add(query.value("ab").toDate()); if(lpWorking) { diff --git a/cmainwindow.cpp b/cmainwindow.cpp index a761723..2dc0b31 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -16,19 +16,25 @@ cMainWindow::cMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), - m_lpMonthlyView(nullptr) + m_lpMonthlyView(nullptr), + m_lpBookingList(nullptr) { openDB(); m_dailyWorkingList.load(); - m_bookingList.load(&m_dailyWorkingList); + + m_lpBookingList = new cBookingList(&m_publicHoliday, &m_dailyWorkingList); + m_lpBookingList->load(); initUI(); - qDebug() << "count: " << m_bookingList.count(); + qDebug() << "count: " << m_lpBookingList->count(); } cMainWindow::~cMainWindow() { + if(m_lpBookingList) + delete m_lpBookingList; + if(m_db.isOpen()) m_db.close(); @@ -68,7 +74,7 @@ void cMainWindow::initUI() if(iX != -1 && iY != -1) move(iX, iY); - m_lpMonthlyView = new cMonthlyView(QDate::currentDate(), &m_bookingList, this); + m_lpMonthlyView = new cMonthlyView(QDate::currentDate(), &m_publicHoliday, m_lpBookingList, this); ui->m_lpMainTab->addTab(m_lpMonthlyView, "Monthly"); } diff --git a/cmainwindow.h b/cmainwindow.h index 9b8560b..feff0ad 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -4,6 +4,7 @@ #include "cmonthlyview.h" #include "cdailyworking.h" +#include "cpublicholiday.h" #include "cbooking.h" #include @@ -28,8 +29,10 @@ private: Ui::cMainWindow* ui; cMonthlyView* m_lpMonthlyView; QSqlDatabase m_db; + cPublicHoliday m_publicHoliday; cDailyWorkingList m_dailyWorkingList; - cBookingList m_bookingList; + cBookingList* m_lpBookingList; + void initUI(); void openDB(); diff --git a/cmonthlyview.cpp b/cmonthlyview.cpp index 27e57d4..eb18f71 100644 --- a/cmonthlyview.cpp +++ b/cmonthlyview.cpp @@ -6,10 +6,11 @@ #include -cMonthlyView::cMonthlyView(const QDate& date, cBookingList* lpBookingList, QWidget *parent) : +cMonthlyView::cMonthlyView(const QDate& date, cPublicHoliday *lpPublicHoliday, cBookingList* lpBookingList, QWidget *parent) : QWidget(parent), ui(new Ui::cMonthlyView), m_loading(true), + m_lpPublicHoliday(lpPublicHoliday), m_lpBookingList(lpBookingList) { m_code.insert(" ", tr("")); @@ -47,7 +48,7 @@ void cMonthlyView::setDate(const QDate& date) { m_loading = true; - m_publicHoliday.setYear(static_cast(date.year())); + m_lpPublicHoliday->setYear(static_cast(date.year())); m_lpMonthlyListModel->clear(); @@ -108,7 +109,7 @@ void cMonthlyView::setDate(const QDate& date) items.append(new QStandardItem); items[COL_DAY1]->setText(date1.toString("dddd dd")); - items[COL_PUBLIC_HOLIDAY]->setText(m_publicHoliday.name(date1)); + items[COL_PUBLIC_HOLIDAY]->setText(m_lpPublicHoliday->name(date1)); items[COL_DAY2]->setText(date1.toString("dd dddd")); setText(items[COL_COME1], lpBooking->kommt1()); @@ -155,7 +156,7 @@ void cMonthlyView::setDate(const QDate& date) for(int z = 0;z < items.count();z++) { - if(date1.dayOfWeek() >= 6 || m_publicHoliday.isPublicHoliday(date1)) + if(date1.dayOfWeek() >= 6 || m_lpPublicHoliday->isPublicHoliday(date1)) { items[z]->setData(QVariant::fromValue(true), DATA_HOLIDAY); items[z]->setBackground(weekend); @@ -168,7 +169,7 @@ void cMonthlyView::setDate(const QDate& date) m_lpMonthlyListModel->appendRow(items); - if(date1.dayOfWeek() < 6 && !m_publicHoliday.isPublicHoliday(date1)) + if(date1.dayOfWeek() < 6 && !m_lpPublicHoliday->isPublicHoliday(date1)) setBackground(date1.day(), lpBooking->code()); } ui->m_lpMonthlyList->resizeColumnToContents(COL_DAY1); @@ -273,6 +274,7 @@ void cMonthlyView::onTextChanged(const int day, const int field, const QString& setBackground(day, code); lpBooking->setCode(code); lpBooking->save(); + recalculate(day, field); break; } case COL_INFORMATION: @@ -319,6 +321,7 @@ void cMonthlyView::recalculate(int day, int /*field*/) { QStandardItem* lpPauseItem = m_lpMonthlyListModel->item(day-1, COL_BREAK); QStandardItem* lpIstItem = m_lpMonthlyListModel->item(day-1, COL_IS); + QStandardItem* lpSollItem = m_lpMonthlyListModel->item(day-1, COL_SHOULD); QStandardItem* lpDecItem = m_lpMonthlyListModel->item(day-1, COL_HOURS_DEC); cBooking* lpBooking = lpPauseItem->data(DATA_BOOKING).value(); @@ -326,4 +329,5 @@ void cMonthlyView::recalculate(int day, int /*field*/) lpPauseItem->setText(lpBooking->pause().toString("hh:mm:ss")); lpIstItem->setText(lpBooking->ist().toString("hh:mm:ss")); lpDecItem->setText(QString::number(lpBooking->hoursDecimal(), 'f', 2)); + lpSollItem->setText(lpBooking->soll().toString("hh:mm:ss")); } diff --git a/cmonthlyview.h b/cmonthlyview.h index add03d7..d536353 100644 --- a/cmonthlyview.h +++ b/cmonthlyview.h @@ -22,7 +22,7 @@ class cMonthlyView : public QWidget Q_OBJECT public: - explicit cMonthlyView(const QDate& date, cBookingList* lpBookingList, QWidget *parent = nullptr); + explicit cMonthlyView(const QDate& date, cPublicHoliday* lpPublicHoliday, cBookingList* lpBookingList, QWidget *parent = nullptr); ~cMonthlyView(); void setDate(const QDate& date); @@ -31,7 +31,7 @@ private: bool m_loading; QStandardItemModel* m_lpMonthlyListModel; QMap m_code; - cPublicHoliday m_publicHoliday; + cPublicHoliday* m_lpPublicHoliday; cBookingList* m_lpBookingList; void setBackground(const int day, const QString& code);