KPublicTransport

backendmodel.h
1/*
2 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPUBLICTRANSPORT_BACKENDMODEL_H
8#define KPUBLICTRANSPORT_BACKENDMODEL_H
9
10#include "kpublictransport_export.h"
11
12#include <QAbstractListModel>
13
14#include <memory>
15
16namespace KPublicTransport {
17
18class BackendModelPrivate;
19class Manager;
20
21/** Model listing backends and allowing to configure which ones are active. */
22class KPUBLICTRANSPORT_EXPORT BackendModel : public QAbstractListModel
23{
24 Q_OBJECT
25
26 /** Sets the KPublicTransport::Manager instance. Necessary for this to work at all. */
27 Q_PROPERTY(KPublicTransport::Manager* manager READ manager WRITE setManager NOTIFY managerChanged)
28 /** Configures the grouping mode for the content of this model. */
29 Q_PROPERTY(Mode mode READ mode WRITE setMode NOTIFY modeChanged)
30public:
31 explicit BackendModel(QObject *parent = nullptr);
32 ~BackendModel() override;
33
34 /** Content grouping modes. */
35 enum Mode {
36 Flat, ///< Each backend appears exactly once, grouping by country is possible (the data is order by country), but multi-country operators might not be properly associated.
37 GroupByCountry, ///< A backend might occur multiple times, for each country it is associated with.
38 };
39 Q_ENUM(Mode)
40
41 [[nodiscard]] Mode mode() const;
42 void setMode(Mode mode);
43
44 enum Roles {
45 NameRole = Qt::DisplayRole,
46 DescriptionRole = Qt::UserRole,
47 IdentifierRole,
48 SecureRole,
49 ItemEnabledRole,
50 BackendEnabledRole,
51 PrimaryCountryCodeRole [[deprecated("use CountryCodeRole")]], ///< @deprecated use CountryCodeRole instead
52 CountryCodeRole, ///< a ISO 3166-1 code usable for grouping content by country
53 };
54
55 [[nodiscard]] Manager* manager() const;
56 void setManager(Manager *mgr);
57
58 [[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override;
59 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
60 [[nodiscard]] bool setData(const QModelIndex &index, const QVariant &value, int role) override;
61 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
62 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
63
64Q_SIGNALS:
65 void managerChanged();
66 void modeChanged();
67
68private:
69 friend class BackendModelPrivate;
70 const std::unique_ptr<BackendModelPrivate> d;
71};
72
73}
74
75#endif // KPUBLICTRANSPORT_BACKENDMODEL_H
Model listing backends and allowing to configure which ones are active.
Mode
Content grouping modes.
@ GroupByCountry
A backend might occur multiple times, for each country it is associated with.
@ Flat
Each backend appears exactly once, grouping by country is possible (the data is order by country),...
@ CountryCodeRole
a ISO 3166-1 code usable for grouping content by country
Entry point for starting public transport queries.
Definition manager.h:42
Query operations and data types for accessing realtime public transport information from online servi...
DisplayRole
typedef ItemFlags
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.