Commit 0c355253 authored by Volker Krause's avatar Volker Krause
Browse files

Correctly compute the number of documents for a reservation batch

The previous simplistic approach ignored the multi-traveler case and thus
could lead to different results than what is actually shown in the document
model.
parent c10a1c60
......@@ -108,7 +108,7 @@ Kirigami.ScrollablePage {
},
Kirigami.Action {
iconName: "folder-documents-symbolic"
text: i18n("Documents (%1)", root.reservation.subjectOf.length)
text: i18n("Documents (%1)", _controller.documentCount)
onTriggered: applicationWindow().pageStack.push(docsComponent, {"controller": root.controller });
},
Kirigami.Action {
......
......@@ -15,6 +15,7 @@
#include "transfer.h"
#include "transfermanager.h"
#include <KItinerary/DocumentUtil>
#include <KItinerary/Flight>
#include <KItinerary/LocationUtil>
#include <KItinerary/SortUtil>
......@@ -686,4 +687,23 @@ QJSValue TimelineDelegateController::departureMapArguments() const
return args;
}
int TimelineDelegateController::documentCount() const
{
if (!m_resMgr || m_batchId.isEmpty()) {
return 0;
}
QSet<QString> allDocIds;
const auto resIds = m_resMgr->reservationsForBatch(m_batchId);
for (const auto &resId : resIds) {
const auto res = m_resMgr->reservation(resId);
const auto docIds = DocumentUtil::documentIds(res);
for (const auto &docId : docIds) {
// TODO we could check if actually have the document first?
allDocIds.insert(docId.toString());
}
}
return allDocIds.size();
}
#include "moc_timelinedelegatecontroller.cpp"
......@@ -68,6 +68,9 @@ class TimelineDelegateController : public QObject
/** Reservation has been canceled (by user or provider, we usually don't know which). */
Q_PROPERTY(bool isCanceled READ isCanceled NOTIFY contentChanged)
/** Number of documents attached to the entire batch. */
Q_PROPERTY(int documentCount READ documentCount NOTIFY contentChanged)
public:
TimelineDelegateController(QObject *parent = nullptr);
~TimelineDelegateController();
......@@ -107,6 +110,8 @@ public:
/** Map page arguments for the departure side, if this is a location change element. */
Q_INVOKABLE QJSValue departureMapArguments() const;
int documentCount() const;
Q_SIGNALS:
void setupChanged();
void batchIdChanged();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment