KOSMIndoorMap

roommodel.h
1/*
2 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KOSMINDOORMAP_ROOMMODEL_H
7#define KOSMINDOORMAP_ROOMMODEL_H
8
9#include <KOSMIndoorMap/MapData>
10#include <KOSMIndoorMap/MapCSSStyle>
11
12#include <KOSM/Element>
13
14#include <QAbstractListModel>
15#include <QDateTime>
16#include <QPolygonF>
17
18namespace KOSMIndoorMap {
19
20/** List all rooms of buildings in a given data set. */
22{
24 Q_PROPERTY(KOSMIndoorMap::MapData mapData READ mapData WRITE setMapData NOTIFY mapDataChanged)
25 /** Number of buildings found in the model data. */
26 Q_PROPERTY(int buildingCount READ buildingCount NOTIFY populated)
27 /** Returns @c true if there are no rooms in the current map data.
28 * @note Binding to this will disable lazy model population.
29 */
30 Q_PROPERTY(bool isEmpty READ isEmpty NOTIFY mapDataChanged)
31
32 /** Time range for which to show the model.
33 * When set this is used to evaluate time-dependent content.
34 */
35 Q_PROPERTY(QDateTime beginTime MEMBER m_beginTime NOTIFY timeChanged)
36 Q_PROPERTY(QDateTime endTime MEMBER m_endTime NOTIFY timeChanged)
37
38public:
39 explicit RoomModel(QObject *parent = nullptr);
40 ~RoomModel();
41
42 [[nodiscard]] MapData mapData() const;
43 void setMapData(const MapData &data);
44
45 enum Role {
46 NameRole = Qt::DisplayRole, ///< room name, if set
47 CoordinateRole = Qt::UserRole,
48 NumberRole, ///< room number, if set
49 LevelRole, ///< numeric level for positioning rather than for display
50 ElementRole, ///< OSM element for this room
51 TypeNameRole, ///< Type of the room as translated human readable text, if set
52 BuildingNameRole, ///< Name of the building the room is in
53 LevelLongNameRole, ///< Name of the floor the room is on (long form, if available)
54 LevelShortNameRole, ///< Name of the floor the room is on (short form, if available)
55 };
57
58 [[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override;
59 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
60 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
61
62 [[nodiscard]] int buildingCount() const;
63 [[nodiscard]] bool isEmpty() const;
64
65 /** Tries to identify the given room name or number and returns the row index if found. */
66 Q_INVOKABLE [[nodiscard]] int findRoom(const QString &name) const;
67
69 void mapDataChanged();
70 void populated();
71 void timeChanged();
72
73private:
74 struct Level {
75 OSM::Element element;
76 int level;
77 };
78
79 struct Building {
80 OSM::Element element;
81 QPolygonF outerPath;
82 std::vector<Level> levels;
83 int roomCount = 0;
84 };
85
86 struct Room {
87 OSM::Element element;
88 OSM::Element buildingElement;
89 OSM::Element levelElement;
90 int level;
91 QString name;
92 };
93
94 void ensurePopulated() const;
95 void populateModel();
96
97 MapData m_data;
98 MapCSSStyle m_style;
99
100 QDateTime m_beginTime;
101 QDateTime m_endTime;
102
103 std::vector<Building> m_buildings;
104 std::vector<Room> m_rooms;
105
106 OSM::Languages m_langs;
107};
108
109}
110
111#endif // KOSMINDOORMAP_ROOMMODEL_H
Raw OSM map data, separated by levels.
Definition mapdata.h:60
List all rooms of buildings in a given data set.
Definition roommodel.h:22
Q_INVOKABLE int findRoom(const QString &name) const
Tries to identify the given room name or number and returns the row index if found.
QDateTime beginTime
Time range for which to show the model.
Definition roommodel.h:35
int buildingCount
Number of buildings found in the model data.
Definition roommodel.h:26
bool isEmpty
Returns true if there are no rooms in the current map data.
Definition roommodel.h:30
@ TypeNameRole
Type of the room as translated human readable text, if set.
Definition roommodel.h:51
@ NumberRole
room number, if set
Definition roommodel.h:48
@ LevelRole
numeric level for positioning rather than for display
Definition roommodel.h:49
@ ElementRole
OSM element for this room.
Definition roommodel.h:50
@ LevelShortNameRole
Name of the floor the room is on (short form, if available)
Definition roommodel.h:54
@ NameRole
room name, if set
Definition roommodel.h:46
@ LevelLongNameRole
Name of the floor the room is on (long form, if available)
Definition roommodel.h:53
@ BuildingNameRole
Name of the building the room is in.
Definition roommodel.h:52
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
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:16:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.