File indexing completed on 2024-05-12 04:42:51
0001 /* 0002 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KPUBLICTRANSPORT_BACKENDMODEL_H 0008 #define KPUBLICTRANSPORT_BACKENDMODEL_H 0009 0010 #include "kpublictransport_export.h" 0011 0012 #include <QAbstractListModel> 0013 0014 #include <memory> 0015 0016 namespace KPublicTransport { 0017 0018 class BackendModelPrivate; 0019 class Manager; 0020 0021 /** Model listing backends and allowing to configure which ones are active. */ 0022 class KPUBLICTRANSPORT_EXPORT BackendModel : public QAbstractListModel 0023 { 0024 Q_OBJECT 0025 0026 /** Sets the KPublicTransport::Manager instance. Necessary for this to work at all. */ 0027 Q_PROPERTY(KPublicTransport::Manager* manager READ manager WRITE setManager NOTIFY managerChanged) 0028 /** Configures the grouping mode for the content of this model. */ 0029 Q_PROPERTY(Mode mode READ mode WRITE setMode NOTIFY modeChanged) 0030 public: 0031 explicit BackendModel(QObject *parent = nullptr); 0032 ~BackendModel() override; 0033 0034 /** Content grouping modes. */ 0035 enum Mode { 0036 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. 0037 GroupByCountry, ///< A backend might occur multiple times, for each country it is associated with. 0038 }; 0039 Q_ENUM(Mode) 0040 0041 Mode mode() const; 0042 void setMode(Mode mode); 0043 0044 enum Roles { 0045 NameRole = Qt::DisplayRole, 0046 DescriptionRole = Qt::UserRole, 0047 IdentifierRole, 0048 SecureRole, 0049 ItemEnabledRole, 0050 BackendEnabledRole, 0051 PrimaryCountryCodeRole [[deprecated("use CountryCodeRole")]], ///< @deprecated use CountryCodeRole instead 0052 CountryCodeRole, ///< a ISO 3166-1 code usable for grouping content by country 0053 }; 0054 0055 Manager* manager() const; 0056 void setManager(Manager *mgr); 0057 0058 int rowCount(const QModelIndex &parent = {}) const override; 0059 QVariant data(const QModelIndex &index, int role) const override; 0060 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 0061 Qt::ItemFlags flags(const QModelIndex &index) const override; 0062 QHash<int, QByteArray> roleNames() const override; 0063 0064 Q_SIGNALS: 0065 void managerChanged(); 0066 void modeChanged(); 0067 0068 private: 0069 friend class BackendModelPrivate; 0070 const std::unique_ptr<BackendModelPrivate> d; 0071 }; 0072 0073 } 0074 0075 #endif // KPUBLICTRANSPORT_BACKENDMODEL_H