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 <wikidata/entities.h>
15#include <wikidata/wikidataquerymanager.h>
16
17#include <QAbstractListModel>
18
19namespace KOSMIndoorMap {
20
21/** Model containing information about a selected element.
22 * Exact content depends on the type of element and the available information.
23 */
25{
27 Q_PROPERTY(KOSMIndoorMap::OSMElement element READ element WRITE setElement NOTIFY elementChanged)
28 Q_PROPERTY(QString name READ name NOTIFY elementChanged)
29 Q_PROPERTY(QString category READ category NOTIFY elementChanged)
30 Q_PROPERTY(bool allowOnlineContent MEMBER m_allowOnlineContent NOTIFY allowOnlineContentChanged)
31 Q_PROPERTY(bool debug MEMBER m_debug)
32
33public:
34 explicit OSMElementInformationModel(QObject *parent = nullptr);
36
37 enum Role {
38 KeyRole = Qt::UserRole,
39 KeyLabelRole,
40 ValueRole,
41 ValueUrlRole,
42 CategoryRole,
43 CategoryLabelRole,
44 TypeRole,
45 };
46 enum KeyCategory {
47 UnresolvedCategory,
48 Header,
49 Main,
50 OpeningHoursCategory,
51 Contact,
52 Payment,
53 Toilets,
54 Accessibility,
55 Parking,
56 Operator,
57 DebugCategory,
58 };
59 Q_ENUM(KeyCategory)
60 enum Key {
61 NoKey,
62 Name,
63 Category,
64 Image,
65 Logo,
66 OldName,
67 Description,
68 Routes,
69 Cuisine,
70 VendingMachineOffer,
71 Diet,
72 Takeaway,
73 Socket,
74 OpeningHours,
75 AvailableVehicles,
76 Fee,
77 Authentication,
78 BicycleParking,
79 Capacity,
80 CapacityDisabled,
81 CapacityWomen,
82 CapacityParent,
83 CapacityCharing,
84 MaxStay,
85 DiaperChangingTable,
86 Gender,
87 Wikipedia,
88 Address,
89 Phone,
90 Email,
91 Website,
92 PaymentCash,
93 PaymentDigital,
94 PaymentDebitCard,
95 PaymentCreditCard,
96 PaymentStoredValueCard,
97 Wheelchair,
98 WheelchairLift,
99 CentralKey,
100 SpeechOutput,
101 TactileWriting,
102 OperatorName,
103 Network,
104 OperatorWikipedia,
105 RemainingRange,
106 DebugLink,
107 DebugKey,
108 };
109 Q_ENUM(Key)
110 enum Type {
111 String,
112 Link,
113 PostalAddress,
114 OpeningHoursType,
115 ImageType,
116 };
117 Q_ENUM(Type)
118
119 [[nodiscard]] OSMElement element() const;
120 void setElement(const OSMElement &element);
121 Q_INVOKABLE void clear();
122
123 [[nodiscard]] QString name() const;
124 [[nodiscard]] QString category() const;
125
126 [[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override;
127 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
128 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
129
131 void elementChanged();
132 void allowOnlineContentChanged();
133
134private:
135 struct Info;
136
137 void reload();
138 /** Process online content, filter out things we don't want, etc. */
139 void resolveOnlineContent();
140 /** Resolve elements who's group depends on context. */
141 void resolveCategories();
142 /** Make sure we have at least one naming element. */
143 void resolveHeaders();
144 [[nodiscard]] bool promoteMainCategory(KeyCategory cat);
145 [[nodiscard]] QString categoryLabel(KeyCategory cat) const;
146 [[nodiscard]] QString debugTagKey(int row) const;
147 [[nodiscard]] QString debugTagValue(int row) const;
148 [[nodiscard]] QUrl debugTagUrl(int row) const;
149 [[nodiscard]] QString keyName(Key key) const;
150 [[nodiscard]] QVariant valueForKey(Info info) const;
151 [[nodiscard]] QVariant urlify(const QVariant &v, Key key) const;
152 [[nodiscard]] QString paymentMethodList(Key key) const;
153 [[nodiscard]] QString paymentMethodValue(Key key) const;
154 [[nodiscard]] QUrl wikipediaUrl(const QByteArray &wp) const;
155 [[nodiscard]] QString capacitryValue(const char *prop) const;
156 [[nodiscard]] QString translatedBoolValue(const QByteArray &value) const;
157
158 template <typename KeyMapEntry, std::size_t N>
159 void addEntryForKey(const char *keyName, const KeyMapEntry(&map)[N]);
160 template <typename KeyMapEntry, std::size_t N>
161 void addEntryForLocalizedKey(const char *keyName, const KeyMapEntry(&map)[N]);
162
163 OSM::Element m_element;
164
165 struct Info {
166 Key key;
167 KeyCategory category;
168
169 [[nodiscard]] bool operator<(Info other) const;
170 [[nodiscard]] bool operator==(Info other) const;
171 };
172 std::vector<Info> m_infos;
173 OSM::Languages m_langs;
174 Key m_nameKey = NoKey;
175 Key m_categoryKey = NoKey;
176 bool m_allowOnlineContent = false;
177 bool m_debug = false;
178
179 Wikidata::QueryManager m_wikidataMgr;
180 QHash<Wikidata::Q, QString> m_wikidataImageMap;
181};
182
183}
184
185#endif // KOSMINDOORMAP_OSMELEMENTINFORMATIONMODEL_H
Model containing information about a selected element.
QML wrapper around an OSM element.
Definition osmelement.h:21
A reference to any of OSM::Node/OSMWay/OSMRelation.
Definition element.h:24
Languages in preference order to consider when looking up translated tag values.
Definition languages.h:25
Executes wikidata queries.
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 Fri Jul 26 2024 11:57:46 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.