Commit 17aa68ee authored by Volker Krause's avatar Volker Krause
Browse files

Remove the pass on-demand loading logic

That is rather pointless as we end up loading all passes anyway for
sorting.
parent ea4e8b65
......@@ -117,12 +117,6 @@ void registerKItineraryTypes()
qRegisterMetaType<KItinerary::KnowledgeDb::DrivingSide>();
qmlRegisterUncreatableType<KItinerary::Ticket>("org.kde.kitinerary", 1, 0, "Ticket", {});
qmlRegisterUncreatableMetaObject(KItinerary::KnowledgeDb::staticMetaObject, "org.kde.kitinerary", 1, 0, "KnowledgeDb", {});
#if KITINERARY_VERSION < QT_VERSION_CHECK(5, 20, 41)
KItinerary::JsonLdDocument().registerType<GenericPkPass>();
#else
KItinerary::JsonLdDocument::registerType<GenericPkPass>();
#endif
}
void registerApplicationTypes()
......@@ -354,6 +348,11 @@ int main(int argc, char **argv)
HealthCertificateManager healthCertificateMgr;
s_healthCertificateManager = &healthCertificateMgr;
#if KITINERARY_VERSION < QT_VERSION_CHECK(5, 20, 41)
KItinerary::JsonLdDocument().registerType<GenericPkPass>();
#else
KItinerary::JsonLdDocument::registerType<GenericPkPass>();
#endif
PassManager passMgr;
s_passManager = &passMgr;
......
......@@ -138,12 +138,10 @@ QVariant PassManager::data(const QModelIndex &index, int role) const
auto &entry = m_entries[index.row()];
switch (role) {
case PassRole:
ensureLoaded(entry);
return entry.data;
case PassIdRole:
return entry.id;
case PassTypeRole:
ensureLoaded(entry);
if (JsonLd::isA<KItinerary::ProgramMembership>(entry.data)) {
return ProgramMembership;
}
......@@ -157,7 +155,6 @@ QVariant PassManager::data(const QModelIndex &index, int role) const
case PassDataRole:
return rawData(entry);
case NameRole:
ensureLoaded(entry);
if (JsonLd::isA<KItinerary::ProgramMembership>(entry.data)) {
return entry.data.value<KItinerary::ProgramMembership>().programName();
}
......@@ -189,23 +186,17 @@ void PassManager::load()
QDirIterator it(basePath(), QDir::Files);
while (it.hasNext()) {
it.next();
m_entries.push_back({it.fileName(), QVariant()});
Entry entry;
entry.id = it.fileName();
const auto data = rawData(entry);
if (!data.isEmpty()) {
entry.data = JsonLdDocument::fromJsonSingular(QJsonDocument::fromJson(data).object());
}
m_entries.push_back(std::move(entry));
}
std::sort(m_entries.begin(), m_entries.end());
}
void PassManager::ensureLoaded(Entry &entry) const
{
if (!entry.data.isNull()) {
return;
}
const auto data = rawData(entry);
if (!data.isEmpty()) {
entry.data = JsonLdDocument::fromJsonSingular(QJsonDocument::fromJson(data).object());
}
}
QByteArray PassManager::rawData(const Entry &entry) const
{
QFile f(basePath() + entry.id);
......
......@@ -63,10 +63,9 @@ private:
bool operator<(const Entry &other) const;
};
mutable std::vector<Entry> m_entries;
std::vector<Entry> m_entries;
void load();
void ensureLoaded(Entry &entry) const;
QByteArray rawData(const Entry &entry) const;
static QString basePath();
......
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