KPublicTransport

locationhistorymodel.h
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPUBLICTRANSPORT_LOCATIONHISTORYMODEL_H
8#define KPUBLICTRANSPORT_LOCATIONHISTORYMODEL_H
9
10#include "kpublictransport_export.h"
11
12#include <KPublicTransport/Location>
13
14#include <QAbstractTableModel>
15#include <QDateTime>
16
17namespace KPublicTransport {
18
19/** Model of frequently/recently used locations.
20 * Content is persisted globally, ie. all applications sharing this see
21 * the same data.
22 */
23class KPUBLICTRANSPORT_EXPORT LocationHistoryModel : public QAbstractListModel
24{
25 Q_OBJECT
26public:
27 explicit LocationHistoryModel(QObject *parent = nullptr);
29
30 enum Role {
31 LocationRole = Qt::UserRole,
32 LocationNameRole,
33 LastUsedRole,
34 UseCountRole,
35 IsRemovableRole,
36 };
37 Q_ENUM(Role)
38
39 [[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override;
40 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
41 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
42 Q_INVOKABLE bool removeRow(int row, const QModelIndex &parent = QModelIndex()); // not exported to QML by default...
43 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = {}) override;
44
45public Q_SLOTS:
46 /** Add a location to the history.
47 * If already present, just the usage data will be updated.
48 */
49 void addLocation(const KPublicTransport::Location &loc);
50
51 /** Add a preset location.
52 * That is, a location that is programmatically determined and isn't actually in
53 * the history, nor can it be removed.
54 */
55 void addPresetLocation(const KPublicTransport::Location &loc, const QDateTime &lastUse, int useCount);
56
57 /** Remove all preset locations, only keeping the history locations. */
58 void clearPresetLocations();
59
60 /** Delete the entire history content. */
61 void clear();
62
63private:
64 struct Data {
65 QString id;
66 Location loc;
67 QDateTime lastUse;
68 int useCount = 0;
69 bool removable = true;
70 };
71
72 void rescan();
73 static void store(const Data &data);
74
75 std::vector<Data> m_locations;
76};
77
78}
79
80#endif // KPUBLICTRANSPORT_LOCATIONHISTORYMODEL_H
Model of frequently/recently used locations.
Query operations and data types for accessing realtime public transport information from online servi...
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.