Commit aa5f8291 authored by Volker Krause's avatar Volker Krause

Decouple the timeline model from the pkpass manager

Also, only load the full pass object when really needed, rather than for
every element in the model.

This mainly was a leftover from early prototyping.
parent e914799f
...@@ -57,7 +57,6 @@ private slots: ...@@ -57,7 +57,6 @@ private slots:
resMgr.setPkPassManager(&mgr); resMgr.setPkPassManager(&mgr);
TimelineModel model; TimelineModel model;
model.setPkPassManager(&mgr);
model.setReservationManager(&resMgr); model.setReservationManager(&resMgr);
QSignalSpy insertSpy(&model, &TimelineModel::rowsInserted); QSignalSpy insertSpy(&model, &TimelineModel::rowsInserted);
......
...@@ -25,7 +25,6 @@ import "." as App ...@@ -25,7 +25,6 @@ import "." as App
Kirigami.AbstractCard { Kirigami.AbstractCard {
id: root id: root
property var reservation property var reservation
property var pass
property string passId property string passId
property var rangeType property var rangeType
...@@ -42,7 +41,7 @@ Kirigami.AbstractCard { ...@@ -42,7 +41,7 @@ Kirigami.AbstractCard {
id: pkpassComponent id: pkpassComponent
App.PkPassPage { App.PkPassPage {
passId: root.passId passId: root.passId
pass: root.pass pass: _pkpassManager.passObject(root.passId)
} }
} }
} }
...@@ -43,7 +43,6 @@ Kirigami.ScrollablePage { ...@@ -43,7 +43,6 @@ Kirigami.ScrollablePage {
App.FlightDelegate { App.FlightDelegate {
reservation: modelData.reservation reservation: modelData.reservation
passId: modelData.passId passId: modelData.passId
pass: modelData.pass
rangeType: modelData.rangeType rangeType: modelData.rangeType
} }
} }
...@@ -52,7 +51,6 @@ Kirigami.ScrollablePage { ...@@ -52,7 +51,6 @@ Kirigami.ScrollablePage {
App.HotelDelegate { App.HotelDelegate {
reservation: modelData.reservation reservation: modelData.reservation
passId: modelData.passId passId: modelData.passId
pass: modelData.pass
rangeType: modelData.rangeType rangeType: modelData.rangeType
} }
} }
...@@ -61,7 +59,6 @@ Kirigami.ScrollablePage { ...@@ -61,7 +59,6 @@ Kirigami.ScrollablePage {
App.TrainDelegate { App.TrainDelegate {
reservation: modelData.reservation reservation: modelData.reservation
passId: modelData.passId passId: modelData.passId
pass: modelData.pass
rangeType: modelData.rangeType rangeType: modelData.rangeType
} }
} }
...@@ -70,7 +67,6 @@ Kirigami.ScrollablePage { ...@@ -70,7 +67,6 @@ Kirigami.ScrollablePage {
App.BusDelegate { App.BusDelegate {
reservation: modelData.reservation reservation: modelData.reservation
passId: modelData.passId passId: modelData.passId
pass: modelData.pass
rangeType: modelData.rangeType rangeType: modelData.rangeType
} }
} }
...@@ -79,7 +75,6 @@ Kirigami.ScrollablePage { ...@@ -79,7 +75,6 @@ Kirigami.ScrollablePage {
App.RestaurantDelegate { App.RestaurantDelegate {
reservation: modelData.reservation reservation: modelData.reservation
passId: modelData.passId passId: modelData.passId
pass: modelData.pass
rangeType: modelData.rangeType rangeType: modelData.rangeType
} }
} }
...@@ -88,7 +83,6 @@ Kirigami.ScrollablePage { ...@@ -88,7 +83,6 @@ Kirigami.ScrollablePage {
App.TouristAttractionDelegate { App.TouristAttractionDelegate {
reservation: modelData.reservation reservation: modelData.reservation
passId: modelData.passId passId: modelData.passId
pass: modelData.pass
rangeType: modelData.rangeType rangeType: modelData.rangeType
} }
} }
......
...@@ -104,7 +104,6 @@ int main(int argc, char **argv) ...@@ -104,7 +104,6 @@ int main(int argc, char **argv)
ReservationManager resMgr; ReservationManager resMgr;
resMgr.setPkPassManager(&passMgr); resMgr.setPkPassManager(&passMgr);
TimelineModel timelineModel; TimelineModel timelineModel;
timelineModel.setPkPassManager(&passMgr);
timelineModel.setReservationManager(&resMgr); timelineModel.setReservationManager(&resMgr);
ApplicationController appController; ApplicationController appController;
......
...@@ -73,6 +73,11 @@ KPkPass::Pass* PkPassManager::pass(const QString& passId) ...@@ -73,6 +73,11 @@ KPkPass::Pass* PkPassManager::pass(const QString& passId)
return file; return file;
} }
QObject* PkPassManager::passObject(const QString& passId)
{
return pass(passId);
}
void PkPassManager::importPass(const QUrl& url) void PkPassManager::importPass(const QUrl& url)
{ {
doImportPass(url, Copy); doImportPass(url, Copy);
......
...@@ -37,6 +37,7 @@ public: ...@@ -37,6 +37,7 @@ public:
QVector<QString> passes() const; QVector<QString> passes() const;
KPkPass::Pass* pass(const QString &passId); KPkPass::Pass* pass(const QString &passId);
Q_INVOKABLE QObject* passObject(const QString &passId);
Q_INVOKABLE void importPass(const QUrl &url); Q_INVOKABLE void importPass(const QUrl &url);
void importPassFromTempFile(const QString &tmpFile); void importPassFromTempFile(const QString &tmpFile);
......
...@@ -110,11 +110,6 @@ TimelineModel::TimelineModel(QObject *parent) ...@@ -110,11 +110,6 @@ TimelineModel::TimelineModel(QObject *parent)
TimelineModel::~TimelineModel() = default; TimelineModel::~TimelineModel() = default;
void TimelineModel::setPkPassManager(PkPassManager* mgr)
{
m_passMgr = mgr;
}
void TimelineModel::setReservationManager(ReservationManager* mgr) void TimelineModel::setReservationManager(ReservationManager* mgr)
{ {
beginResetModel(); beginResetModel();
...@@ -158,8 +153,6 @@ QVariant TimelineModel::data(const QModelIndex& index, int role) const ...@@ -158,8 +153,6 @@ QVariant TimelineModel::data(const QModelIndex& index, int role) const
const auto &elem = m_elements.at(index.row()); const auto &elem = m_elements.at(index.row());
const auto res = m_resMgr->reservation(elem.id); const auto res = m_resMgr->reservation(elem.id);
switch (role) { switch (role) {
case PassRole:
return QVariant::fromValue(m_passMgr->pass(passId(res)));
case PassIdRole: case PassIdRole:
return passId(res); return passId(res);
case SectionHeader: case SectionHeader:
...@@ -196,7 +189,6 @@ QVariant TimelineModel::data(const QModelIndex& index, int role) const ...@@ -196,7 +189,6 @@ QVariant TimelineModel::data(const QModelIndex& index, int role) const
QHash<int, QByteArray> TimelineModel::roleNames() const QHash<int, QByteArray> TimelineModel::roleNames() const
{ {
auto names = QAbstractListModel::roleNames(); auto names = QAbstractListModel::roleNames();
names.insert(PassRole, "pass");
names.insert(PassIdRole, "passId"); names.insert(PassIdRole, "passId");
names.insert(SectionHeader, "sectionHeader"); names.insert(SectionHeader, "sectionHeader");
names.insert(ReservationRole, "reservation"); names.insert(ReservationRole, "reservation");
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QDateTime> #include <QDateTime>
class PkPassManager;
class ReservationManager; class ReservationManager;
class TimelineModel : public QAbstractListModel class TimelineModel : public QAbstractListModel
...@@ -31,8 +30,7 @@ class TimelineModel : public QAbstractListModel ...@@ -31,8 +30,7 @@ class TimelineModel : public QAbstractListModel
public: public:
enum Role { enum Role {
PassRole = Qt::UserRole + 1, PassIdRole = Qt::UserRole + 1,
PassIdRole,
SectionHeader, SectionHeader,
ReservationRole, ReservationRole,
ReservationIdRole, ReservationIdRole,
...@@ -67,7 +65,6 @@ public: ...@@ -67,7 +65,6 @@ public:
explicit TimelineModel(QObject *parent = nullptr); explicit TimelineModel(QObject *parent = nullptr);
~TimelineModel(); ~TimelineModel();
void setPkPassManager(PkPassManager *mgr);
void setReservationManager(ReservationManager *mgr); void setReservationManager(ReservationManager *mgr);
QVariant data(const QModelIndex& index, int role) const override; QVariant data(const QModelIndex& index, int role) const override;
...@@ -97,7 +94,6 @@ private: ...@@ -97,7 +94,6 @@ private:
void updateInformationElements(); void updateInformationElements();
std::vector<Element>::iterator erasePreviousCountyInfo(std::vector<Element>::iterator it); std::vector<Element>::iterator erasePreviousCountyInfo(std::vector<Element>::iterator it);
PkPassManager *m_passMgr = nullptr;
ReservationManager *m_resMgr = nullptr; ReservationManager *m_resMgr = nullptr;
std::vector<Element> m_elements; std::vector<Element> m_elements;
}; };
......
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