KOSMIndoorMap

osmelementinformationmodel.h
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
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 
16 namespace 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 {
23  Q_OBJECT
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 
29 public:
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  Routes,
62  Cuisine,
63  Diet,
64  Takeaway,
65  Socket,
66  OpeningHours,
67  AvailableVehicles,
68  Fee,
69  Authentication,
70  BicycleParking,
71  Capacity,
72  CapacityDisabled,
73  CapacityWomen,
74  CapacityParent,
75  CapacityCharing,
76  MaxStay,
77  DiaperChangingTable,
78  Wikipedia,
79  Address,
80  Phone,
81  Email,
82  Website,
83  PaymentCash,
84  PaymentDigital,
85  PaymentDebitCard,
86  PaymentCreditCard,
87  PaymentStoredValueCard,
88  Wheelchair,
89  CentralKey,
90  OperatorName,
91  Network,
92  OperatorWikipedia,
93  RemainingRange,
94  DebugLink,
95  DebugKey,
96  };
97  Q_ENUM(Key)
98  enum Type {
99  String,
100  Link,
101  PostalAddress,
102  OpeningHoursType,
103  };
104  Q_ENUM(Type)
105 
106  OSMElement element() const;
107  void setElement(const OSMElement &element);
108  Q_INVOKABLE void clear();
109 
110  QString name() const;
111  QString category() const;
112 
113  int rowCount(const QModelIndex &parent = {}) const override;
114  QVariant data(const QModelIndex &index, int role) const override;
115  QHash<int, QByteArray> roleNames() const override;
116 
117 Q_SIGNALS:
118  void elementChanged();
119 
120 private:
121  struct Info;
122 
123  void reload();
124  /** Resolve elements who's group depends on context. */
125  void resolveCategories();
126  /** Make sure we have at least one naming element. */
127  void resolveHeaders();
128  bool promoteMainCategory(KeyCategory cat);
129  QString categoryLabel(KeyCategory cat) const;
130  QString debugTagKey(int row) const;
131  QString debugTagValue(int row) const;
132  QString keyName(Key key) const;
133  QVariant valueForKey(Info info) const;
134  QVariant urlify(const QVariant &v, Key key) const;
135  QString paymentMethodList(Key key) const;
136  QString paymentMethodValue(Key key) const;
137  QUrl wikipediaUrl(const QByteArray &wp) const;
138  QString capacitryValue(const char *prop) const;
139 
140  template <typename KeyMapEntry, std::size_t N>
141  void addEntryForKey(const char *keyName, const KeyMapEntry(&map)[N]);
142 
143  OSM::Element m_element;
144 
145  struct Info {
146  Key key;
147  KeyCategory category;
148 
149  bool operator<(Info other) const;
150  bool operator==(Info other) const;
151  };
152  std::vector<Info> m_infos;
153  Key m_nameKey = NoKey;
154  Key m_categoryKey = NoKey;
155  bool m_debug = false;
156 };
157 
158 }
159 
160 #endif // KOSMINDOORMAP_OSMELEMENTINFORMATIONMODEL_H
Q_ENUM(...)
OSM-based multi-floor indoor maps for buildings.
QML wrapper around an OSM element.
Definition: osmelement.h:18
Q_SIGNALSQ_SIGNALS
A reference to any of OSM::Node/OSMWay/OSMRelation.
Definition: element.h:22
Q_OBJECTQ_OBJECT
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
UserRole
Q_PROPERTY(...)
Q_INVOKABLEQ_INVOKABLE
Model containing information about a selected element.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:03:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.