File indexing completed on 2022-11-29 20:26:08

0001 /**
0002  * SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QAbstractListModel>
0010 #include <QFile>
0011 #include <QJsonArray>
0012 
0013 #include <KPublicTransport/Location>
0014 
0015 class LocationCacheModel : public QAbstractListModel
0016 {
0017     Q_OBJECT
0018 
0019 public:
0020     explicit LocationCacheModel(QObject *parent = nullptr);
0021 
0022     QVariant data(const QModelIndex &index, int role) const override;
0023     int rowCount(const QModelIndex &parent) const override;
0024     QHash<int, QByteArray> roleNames() const override;
0025 
0026     Q_INVOKABLE void addCachedLocation(const KPublicTransport::Location location);
0027 
0028 private:
0029     void loadLocationsFromCache();
0030 
0031     QVariantList m_cachedLocations;
0032     QFile m_locationCacheFile;
0033     QJsonArray m_cachedLocationsJson;
0034 };