File indexing completed on 2024-05-12 04:42:08

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KOSMINDOORMAP_FLOORLEVELCHANGEMODEL_H
0008 #define KOSMINDOORMAP_FLOORLEVELCHANGEMODEL_H
0009 
0010 #include "osmelement.h"
0011 
0012 #include <KOSMIndoorMap/FloorLevelModel>
0013 
0014 #include <osm/element.h>
0015 
0016 #include <QAbstractListModel>
0017 
0018 #include <vector>
0019 
0020 namespace KOSMIndoorMap {
0021 
0022 class MapLevel;
0023 
0024 /** Floor level changes on steps or elevators. */
0025 class FloorLevelChangeModel : public QAbstractListModel
0026 {
0027     Q_OBJECT
0028     Q_PROPERTY(int currentFloorLevel READ currentFloorLevel WRITE setCurrentFloorLevel NOTIFY contentChanged)
0029     Q_PROPERTY(KOSMIndoorMap::FloorLevelModel* floorLevelModel READ floorLevelModel WRITE setFloorLevelModel NOTIFY contentChanged)
0030     Q_PROPERTY(KOSMIndoorMap::OSMElement element READ element WRITE setElement NOTIFY contentChanged)
0031 
0032     /** The current element changes to a single other floor, ie. typically stairs or a ramp. */
0033     Q_PROPERTY(bool hasSingleLevelChange READ hasSingleLevelChange NOTIFY contentChanged)
0034     /** The destination level for a single level change. */
0035     Q_PROPERTY(int destinationLevel READ destinationLevel NOTIFY contentChanged)
0036     Q_PROPERTY(QString destinationLevelName READ destinationLevelName NOTIFY contentChanged)
0037 
0038     /** The current element changes to multiple levels based on users choice, ie. typically an elevator.
0039      *  The model in this case provides the levels that are reachable.
0040      */
0041     Q_PROPERTY(bool hasMultipleLevelChanges READ hasMultipleLevelChanges NOTIFY contentChanged)
0042 
0043     /** Human-readable title of the thing enabling a floor level change here.
0044      *  E.g. "Elevator" or "Staircase"
0045      */
0046     Q_PROPERTY(QString title READ title NOTIFY contentChanged)
0047 
0048 public:
0049     explicit FloorLevelChangeModel(QObject *parent = nullptr);
0050     ~FloorLevelChangeModel();
0051 
0052     enum Roles {
0053         FloorLevelRole = Qt::UserRole,
0054         CurrentFloorRole,
0055     };
0056 
0057     int rowCount(const QModelIndex &parent = {}) const override;
0058     QVariant data(const QModelIndex &index, int role) const override;
0059     QHash<int, QByteArray> roleNames() const override;
0060 
0061     int currentFloorLevel() const;
0062     void setCurrentFloorLevel(int level);
0063     FloorLevelModel* floorLevelModel() const;
0064     void setFloorLevelModel(FloorLevelModel *floorLevelModel);
0065     OSMElement element() const;
0066     void setElement(const OSMElement &element);
0067 
0068     bool hasSingleLevelChange() const;
0069     int destinationLevel() const;
0070     QString destinationLevelName() const;
0071     bool hasMultipleLevelChanges() const;
0072 
0073     QString title() const;
0074 
0075 Q_SIGNALS:
0076     void contentChanged();
0077 
0078 private:
0079     bool isLevelChangeElement(OSM::Element element) const;
0080     void appendFloorLevel(int level);
0081     void appendFullFloorLevel(int level);
0082 
0083     int m_currentFloorLevel = 0;
0084     FloorLevelModel *m_floorLevelModel = nullptr;
0085     OSM::Element m_element;
0086     std::vector<MapLevel> m_levels;
0087 };
0088 
0089 }
0090 
0091 #endif // KOSMINDOORMAP_FLOORLEVELCHANGEMODEL_H