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 };
36 Q_ENUM(Role)
37
38 int rowCount(const QModelIndex &parent = {}) const override;
39 QVariant data(const QModelIndex &index, int role) const override;
40 QHash<int, QByteArray> roleNames() const override;
41 Q_INVOKABLE bool removeRow(int row, const QModelIndex &parent = QModelIndex()); // not exported to QML by default...
42 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = {}) override;
43
44public Q_SLOTS:
45 /** Add a location to the history.
46 * If already present, just the usage data will be updated.
47 */
48 void addLocation(const KPublicTransport::Location &loc);
49
50 /** Delete the entire history content. */
51 void clear();
52
53private:
54 struct Data {
55 QString id;
56 Location loc;
57 QDateTime lastUse;
58 int useCount = 0;
59 };
60
61 void rescan();
62 void store(const Data &data) const;
63
64 std::vector<Data> m_locations;
65};
66
67}
68
69#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 Tue Mar 26 2024 11:13:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.