KOSMIndoorMap

platformmodel.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_PLATFORMMODEL_H
8 #define KOSMINDOORMAP_PLATFORMMODEL_H
9 
10 #include "kosmindoormap_export.h"
11 
12 #include "platform.h"
13 
14 #include <KOSMIndoorMap/MapData>
15 
16 #include <QAbstractItemModel>
17 
18 namespace 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  */
24 class 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 public:
34  explicit PlatformModel(QObject *parent = nullptr);
35  ~PlatformModel();
36 
37  MapData mapData() const;
38  void setMapData(const MapData &data);
39 
40  bool isEmpty() const;
41 
42  enum Role {
43  CoordinateRole = Qt::UserRole,
44  ElementRole,
45  LevelRole,
46  TransportModeRole,
47  LinesRole,
48  ArrivalPlatformRole,
49  DeparturePlatformRole,
50  };
51  Q_ENUM(Role)
52 
53  int columnCount(const QModelIndex &parent = {}) const override;
54  int rowCount(const QModelIndex &parent = {}) const override;
55  QVariant data(const QModelIndex &index, int role) const override;
56  QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
57  QModelIndex parent(const QModelIndex &child) const override;
58  QHash<int, QByteArray> roleNames() const override;
59 
60  /** Match arrival/departure platform against what we found in the map data. */
61  Q_INVOKABLE void setArrivalPlatform(const QString &name, KOSMIndoorMap::Platform::Mode mode);
62  Q_INVOKABLE void setDeparturePlatform(const QString &name, KOSMIndoorMap::Platform::Mode mode);
63 
64  int arrivalPlatformRow() const;
65  int departurePlatformRow() const;
66 
67 Q_SIGNALS:
68  void mapDataChanged();
69  void platformIndexChanged();
70 
71 private:
72  void matchPlatforms();
73  int matchPlatform(const Platform &platform) const;
74  void createLabels();
75  void setPlatformTag(int idx, OSM::TagKey key, bool enabled);
76 
77  std::vector<Platform> m_platforms;
78  MapData m_data;
79  struct {
80  OSM::TagKey arrival;
81  OSM::TagKey departure;
82  } m_tagKeys;
83 
84  std::vector<OSM::UniqueElement> m_platformLabels;
85  std::vector<std::vector<OSM::UniqueElement>> m_sectionsLabels;
86 
87  Platform m_arrivalPlatform;
88  Platform m_departurePlatform;
89  int m_arrivalPlatformRow = -1;
90  int m_departurePlatformRow = -1;
91 };
92 
93 }
94 
95 #endif // KOSMINDOORMAP_PLATFORMMODEL_H
OSM-based multi-floor indoor maps for buildings.
A key of an OSM tag.
Definition: datatypes.h:179
UserRole
Raw OSM map data, separated by levels.
Definition: mapdata.h:59
A railway platform/track.
Definition: platform.h:34
Mode
Transportation mode served by a platform.
Definition: platform.h:80
Lists all platforms/tracks and platform sections found in the current map.
Definition: platformmodel.h:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:04:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.