Skip to content
This repository was archived by the owner on Sep 24, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions Charm/Widgets/ActivityReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand All @@ -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("<Previous %1>").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("<Next %1>").arg(timeSpanTypeName));
nextLink.appendChild(nextLinkText);
body.appendChild(nextLink);
{
QDomElement paragraph = doc.createElement(QStringLiteral("h4"));
QString totalsText = tr("Total: %1").arg(hoursAndMinutes(totalSeconds));
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Charm/Widgets/ActivityReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Charm/Widgets/ActivityReportConfigurationDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>386</width>
<height>296</height>
<width>643</width>
<height>407</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -168,7 +168,7 @@
<string>(events that start before...)</string>
</property>
<property name="text">
<string>End date</string>
<string>End date (excluded)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
Expand Down
29 changes: 12 additions & 17 deletions Charm/Widgets/MonthlyTimesheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand All @@ -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("<Previous Month>"));
previousLink.appendChild(previousLinkText);
body.appendChild(previousLink);
QDomElement nextLink = doc.createElement(QStringLiteral("a"));
nextLink.setAttribute(QStringLiteral("href"), QStringLiteral("Next"));
QDomText nextLinkText = doc.createTextNode(tr("<Next Month>"));
nextLink.appendChild(nextLinkText);
body.appendChild(nextLink);
QDomElement paragraph = doc.createElement(QStringLiteral("br"));
body.appendChild(paragraph);
}
Expand Down Expand Up @@ -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());
}
2 changes: 1 addition & 1 deletion Charm/Widgets/MonthlyTimesheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions Charm/Widgets/ReportPreviewWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Charm/Widgets/ReportPreviewWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -66,6 +69,7 @@ private Q_SLOTS:
private:
QScopedPointer<Ui::ReportPreviewWindow> m_ui;
QScopedPointer<QTextDocument> m_document;
QString m_timeSpanTypeName;
};

#endif
18 changes: 16 additions & 2 deletions Charm/Widgets/ReportPreviewWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>593</width>
<height>258</height>
<width>802</width>
<height>406</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -43,6 +43,20 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonPrevious">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonNext">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonUpdate">
<property name="text">
Expand Down
29 changes: 13 additions & 16 deletions Charm/Widgets/WeeklyTimesheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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("<Previous Week>"));
previousLink.appendChild(previousLinkText);
body.appendChild(previousLink);
QDomElement nextLink = doc.createElement(QStringLiteral("a"));
nextLink.setAttribute(QStringLiteral("href"), QStringLiteral("Next"));
QDomText nextLinkText = doc.createTextNode(tr("<Next Week>"));
nextLink.appendChild(nextLinkText);
body.appendChild(nextLink);

QDomElement paragraph = doc.createElement(QStringLiteral("br"));
body.appendChild(paragraph);
}
Expand Down Expand Up @@ -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());
}
2 changes: 1 addition & 1 deletion Charm/Widgets/WeeklyTimesheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion Core/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down