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