From 9a5572d6939065e61ca56bf1d3e2bc8ced4a4b33 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 10 Jun 2019 13:05:02 +0200 Subject: [PATCH 1/4] print the actual legal end date in the report charm does not include the last day of the range, tough to change this it should be heavily refactored --- Charm/Widgets/ActivityReport.cpp | 2 +- Charm/Widgets/ActivityReportConfigurationDialog.ui | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Charm/Widgets/ActivityReport.cpp b/Charm/Widgets/ActivityReport.cpp index 95773f04..ae19609e 100644 --- a/Charm/Widgets/ActivityReport.cpp +++ b/Charm/Widgets/ActivityReport.cpp @@ -332,7 +332,7 @@ 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); 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 From 12a128b8b34ed7537e785b60416b746a67e1cdfd Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 10 Jun 2019 14:44:15 +0200 Subject: [PATCH 2/4] Don't make metadata forget the user name happened that the user name gets forgotten and the report generates with an empty name. if it's empty, the one taken from the user table takes precedence Why a cached value of the user name is needed in metadata in the first place? --- Core/Controller.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); From 3a75b42f3bd84956bf3fc35161d516aa67ad93c7 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 10 Jun 2019 16:51:59 +0200 Subject: [PATCH 3/4] previous and next navigation in buttons now previous and next links should never be in the printed report. move them to external push buttons --- Charm/Widgets/ActivityReport.cpp | 24 +++++++++------------- Charm/Widgets/ActivityReport.h | 2 +- Charm/Widgets/MonthlyTimesheet.cpp | 29 +++++++++++---------------- Charm/Widgets/MonthlyTimesheet.h | 2 +- Charm/Widgets/ReportPreviewWindow.cpp | 10 +++++++++ Charm/Widgets/ReportPreviewWindow.h | 4 ++++ Charm/Widgets/ReportPreviewWindow.ui | 18 +++++++++++++++-- Charm/Widgets/WeeklyTimesheet.cpp | 29 ++++++++++++--------------- Charm/Widgets/WeeklyTimesheet.h | 2 +- 9 files changed, 68 insertions(+), 52 deletions(-) diff --git a/Charm/Widgets/ActivityReport.cpp b/Charm/Widgets/ActivityReport.cpp index ae19609e..92bd7396 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(); @@ -336,16 +343,6 @@ void ActivityReport::slotUpdate() 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)); @@ -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/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; From ad83945863db88ee0865097fcb12769181f3446f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 10 Jun 2019 17:31:29 +0200 Subject: [PATCH 4/4] don't use a
 for the comments

need to fit very long text in the comments, use a normal flow with a 

--- Charm/Widgets/ActivityReport.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Charm/Widgets/ActivityReport.cpp b/Charm/Widgets/ActivityReport.cpp index 92bd7396..5062bfd2 100644 --- a/Charm/Widgets/ActivityReport.cpp +++ b/Charm/Widgets/ActivityReport.cpp @@ -466,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);