File indexing completed on 2024-11-24 04:15:36
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KOSMINDOORMAP_GATEMODEL_H 0008 #define KOSMINDOORMAP_GATEMODEL_H 0009 0010 #include "kosmindoormap_export.h" 0011 0012 #include <KOSMIndoorMap/MapData> 0013 0014 #include <KOSM/Element> 0015 0016 #include <QAbstractListModel> 0017 0018 namespace KOSMIndoorMap { 0019 0020 /** An airport gate. */ 0021 struct Gate { 0022 OSM::Node node; 0023 OSM::Element sourceElement; 0024 QString name; 0025 int level = 0; 0026 }; 0027 0028 0029 /** Lists all airport gates found in the current map. 0030 * This also contains the concept of (optional) arrival/departure gates, 0031 * for matching gate names from other sources and highlighting those in the output. 0032 */ 0033 class KOSMINDOORMAP_EXPORT GateModel : public QAbstractListModel 0034 { 0035 Q_OBJECT 0036 Q_PROPERTY(KOSMIndoorMap::MapData mapData READ mapData WRITE setMapData NOTIFY mapDataChanged) 0037 Q_PROPERTY(bool isEmpty READ isEmpty NOTIFY mapDataChanged) 0038 0039 /** Row indexes of the matched arrival/departure gates, if found and/or set, otherwise @c -1. */ 0040 Q_PROPERTY(int arrivalGateRow READ arrivalGateRow NOTIFY gateIndexChanged) 0041 Q_PROPERTY(int departureGateRow READ departureGateRow NOTIFY gateIndexChanged) 0042 public: 0043 explicit GateModel(QObject *parent = nullptr); 0044 ~GateModel(); 0045 0046 MapData mapData() const; 0047 void setMapData(const MapData &data); 0048 0049 bool isEmpty() const; 0050 0051 enum Role { 0052 CoordinateRole = Qt::UserRole, 0053 ElementRole, 0054 LevelRole, 0055 ArrivalGateRole, 0056 DepartureGateRole, 0057 HiddenElementRole, 0058 }; 0059 Q_ENUM(Role) 0060 0061 int rowCount(const QModelIndex &parent = {}) const override; 0062 QVariant data(const QModelIndex & index, int role) const override; 0063 QHash<int, QByteArray> roleNames() const override; 0064 0065 /** Match arrival/departure gates against what we found in the map data. */ 0066 Q_INVOKABLE void setArrivalGate(const QString &name); 0067 Q_INVOKABLE void setDepartureGate(const QString &name); 0068 0069 int arrivalGateRow() const; 0070 int departureGateRow() const; 0071 0072 Q_SIGNALS: 0073 void mapDataChanged(); 0074 void gateIndexChanged(); 0075 0076 private: 0077 void populateModel(); 0078 void matchGates(); 0079 int matchGate(const QString &name) const; 0080 void setGateTag(int idx, OSM::TagKey key, bool enabled); 0081 0082 std::vector<Gate> m_gates; 0083 MapData m_data; 0084 0085 struct { 0086 OSM::TagKey mxArrival; 0087 OSM::TagKey mxDeparture; 0088 } m_tagKeys; 0089 0090 QString m_arrivalGate; 0091 QString m_departureGate; 0092 int m_arrivalGateRow = -1; 0093 int m_departureGateRow = -1; 0094 }; 0095 0096 } 0097 0098 #endif // KOSMINDOORMAP_GATEMODEL_H