File indexing completed on 2024-05-12 04:42:10

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_OSMELEMENTINFORMATIONMODEL_H
0008 #define KOSMINDOORMAP_OSMELEMENTINFORMATIONMODEL_H
0009 
0010 #include "osmelement.h"
0011 
0012 #include <osm/element.h>
0013 
0014 #include <QAbstractListModel>
0015 
0016 namespace KOSMIndoorMap {
0017 
0018 /** Model containing information about a selected element.
0019  *  Exact content depends on the type of element and the available information.
0020  */
0021 class OSMElementInformationModel : public QAbstractListModel
0022 {
0023     Q_OBJECT
0024     Q_PROPERTY(KOSMIndoorMap::OSMElement element READ element WRITE setElement NOTIFY elementChanged)
0025     Q_PROPERTY(QString name READ name NOTIFY elementChanged)
0026     Q_PROPERTY(QString category READ category NOTIFY elementChanged)
0027     Q_PROPERTY(bool debug MEMBER m_debug)
0028 
0029 public:
0030     explicit OSMElementInformationModel(QObject *parent = nullptr);
0031     ~OSMElementInformationModel();
0032 
0033     enum Role {
0034         KeyRole = Qt::UserRole,
0035         KeyLabelRole,
0036         ValueRole,
0037         ValueUrlRole,
0038         CategoryRole,
0039         CategoryLabelRole,
0040         TypeRole,
0041     };
0042     enum KeyCategory {
0043         UnresolvedCategory,
0044         Header,
0045         Main,
0046         OpeningHoursCategory,
0047         Contact,
0048         Payment,
0049         Toilets,
0050         Accessibility,
0051         Parking,
0052         Operator,
0053         DebugCategory,
0054     };
0055     Q_ENUM(KeyCategory)
0056     enum Key {
0057         NoKey,
0058         Name,
0059         Category,
0060         OldName,
0061         Description,
0062         Routes,
0063         Cuisine,
0064         Diet,
0065         Takeaway,
0066         Socket,
0067         OpeningHours,
0068         AvailableVehicles,
0069         Fee,
0070         Authentication,
0071         BicycleParking,
0072         Capacity,
0073         CapacityDisabled,
0074         CapacityWomen,
0075         CapacityParent,
0076         CapacityCharing,
0077         MaxStay,
0078         DiaperChangingTable,
0079         Gender,
0080         Wikipedia,
0081         Address,
0082         Phone,
0083         Email,
0084         Website,
0085         PaymentCash,
0086         PaymentDigital,
0087         PaymentDebitCard,
0088         PaymentCreditCard,
0089         PaymentStoredValueCard,
0090         Wheelchair,
0091         WheelchairLift,
0092         CentralKey,
0093         SpeechOutput,
0094         TactileWriting,
0095         OperatorName,
0096         Network,
0097         OperatorWikipedia,
0098         RemainingRange,
0099         DebugLink,
0100         DebugKey,
0101     };
0102     Q_ENUM(Key)
0103     enum Type {
0104         String,
0105         Link,
0106         PostalAddress,
0107         OpeningHoursType,
0108     };
0109     Q_ENUM(Type)
0110 
0111     OSMElement element() const;
0112     void setElement(const OSMElement &element);
0113     Q_INVOKABLE void clear();
0114 
0115     QString name() const;
0116     QString category() const;
0117 
0118     int rowCount(const QModelIndex &parent = {}) const override;
0119     QVariant data(const QModelIndex &index, int role) const override;
0120     QHash<int, QByteArray> roleNames() const override;
0121 
0122 Q_SIGNALS:
0123     void elementChanged();
0124 
0125 private:
0126     struct Info;
0127 
0128     void reload();
0129     /** Resolve elements who's group depends on context. */
0130     void resolveCategories();
0131     /** Make sure we have at least one naming element. */
0132     void resolveHeaders();
0133     bool promoteMainCategory(KeyCategory cat);
0134     QString categoryLabel(KeyCategory cat) const;
0135     QString debugTagKey(int row) const;
0136     QString debugTagValue(int row) const;
0137     QString keyName(Key key) const;
0138     QVariant valueForKey(Info info) const;
0139     QVariant urlify(const QVariant &v, Key key) const;
0140     QString paymentMethodList(Key key) const;
0141     QString paymentMethodValue(Key key) const;
0142     QUrl wikipediaUrl(const QByteArray &wp) const;
0143     QString capacitryValue(const char *prop) const;
0144     QString translatedBoolValue(const QByteArray &value) const;
0145 
0146     template <typename KeyMapEntry, std::size_t N>
0147     void addEntryForKey(const char *keyName, const KeyMapEntry(&map)[N]);
0148     template <typename KeyMapEntry, std::size_t N>
0149     void addEntryForLocalizedKey(const char *keyName, const KeyMapEntry(&map)[N]);
0150 
0151     OSM::Element m_element;
0152 
0153     struct Info {
0154         Key key;
0155         KeyCategory category;
0156 
0157         bool operator<(Info other) const;
0158         bool operator==(Info other) const;
0159     };
0160     std::vector<Info> m_infos;
0161     OSM::Languages m_langs;
0162     Key m_nameKey = NoKey;
0163     Key m_categoryKey = NoKey;
0164     bool m_debug = false;
0165 };
0166 
0167 }
0168 
0169 #endif // KOSMINDOORMAP_OSMELEMENTINFORMATIONMODEL_H