File indexing completed on 2024-05-12 04:42:08
0001 /* 0002 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #ifndef KOSMINDOORMAP_AMENITYMODEL_H 0007 #define KOSMINDOORMAP_AMENITYMODEL_H 0008 0009 #include <KOSMIndoorMap/MapData> 0010 #include <KOSMIndoorMap/MapCSSStyle> 0011 0012 #include <KOSM/Element> 0013 0014 #include <QAbstractListModel> 0015 0016 namespace KOSMIndoorMap { 0017 0018 /** List all amenities in a given data set. */ 0019 class AmenityModel : public QAbstractListModel 0020 { 0021 Q_OBJECT 0022 Q_PROPERTY(KOSMIndoorMap::MapData mapData READ mapData WRITE setMapData NOTIFY mapDataChanged) 0023 public: 0024 explicit AmenityModel(QObject *parent = nullptr); 0025 ~AmenityModel(); 0026 0027 [[nodiscard]] MapData mapData() const; 0028 void setMapData(const MapData &data); 0029 0030 enum Role { 0031 NameRole = Qt::DisplayRole, 0032 CoordinateRole = Qt::UserRole, 0033 LevelRole, 0034 ElementRole, 0035 TypeNameRole, 0036 GroupRole, 0037 GroupNameRole, 0038 IconSourceRole, 0039 CuisineRole, ///< details on entries in the FoodGroup 0040 FallbackNameRole, ///< Brand/operator/network name, better than nothing but not the first choice to display 0041 OpeningHoursRole, ///< opening hours expression 0042 }; 0043 Q_ENUM(Role) 0044 0045 enum Group { 0046 UndefinedGroup, 0047 FoodGroup, 0048 ShopGroup, 0049 ToiletGroup, 0050 AmenityGroup, 0051 HealthcareGroup, 0052 AccommodationGroup, 0053 }; 0054 Q_ENUM(Group) 0055 0056 [[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override; 0057 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override; 0058 [[nodiscard]] QHash<int, QByteArray> roleNames() const override; 0059 0060 Q_SIGNALS: 0061 void mapDataChanged(); 0062 0063 private: 0064 struct Entry { 0065 OSM::Element element; 0066 int level; 0067 Group group = UndefinedGroup; 0068 QByteArray typeKey; 0069 QString icon; 0070 }; 0071 0072 void populateModel(); 0073 static QString iconSource(const Entry &entry); 0074 0075 MapData m_data; 0076 MapCSSStyle m_style; 0077 std::vector<Entry> m_entries; 0078 OSM::Languages m_langs; 0079 }; 0080 0081 } 0082 0083 #endif // KOSMINDOORMAP_AMENITYMODEL_H