Commit bf5b1b03 authored by Volker Krause's avatar Volker Krause
Browse files

Prepare pass manager for doing pass sorting internally

parent 17aa68ee
......@@ -53,6 +53,7 @@ private Q_SLOTS:
QCOMPARE(idx.data(PassManager::PassTypeRole).toInt(), PassManager::ProgramMembership);
QVERIFY(!idx.data(PassManager::PassDataRole).toByteArray().isEmpty());
QCOMPARE(idx.data(PassManager::NameRole).toString(), QLatin1String("BahnCard 25 (2. Kl.) (BC25)"));
QCOMPARE(idx.data(PassManager::ValidUntilRole).toDateTime(), QDateTime({2122, 3, 24}, {23, 59, 59}));
QVERIFY(!mgr.pass(passId).isNull());
idx = mgr.index(1, 0);
......@@ -64,6 +65,7 @@ private Q_SLOTS:
QCOMPARE(idx.data(PassManager::PassTypeRole).toInt(), PassManager::Ticket);
QVERIFY(!idx.data(PassManager::PassDataRole).toByteArray().isEmpty());
QCOMPARE(idx.data(PassManager::NameRole).toString(), QLatin1String("9-Euro-Ticket"));
QCOMPARE(idx.data(PassManager::ValidUntilRole).toDateTime(), QDateTime({2022, 5, 31}, {23, 59, 59}));
QVERIFY(!mgr.pass(passId2).isNull());
mgr.remove(passId2);
QCOMPARE(mgr.rowCount(), 1);
......
......@@ -20,6 +20,31 @@
using namespace KItinerary;
QString PassManager::Entry::name() const
{
if (JsonLd::isA<KItinerary::ProgramMembership>(data)) {
return data.value<KItinerary::ProgramMembership>().programName();
}
if (JsonLd::isA<GenericPkPass>(data)) {
return data.value<GenericPkPass>().name();
}
if (JsonLd::isA<KItinerary::Ticket>(data)) {
return data.value<KItinerary::Ticket>().name();
}
return {};
}
QDateTime PassManager::Entry::validUntil() const
{
if (JsonLd::isA<KItinerary::ProgramMembership>(data)) {
return data.value<KItinerary::ProgramMembership>().validUntil();
}
if (JsonLd::isA<KItinerary::Ticket>(data)) {
return data.value<KItinerary::Ticket>().validUntil();
}
return {};
}
bool PassManager::Entry::operator<(const PassManager::Entry &other) const
{
return id < other.id;
......@@ -155,17 +180,9 @@ QVariant PassManager::data(const QModelIndex &index, int role) const
case PassDataRole:
return rawData(entry);
case NameRole:
if (JsonLd::isA<KItinerary::ProgramMembership>(entry.data)) {
return entry.data.value<KItinerary::ProgramMembership>().programName();
}
if (JsonLd::isA<GenericPkPass>(entry.data)) {
return entry.data.value<GenericPkPass>().name();
}
if (JsonLd::isA<KItinerary::Ticket>(entry.data)) {
return entry.data.value<KItinerary::Ticket>().name();
}
return {};
return entry.name();
case ValidUntilRole:
return entry.validUntil();
}
return {};
......@@ -178,6 +195,7 @@ QHash<int, QByteArray> PassManager::roleNames() const
r.insert(PassIdRole, "passId");
r.insert(PassTypeRole, "type");
r.insert(NameRole, "name");
r.insert(ValidUntilRole, "validUntil");
return r;
}
......
......@@ -25,6 +25,7 @@ public:
PassTypeRole,
PassDataRole,
NameRole,
ValidUntilRole,
};
enum PassType {
......@@ -61,6 +62,9 @@ private:
QString id;
QVariant data;
QString name() const;
QDateTime validUntil() const;
bool operator<(const Entry &other) const;
};
std::vector<Entry> m_entries;
......
Supports Markdown
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