KOSMIndoorMap

platformmodel.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_PLATFORMMODEL_H
8#define KOSMINDOORMAP_PLATFORMMODEL_H
9
10#include "kosmindoormap_export.h"
11
12#include <KOSMIndoorMap/MapData>
13#include <KOSMIndoorMap/Platform>
14
15#include <QAbstractItemModel>
16#include <QTimer>
17
18namespace KOSMIndoorMap {
19
20/** Lists all platforms/tracks and platform sections found in the current map.
21 * There's also the concept of (optional) arrival/departure platforms in here to highlight
22 * arriving/departing locations when used in context of a planned journey.
23 */
24class KOSMINDOORMAP_EXPORT PlatformModel : public QAbstractItemModel
25{
26 Q_OBJECT
27 Q_PROPERTY(KOSMIndoorMap::MapData mapData READ mapData WRITE setMapData NOTIFY mapDataChanged)
28 Q_PROPERTY(bool isEmpty READ isEmpty NOTIFY mapDataChanged)
29
30 /** Row indexes of the matched arrival/departure platforms, if found and/or set, otherwise @c -1. */
31 Q_PROPERTY(int arrivalPlatformRow READ arrivalPlatformRow NOTIFY platformIndexChanged)
32 Q_PROPERTY(int departurePlatformRow READ departurePlatformRow NOTIFY platformIndexChanged)
33
34 /** Platform search parameters (name/mode/ifopt) for matching arrival/departure platform against what we found in the map data. */
35 Q_PROPERTY(KOSMIndoorMap::Platform arrivalPlatform READ arrivalPlatform WRITE setArrivalPlatform NOTIFY arrivalPlatformChanged)
36 Q_PROPERTY(KOSMIndoorMap::Platform departurePlatform READ departurePlatform WRITE setDeparturePlatform NOTIFY departurePlatformChanged)
37
38public:
39 explicit PlatformModel(QObject *parent = nullptr);
41
42 MapData mapData() const;
43 void setMapData(const MapData &data);
44
45 bool isEmpty() const;
46
47 enum Role {
48 CoordinateRole = Qt::UserRole,
49 ElementRole,
50 LevelRole,
51 TransportModeRole,
52 LinesRole,
53 ArrivalPlatformRole,
54 DeparturePlatformRole,
55 };
56 Q_ENUM(Role)
57
58 int columnCount(const QModelIndex &parent = {}) const override;
59 int rowCount(const QModelIndex &parent = {}) const override;
60 QVariant data(const QModelIndex &index, int role) const override;
61 QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
62 QModelIndex parent(const QModelIndex &child) const override;
63 QHash<int, QByteArray> roleNames() const override;
64
65 /** Match arrival/departure platform against what we found in the map data. */
66 Platform arrivalPlatform() const;
67 void setArrivalPlatform(const Platform &platform);
68 Q_INVOKABLE [[deprecated("use arrivalPlatform property")]] void setArrivalPlatform(const QString &name, KOSMIndoorMap::Platform::Mode mode);
69 Platform departurePlatform() const;
70 void setDeparturePlatform(const Platform &platform);
71 Q_INVOKABLE [[deprecated("use departurePlatform property")]] void setDeparturePlatform(const QString &name, KOSMIndoorMap::Platform::Mode mode);
72
73 int arrivalPlatformRow() const;
74 int departurePlatformRow() const;
75
76Q_SIGNALS:
77 void mapDataChanged();
78 void platformIndexChanged();
79 void arrivalPlatformChanged();
80 void departurePlatformChanged();
81
82private:
83 void matchPlatforms();
84 int matchPlatform(const Platform &platform) const;
85 void createLabels();
86 void setPlatformTag(int idx, OSM::TagKey key, bool enabled);
87
88 QStringView effectiveArrivalSections() const;
89 QStringView effectiveDepartureSections() const;
90 void applySectionSelection(int platformIdx, OSM::TagKey key, QStringView sections);
91
92 std::vector<Platform> m_platforms;
93 MapData m_data;
94 struct {
95 OSM::TagKey arrival;
96 OSM::TagKey departure;
97 } m_tagKeys;
98
99 std::vector<OSM::UniqueElement> m_platformLabels;
100 std::vector<std::vector<OSM::UniqueElement>> m_sectionsLabels;
101
102 Platform m_arrivalPlatform;
103 Platform m_departurePlatform;
104 int m_arrivalPlatformRow = -1;
105 int m_departurePlatformRow = -1;
106
107 QTimer m_matchTimer;
108};
109
110}
111
112#endif // KOSMINDOORMAP_PLATFORMMODEL_H
Raw OSM map data, separated by levels.
Definition mapdata.h:60
Lists all platforms/tracks and platform sections found in the current map.
A railway platform/track.
Definition platform.h:56
Mode
Transportation mode served by a platform.
Definition platform.h:109
A key of an OSM tag.
Definition datatypes.h:179
OSM-based multi-floor indoor maps for buildings.
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 1 2024 18:55:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.