KPublicTransport

backendmodel.h
1 /*
2  SPDX-FileCopyrightText: 2019 Volker Krause <[email protected]>
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 
16 namespace KPublicTransport {
17 
18 class BackendModelPrivate;
19 class Manager;
20 
21 /** Model listing backends and allowing to configure which ones are active. */
22 class 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)
30 public:
31  explicit BackendModel(QObject *parent = nullptr);
32  ~BackendModel();
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  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  Manager* manager() const;
56  void setManager(Manager *mgr);
57 
58  int rowCount(const QModelIndex &parent = {}) const override;
59  QVariant data(const QModelIndex &index, int role) const override;
60  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
61  Qt::ItemFlags flags(const QModelIndex &index) const override;
62  QHash<int, QByteArray> roleNames() const override;
63 
64 Q_SIGNALS:
65  void managerChanged();
66  void modeChanged();
67 
68 private:
69  friend class BackendModelPrivate;
70  const std::unique_ptr<BackendModelPrivate> d;
71 };
72 
73 }
74 
75 #endif // KPUBLICTRANSPORT_BACKENDMODEL_H
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
Mode
Content grouping modes.
Definition: backendmodel.h:35
Each backend appears exactly once, grouping by country is possible (the data is order by country)...
Definition: backendmodel.h:36
A backend might occur multiple times, for each country it is associated with.
Definition: backendmodel.h:37
Definition: location.h:16
DisplayRole
a ISO 3166-1 code usable for grouping content by country
Definition: backendmodel.h:52
Model listing backends and allowing to configure which ones are active.
Definition: backendmodel.h:22
Entry point for starting public transport queries.
Definition: manager.h:41
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 23:07:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.