diff --git a/Charm/Widgets/ActivityReport.cpp b/Charm/Widgets/ActivityReport.cpp index 95773f04..5062bfd2 100644 --- a/Charm/Widgets/ActivityReport.cpp +++ b/Charm/Widgets/ActivityReport.cpp @@ -238,8 +238,14 @@ ActivityReport::ActivityReport(QWidget *parent) saveToXmlButton()->hide(); saveToTextButton()->hide(); uploadButton()->hide(); - connect(this, &ReportPreviewWindow::anchorClicked, - this, &ActivityReport::slotLinkClicked); + connect(this, &ReportPreviewWindow::nextClicked, + this, [this]() { + updateRange(1); + }); + connect(this, &ReportPreviewWindow::previousClicked, + this, [this]() { + updateRange(-1); + }); } ActivityReport::~ActivityReport() @@ -315,6 +321,7 @@ void ActivityReport::slotUpdate() Q_ASSERT(false); // should not happen } + setTimeSpanTypeName(timeSpanTypeName); auto report = new QTextDocument(this); QDomDocument doc = createReportTemplate(); QDomElement root = doc.documentElement(); @@ -332,20 +339,10 @@ void ActivityReport::slotUpdate() QString content = tr("Report for %1, from %2 to %3") .arg(CONFIGURATION.user.name(), m_properties.start.toString(Qt::TextDate), - m_properties.end.toString(Qt::TextDate)); + m_properties.end.addDays(-1).toString(Qt::TextDate)); QDomText text = doc.createTextNode(content); headline.appendChild(text); body.appendChild(headline); - QDomElement previousLink = doc.createElement(QStringLiteral("a")); - previousLink.setAttribute(QStringLiteral("href"), QStringLiteral("Previous")); - QDomText previousLinkText = doc.createTextNode(tr("").arg(timeSpanTypeName)); - previousLink.appendChild(previousLinkText); - body.appendChild(previousLink); - QDomElement nextLink = doc.createElement(QStringLiteral("a")); - nextLink.setAttribute(QStringLiteral("href"), QStringLiteral("Next")); - QDomText nextLinkText = doc.createTextNode(tr("").arg(timeSpanTypeName)); - nextLink.appendChild(nextLinkText); - body.appendChild(nextLink); { QDomElement paragraph = doc.createElement(QStringLiteral("h4")); QString totalsText = tr("Total: %1").arg(hoursAndMinutes(totalSeconds)); @@ -469,11 +466,11 @@ void ActivityReport::slotUpdate() QDomElement cell2 = doc.createElement(QStringLiteral("td")); cell2.setAttribute(QStringLiteral("class"), QStringLiteral("event_description")); cell2.setAttribute(QStringLiteral("align"), QStringLiteral("left")); - QDomElement preElement = doc.createElement(QStringLiteral("pre")); - QDomText preText = doc.createTextNode( + QDomElement commentElement = doc.createElement(QStringLiteral("p")); + QDomText commentText = doc.createTextNode( m_properties.groupByTaskId ? QString() : event.comment()); - preElement.appendChild(preText); - cell2.appendChild(preElement); + commentElement.appendChild(commentText); + cell2.appendChild(commentElement); row2.appendChild(cell2); tableBody.appendChild(row1); @@ -494,9 +491,8 @@ void ActivityReport::slotUpdate() setDocument(report); } -void ActivityReport::slotLinkClicked(const QUrl &which) +void ActivityReport::updateRange(int direction) { - const int direction = which.toString() == QLatin1String("Previous") ? -1 : 1; switch (m_properties.timeSpanSelection.timeSpanType) { case Day: m_properties.start = m_properties.start.addDays(1 * direction); diff --git a/Charm/Widgets/ActivityReport.h b/Charm/Widgets/ActivityReport.h index 8568fc6f..010e2e68 100644 --- a/Charm/Widgets/ActivityReport.h +++ b/Charm/Widgets/ActivityReport.h @@ -97,7 +97,7 @@ class ActivityReport : public ReportPreviewWindow void setReportProperties(const ActivityReportConfigurationDialog::Properties &properties); private Q_SLOTS: - void slotLinkClicked(const QUrl &which); + void updateRange(int direction); private: void slotUpdate() override; diff --git a/Charm/Widgets/ActivityReportConfigurationDialog.ui b/Charm/Widgets/ActivityReportConfigurationDialog.ui index 2ba53f32..f1f9ad92 100644 --- a/Charm/Widgets/ActivityReportConfigurationDialog.ui +++ b/Charm/Widgets/ActivityReportConfigurationDialog.ui @@ -6,8 +6,8 @@ 0 0 - 386 - 296 + 643 + 407 @@ -168,7 +168,7 @@ (events that start before...) - End date + End date (excluded) Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter diff --git a/Charm/Widgets/MonthlyTimesheet.cpp b/Charm/Widgets/MonthlyTimesheet.cpp index 48fefe2c..4c3189a3 100644 --- a/Charm/Widgets/MonthlyTimesheet.cpp +++ b/Charm/Widgets/MonthlyTimesheet.cpp @@ -55,8 +55,12 @@ MonthlyTimeSheetReport::MonthlyTimeSheetReport(QWidget *parent) m_dailyhours = 8; } - connect(this, &MonthlyTimeSheetReport::anchorClicked, - this, &MonthlyTimeSheetReport::slotLinkClicked); + connect(this, &ReportPreviewWindow::nextClicked, this, [this] () { + updateRange(1); + }); + connect(this, &ReportPreviewWindow::previousClicked, this, [this] () { + updateRange(-1); + }); } MonthlyTimeSheetReport::~MonthlyTimeSheetReport() @@ -178,6 +182,9 @@ void MonthlyTimeSheetReport::update() // store in minute map: m_secondsMap[event.taskId()] = seconds; } + + setTimeSpanTypeName(tr("Month")); + // now the reporting: // headline first: QTextDocument report; @@ -204,16 +211,6 @@ void MonthlyTimeSheetReport::update() QDomText text = doc.createTextNode(content); headline.appendChild(text); body.appendChild(headline); - QDomElement previousLink = doc.createElement(QStringLiteral("a")); - previousLink.setAttribute(QStringLiteral("href"), QStringLiteral("Previous")); - QDomText previousLinkText = doc.createTextNode(tr("")); - previousLink.appendChild(previousLinkText); - body.appendChild(previousLink); - QDomElement nextLink = doc.createElement(QStringLiteral("a")); - nextLink.setAttribute(QStringLiteral("href"), QStringLiteral("Next")); - QDomText nextLinkText = doc.createTextNode(tr("")); - nextLink.appendChild(nextLinkText); - body.appendChild(nextLink); QDomElement paragraph = doc.createElement(QStringLiteral("br")); body.appendChild(paragraph); } @@ -306,11 +303,9 @@ void MonthlyTimeSheetReport::update() uploadButton()->setEnabled(false); } -void MonthlyTimeSheetReport::slotLinkClicked(const QUrl &which) +void MonthlyTimeSheetReport::updateRange(int deltaMonths) { - QDate start = which.toString() - == QLatin1String("Previous") ? startDate().addMonths(-1) : startDate().addMonths(1); - QDate end = which.toString() - == QLatin1String("Previous") ? endDate().addMonths(-1) : endDate().addMonths(1); + QDate start = startDate().addMonths(deltaMonths); + QDate end = endDate().addMonths(deltaMonths); setReportProperties(start, end, rootTask(), activeTasksOnly()); } diff --git a/Charm/Widgets/MonthlyTimesheet.h b/Charm/Widgets/MonthlyTimesheet.h index 5ac65176..f63c83a2 100644 --- a/Charm/Widgets/MonthlyTimesheet.h +++ b/Charm/Widgets/MonthlyTimesheet.h @@ -42,7 +42,7 @@ class MonthlyTimeSheetReport : public TimeSheetReport bool activeTasksOnly) override; private Q_SLOTS: - void slotLinkClicked(const QUrl &which); + void updateRange(int deltaMonths); private: QString suggestedFileName() const override; diff --git a/Charm/Widgets/ReportPreviewWindow.cpp b/Charm/Widgets/ReportPreviewWindow.cpp index ec170f83..70579e9b 100644 --- a/Charm/Widgets/ReportPreviewWindow.cpp +++ b/Charm/Widgets/ReportPreviewWindow.cpp @@ -47,6 +47,10 @@ ReportPreviewWindow::ReportPreviewWindow(QWidget *parent) this, &ReportPreviewWindow::slotSaveToText); connect(m_ui->textBrowser, &QTextBrowser::anchorClicked, this, &ReportPreviewWindow::anchorClicked); + connect(m_ui->pushButtonNext, &QPushButton::clicked, + this, &ReportPreviewWindow::nextClicked); + connect(m_ui->pushButtonPrevious, &QPushButton::clicked, + this, &ReportPreviewWindow::previousClicked); #ifndef QT_NO_PRINTER connect(m_ui->pushButtonPrint, &QPushButton::clicked, this, &ReportPreviewWindow::slotPrint); @@ -79,6 +83,12 @@ void ReportPreviewWindow::setDocument(const QTextDocument *document) } } +void ReportPreviewWindow::setTimeSpanTypeName(const QString &name) +{ + m_ui->pushButtonPrevious->setText(tr("Previous %1").arg(name)); + m_ui->pushButtonNext->setText(tr("Next %1").arg(name)); +} + QDomDocument ReportPreviewWindow::createReportTemplate() const { // create XHTML v1.0 structure: diff --git a/Charm/Widgets/ReportPreviewWindow.h b/Charm/Widgets/ReportPreviewWindow.h index 4b397e71..65ab771b 100644 --- a/Charm/Widgets/ReportPreviewWindow.h +++ b/Charm/Widgets/ReportPreviewWindow.h @@ -46,9 +46,12 @@ class ReportPreviewWindow : public QDialog Q_SIGNALS: void anchorClicked(const QUrl &which); + void nextClicked(); + void previousClicked(); protected: void setDocument(const QTextDocument *document); + void setTimeSpanTypeName(const QString &name); QDomDocument createReportTemplate() const; QPushButton *saveToXmlButton() const; QPushButton *saveToTextButton() const; @@ -66,6 +69,7 @@ private Q_SLOTS: private: QScopedPointer m_ui; QScopedPointer m_document; + QString m_timeSpanTypeName; }; #endif diff --git a/Charm/Widgets/ReportPreviewWindow.ui b/Charm/Widgets/ReportPreviewWindow.ui index aa5ac9d1..6c227c58 100644 --- a/Charm/Widgets/ReportPreviewWindow.ui +++ b/Charm/Widgets/ReportPreviewWindow.ui @@ -6,8 +6,8 @@ 0 0 - 593 - 258 + 802 + 406 @@ -43,6 +43,20 @@ + + + + Previous + + + + + + + Next + + + diff --git a/Charm/Widgets/WeeklyTimesheet.cpp b/Charm/Widgets/WeeklyTimesheet.cpp index 6ce3b334..24bcee55 100644 --- a/Charm/Widgets/WeeklyTimesheet.cpp +++ b/Charm/Widgets/WeeklyTimesheet.cpp @@ -266,7 +266,12 @@ WeeklyTimeSheetReport::WeeklyTimeSheetReport(QWidget *parent) { QPushButton *upload = uploadButton(); connect(upload, &QPushButton::clicked, this, &WeeklyTimeSheetReport::slotUploadTimesheet); - connect(this, &ReportPreviewWindow::anchorClicked, this, &WeeklyTimeSheetReport::slotLinkClicked); + connect(this, &ReportPreviewWindow::nextClicked, this, [this] () { + updateRange(7); + }); + connect(this, &ReportPreviewWindow::previousClicked, this, [this] () { + updateRange(-7); + }); if (!Lotsofcake::Configuration().isConfigured()) upload->hide(); @@ -347,6 +352,9 @@ void WeeklyTimeSheetReport::update() // store in minute map: m_secondsMap[event.taskId()] = seconds; } + + setTimeSpanTypeName(tr("Week")); + // now the reporting: // headline first: QTextDocument report; @@ -371,16 +379,7 @@ void WeeklyTimeSheetReport::update() QDomText text = doc.createTextNode(content); headline.appendChild(text); body.appendChild(headline); - QDomElement previousLink = doc.createElement(QStringLiteral("a")); - previousLink.setAttribute(QStringLiteral("href"), QStringLiteral("Previous")); - QDomText previousLinkText = doc.createTextNode(tr("")); - previousLink.appendChild(previousLinkText); - body.appendChild(previousLink); - QDomElement nextLink = doc.createElement(QStringLiteral("a")); - nextLink.setAttribute(QStringLiteral("href"), QStringLiteral("Next")); - QDomText nextLinkText = doc.createTextNode(tr("")); - nextLink.appendChild(nextLinkText); - body.appendChild(nextLink); + QDomElement paragraph = doc.createElement(QStringLiteral("br")); body.appendChild(paragraph); } @@ -571,11 +570,9 @@ QByteArray WeeklyTimeSheetReport::saveToText() return output; } -void WeeklyTimeSheetReport::slotLinkClicked(const QUrl &which) +void WeeklyTimeSheetReport::updateRange(int deltaDays) { - QDate start = which.toString() - == QLatin1String("Previous") ? startDate().addDays(-7) : startDate().addDays(7); - QDate end = which.toString() - == QLatin1String("Previous") ? endDate().addDays(-7) : endDate().addDays(7); + QDate start = startDate().addDays(deltaDays); + QDate end = endDate().addDays(deltaDays); setReportProperties(start, end, rootTask(), activeTasksOnly()); } diff --git a/Charm/Widgets/WeeklyTimesheet.h b/Charm/Widgets/WeeklyTimesheet.h index a1a46ef3..a5db66df 100644 --- a/Charm/Widgets/WeeklyTimesheet.h +++ b/Charm/Widgets/WeeklyTimesheet.h @@ -86,7 +86,7 @@ class WeeklyTimeSheetReport : public TimeSheetReport private Q_SLOTS: void slotUploadTimesheet(); void slotTimesheetUploaded(HttpJob *); - void slotLinkClicked(const QUrl &which); + void updateRange(int deltaDays); private: QString suggestedFileName() const override; diff --git a/Core/Controller.cpp b/Core/Controller.cpp index a8e5ceb2..5b1ae4e8 100644 --- a/Core/Controller.cpp +++ b/Core/Controller.cpp @@ -261,7 +261,11 @@ void Controller::loadConfigValue(const QString &key, T &configValue) const void Controller::provideMetaData(Configuration &configuration) { Q_ASSERT_X(m_storage != nullptr, Q_FUNC_INFO, "No storage interface available"); - configuration.user.setName(m_storage->getMetaData(MetaKey_Key_UserName)); + + const QString userName = m_storage->getMetaData(MetaKey_Key_UserName); + if (!userName.isEmpty()) { + configuration.user.setName(userName); + } loadConfigValue(MetaKey_Key_TimeTrackerFontSize, configuration.timeTrackerFontSize); loadConfigValue(MetaKey_Key_DurationFormat, configuration.durationFormat);