calculations
This commit is contained in:
+63
-9
@@ -24,7 +24,6 @@ cBooking::cBooking(const QDate& date, QObject* parent) :
|
||||
m_information(""),
|
||||
m_soll(QTime()),
|
||||
m_prevDiff(0)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
@@ -203,12 +202,18 @@ QTime cBooking::soll()
|
||||
code() == "U" ||
|
||||
code() == "SU")
|
||||
return(QTime(0, 0, 0));
|
||||
|
||||
return(m_soll);
|
||||
}
|
||||
|
||||
qint32 cBooking::diff()
|
||||
{
|
||||
return(0);
|
||||
int i = istSecs();
|
||||
QTime t = soll();
|
||||
int s = t.hour()*3600+t.minute()*60+t.second();
|
||||
int d = i-s;
|
||||
|
||||
return(d);
|
||||
}
|
||||
|
||||
QString cBooking::diffString()
|
||||
@@ -219,13 +224,13 @@ QString cBooking::diffString()
|
||||
|
||||
if(d < 0)
|
||||
{
|
||||
t = QTime(0, 0, 0, d*1000);
|
||||
t = QTime(0, 0, 0).addSecs(-d);
|
||||
bNeg = true;
|
||||
}
|
||||
else
|
||||
t = QTime(0, 0, 0, d*1000);
|
||||
t = QTime(0, 0, 0).addSecs(d);
|
||||
|
||||
return(bNeg ? "-" : "" + t.toString("hh:mm:ss"));
|
||||
return((bNeg ? "-" : "") + t.toString("hh:mm:ss"));
|
||||
}
|
||||
|
||||
void cBooking::setPrevDiff(qint32 diff)
|
||||
@@ -240,7 +245,7 @@ qint32 cBooking::prevDiff()
|
||||
|
||||
qint32 cBooking::currentDiff()
|
||||
{
|
||||
return(0);
|
||||
return(prevDiff()+diff());
|
||||
}
|
||||
|
||||
QString cBooking::currentDiffString()
|
||||
@@ -251,13 +256,15 @@ QString cBooking::currentDiffString()
|
||||
|
||||
if(d < 0)
|
||||
{
|
||||
t = QTime(0, 0, 0, d*1000);
|
||||
t = QTime(0, 0, 0).addSecs(-d);
|
||||
bNeg = true;
|
||||
}
|
||||
else
|
||||
t = QTime(0, 0, 0, d*1000);
|
||||
t = QTime(0, 0, 0).addSecs(d);
|
||||
|
||||
return(bNeg ? "-" : "" + t.toString("hh:mm:ss"));
|
||||
qint32 h = d / 3600;
|
||||
|
||||
return(QString::number(h) + t.toString(":mm:ss"));
|
||||
}
|
||||
|
||||
qreal cBooking::hoursDecimal()
|
||||
@@ -440,9 +447,16 @@ bool cBookingList::load()
|
||||
}
|
||||
}
|
||||
|
||||
recalculate();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool sortAsc(cBooking* &v1, cBooking* &v2)
|
||||
{
|
||||
return(v1->date() < v2->date());
|
||||
}
|
||||
|
||||
cBooking* cBookingList::add(const QDate& date)
|
||||
{
|
||||
if(find(date))
|
||||
@@ -450,6 +464,7 @@ cBooking* cBookingList::add(const QDate& date)
|
||||
|
||||
cBooking* lpBooking = new cBooking(date);
|
||||
append(lpBooking);
|
||||
|
||||
return(lpBooking);
|
||||
}
|
||||
|
||||
@@ -462,3 +477,42 @@ cBooking* cBookingList::find(const QDate& date)
|
||||
}
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
void cBookingList::sort()
|
||||
{
|
||||
std::sort(begin(), end(), sortAsc);
|
||||
}
|
||||
|
||||
void cBookingList::recalculate(const QDate& date)
|
||||
{
|
||||
sort();
|
||||
|
||||
bool bFirst = false;
|
||||
cBookingList::iterator i = begin();
|
||||
|
||||
if(!date.isNull() && date.isValid())
|
||||
{
|
||||
for(;i != end(); i++)
|
||||
{
|
||||
if((*i)->date() >= date)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(i == end())
|
||||
return;
|
||||
|
||||
if(i == begin())
|
||||
bFirst = true;
|
||||
|
||||
for(;i != end(); i++)
|
||||
{
|
||||
if(bFirst)
|
||||
{
|
||||
bFirst = false;
|
||||
(*i)->setPrevDiff(0);
|
||||
}
|
||||
else
|
||||
(*i)->setPrevDiff((*(i-1))->currentDiff());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,9 @@ public:
|
||||
bool load();
|
||||
cBooking* add(const QDate& date);
|
||||
cBooking* find(const QDate& date);
|
||||
void sort();
|
||||
|
||||
void recalculate(const QDate& date = QDate());
|
||||
private:
|
||||
cPublicHoliday* m_lpPublicHoliday;
|
||||
cDailyWorkingList* m_lpDailyWorkingList;
|
||||
|
||||
+23
-4
@@ -11,13 +11,15 @@ cMonthlyView::cMonthlyView(const QDate& date, cPublicHoliday *lpPublicHoliday, c
|
||||
ui(new Ui::cMonthlyView),
|
||||
m_loading(true),
|
||||
m_lpPublicHoliday(lpPublicHoliday),
|
||||
m_lpBookingList(lpBookingList)
|
||||
m_lpBookingList(lpBookingList),
|
||||
m_date(date)
|
||||
{
|
||||
m_code.insert(" ", tr(""));
|
||||
m_code.insert("G", tr("Gleitzeit"));
|
||||
m_code.insert("U", tr("Urlaub"));
|
||||
m_code.insert("K", tr("Krank"));
|
||||
m_code.insert("SU", tr("Sonderurlaub"));
|
||||
m_code.insert("K", tr("Krank"));
|
||||
m_code.insert("T", tr("Training"));
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -34,6 +36,8 @@ cMonthlyView::cMonthlyView(const QDate& date, cPublicHoliday *lpPublicHoliday, c
|
||||
ui->m_lpUrlaubLabel->setStyleSheet(QString("QLabel { background-color: rgba(%1, %2, %3, 255); }").arg(COLOR_URLAUB.red()).arg(COLOR_URLAUB.green()).arg(COLOR_URLAUB.blue()));
|
||||
ui->m_lpSonderurlaubLabel->setAutoFillBackground(true);
|
||||
ui->m_lpSonderurlaubLabel->setStyleSheet(QString("QLabel { background-color: rgba(%1, %2, %3, 255); }").arg(COLOR_SONDERURLAUB.red()).arg(COLOR_SONDERURLAUB.green()).arg(COLOR_SONDERURLAUB.blue()));
|
||||
ui->m_lpTrainingLabel->setAutoFillBackground(true);
|
||||
ui->m_lpTrainingLabel->setStyleSheet(QString("QLabel { background-color: rgba(%1, %2, %3, 255); }").arg(COLOR_TRAINING.red()).arg(COLOR_TRAINING.green()).arg(COLOR_TRAINING.blue()));
|
||||
|
||||
ui->m_lpMonth->setDate(date);
|
||||
setDate(date);
|
||||
@@ -48,6 +52,8 @@ void cMonthlyView::setDate(const QDate& date)
|
||||
{
|
||||
m_loading = true;
|
||||
|
||||
m_date = date;
|
||||
|
||||
m_lpPublicHoliday->setYear(static_cast<qint16>(date.year()));
|
||||
|
||||
m_lpMonthlyListModel->clear();
|
||||
@@ -148,9 +154,9 @@ void cMonthlyView::setDate(const QDate& date)
|
||||
items[COL_CODE]->setTextAlignment(Qt::AlignHCenter);
|
||||
items[COL_IS]->setTextAlignment(Qt::AlignHCenter);
|
||||
items[COL_SHOULD]->setTextAlignment(Qt::AlignHCenter);
|
||||
items[COL_DIFF]->setTextAlignment(Qt::AlignHCenter);
|
||||
items[COL_DIFF]->setTextAlignment(Qt::AlignRight);
|
||||
items[COL_INFORMATION]->setTextAlignment(Qt::AlignLeft);
|
||||
items[COL_CURRENT]->setTextAlignment(Qt::AlignHCenter);
|
||||
items[COL_CURRENT]->setTextAlignment(Qt::AlignRight);
|
||||
items[COL_HOURS_DEC]->setTextAlignment(Qt::AlignRight);
|
||||
items[COL_DAY2]->setTextAlignment(Qt::AlignLeft);
|
||||
|
||||
@@ -301,6 +307,8 @@ void cMonthlyView::setBackground(const int day, const QString& code)
|
||||
brush = QBrush(COLOR_KRANK);
|
||||
else if(code == "SU")
|
||||
brush = QBrush(COLOR_SONDERURLAUB);
|
||||
else if(code == "T")
|
||||
brush = QBrush(COLOR_TRAINING);
|
||||
|
||||
for(int x = 0;x < m_lpMonthlyListModel->columnCount();x++)
|
||||
{
|
||||
@@ -319,10 +327,13 @@ void cMonthlyView::setText(QStandardItem* lpItem, const QTime& time)
|
||||
|
||||
void cMonthlyView::recalculate(int day, int /*field*/)
|
||||
{
|
||||
m_lpBookingList->recalculate(QDate(m_date.year(), m_date.month(), day));
|
||||
|
||||
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);
|
||||
QStandardItem* lpDiffItem = m_lpMonthlyListModel->item(day-1, COL_DIFF);
|
||||
|
||||
cBooking* lpBooking = lpPauseItem->data(DATA_BOOKING).value<cBooking*>();
|
||||
|
||||
@@ -330,4 +341,12 @@ void cMonthlyView::recalculate(int day, int /*field*/)
|
||||
lpIstItem->setText(lpBooking->ist().toString("hh:mm:ss"));
|
||||
lpDecItem->setText(QString::number(lpBooking->hoursDecimal(), 'f', 2));
|
||||
lpSollItem->setText(lpBooking->soll().toString("hh:mm:ss"));
|
||||
lpDiffItem->setText(lpBooking->diffString());
|
||||
|
||||
for(int i = day;i <= m_date.daysInMonth();i++)
|
||||
{
|
||||
QStandardItem* lpCurrentDiffItem = m_lpMonthlyListModel->item(i-1, COL_CURRENT);
|
||||
cBooking* lpCurrentBooking = lpCurrentDiffItem->data(DATA_BOOKING).value<cBooking*>();
|
||||
lpCurrentDiffItem->setText(lpCurrentBooking->currentDiffString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ private:
|
||||
QMap<QString, QString> m_code;
|
||||
cPublicHoliday* m_lpPublicHoliday;
|
||||
cBookingList* m_lpBookingList;
|
||||
QDate m_date;
|
||||
|
||||
void setBackground(const int day, const QString& code);
|
||||
void setText(QStandardItem* lpItem, const QTime& time);
|
||||
|
||||
@@ -356,6 +356,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="4">
|
||||
<widget class="QLineEdit" name="m_lpTraining"/>
|
||||
</item>
|
||||
<item row="4" column="5">
|
||||
<widget class="QLabel" name="m_lpTrainingLabel">
|
||||
<property name="text">
|
||||
<string>Training</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
Reference in New Issue
Block a user