KOSMIndoorMap

osmelementinformationmodel.h
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KOSMINDOORMAP_OSMELEMENTINFORMATIONMODEL_H
8#define KOSMINDOORMAP_OSMELEMENTINFORMATIONMODEL_H
9
10#include "osmelement.h"
11
12#include <osm/element.h>
13
14#include <QAbstractListModel>
15
16namespace KOSMIndoorMap {
17
18/** Model containing information about a selected element.
19 * Exact content depends on the type of element and the available information.
20 */
22{
24 Q_PROPERTY(KOSMIndoorMap::OSMElement element READ element WRITE setElement NOTIFY elementChanged)
25 Q_PROPERTY(QString name READ name NOTIFY elementChanged)
26 Q_PROPERTY(QString category READ category NOTIFY elementChanged)
27 Q_PROPERTY(bool debug MEMBER m_debug)
28
29public:
30 explicit OSMElementInformationModel(QObject *parent = nullptr);
32
33 enum Role {
34 KeyRole = Qt::UserRole,
35 KeyLabelRole,
36 ValueRole,
37 ValueUrlRole,
38 CategoryRole,
39 CategoryLabelRole,
40 TypeRole,
41 };
42 enum KeyCategory {
43 UnresolvedCategory,
44 Header,
45 Main,
46 OpeningHoursCategory,
47 Contact,
48 Payment,
49 Toilets,
50 Accessibility,
51 Parking,
52 Operator,
53 DebugCategory,
54 };
55 Q_ENUM(KeyCategory)
56 enum Key {
57 NoKey,
58 Name,
59 Category,
60 OldName,
61 Description,
62 Routes,
63 Cuisine,
64 Diet,
65 Takeaway,
66 Socket,
67 OpeningHours,
68 AvailableVehicles,
69 Fee,
70 Authentication,
71 BicycleParking,
72 Capacity,
73 CapacityDisabled,
74 CapacityWomen,
75 CapacityParent,
76 CapacityCharing,
77 MaxStay,
78 DiaperChangingTable,
79 Gender,
80 Wikipedia,
81 Address,
82 Phone,
83 Email,
84 Website,
85 PaymentCash,
86 PaymentDigital,
87 PaymentDebitCard,
88 PaymentCreditCard,
89 PaymentStoredValueCard,
90 Wheelchair,
91 WheelchairLift,
92 CentralKey,
93 SpeechOutput,
94 TactileWriting,
95 OperatorName,
96 Network,
97 OperatorWikipedia,
98 RemainingRange,
99 DebugLink,
100 DebugKey,
101 };
102 Q_ENUM(Key)
103 enum Type {
104 String,
105 Link,
106 PostalAddress,
107 OpeningHoursType,
108 };
109 Q_ENUM(Type)
110
111 OSMElement element() const;
112 void setElement(const OSMElement &element);
113 Q_INVOKABLE void clear();
114
115 QString name() const;
116 QString category() const;
117
118 int rowCount(const QModelIndex &parent = {}) const override;
119 QVariant data(const QModelIndex &index, int role) const override;
120 QHash<int, QByteArray> roleNames() const override;
121
123 void elementChanged();
124
125private:
126 struct Info;
127
128 void reload();
129 /** Resolve elements who's group depends on context. */
130 void resolveCategories();
131 /** Make sure we have at least one naming element. */
132 void resolveHeaders();
133 bool promoteMainCategory(KeyCategory cat);
134 QString categoryLabel(KeyCategory cat) const;
135 QString debugTagKey(int row) const;
136 QString debugTagValue(int row) const;
137 QString keyName(Key key) const;
138 QVariant valueForKey(Info info) const;
139 QVariant urlify(const QVariant &v, Key key) const;
140 QString paymentMethodList(Key key) const;
141 QString paymentMethodValue(Key key) const;
142 QUrl wikipediaUrl(const QByteArray &wp) const;
143 QString capacitryValue(const char *prop) const;
144 QString translatedBoolValue(const QByteArray &value) const;
145
146 template <typename KeyMapEntry, std::size_t N>
147 void addEntryForKey(const char *keyName, const KeyMapEntry(&map)[N]);
148 template <typename KeyMapEntry, std::size_t N>
149 void addEntryForLocalizedKey(const char *keyName, const KeyMapEntry(&map)[N]);
150
151 OSM::Element m_element;
152
153 struct Info {
154 Key key;
155 KeyCategory category;
156
157 bool operator<(Info other) const;
158 bool operator==(Info other) const;
159 };
160 std::vector<Info> m_infos;
161 OSM::Languages m_langs;
162 Key m_nameKey = NoKey;
163 Key m_categoryKey = NoKey;
164 bool m_debug = false;
165};
166
167}
168
169#endif // KOSMINDOORMAP_OSMELEMENTINFORMATIONMODEL_H
Model containing information about a selected element.
QML wrapper around an OSM element.
Definition osmelement.h:19
A reference to any of OSM::Node/OSM::Way/OSM::Relation.
Definition element.h:24
Languages in preference order to consider when looking up translated tag values.
Definition languages.h:25
OSM-based multi-floor indoor maps for buildings.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
Q_ENUM(...)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.