File indexing completed on 2024-05-12 04:42:09
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_MAPITEM_H 0008 #define KOSMINDOORMAP_MAPITEM_H 0009 0010 #include "osmelement.h" 0011 0012 #include <KOSMIndoorMap/FloorLevelModel> 0013 #include <KOSMIndoorMap/MapData> 0014 #include <KOSMIndoorMap/MapCSSStyle> 0015 #include <KOSMIndoorMap/MapLoader> 0016 #include <KOSMIndoorMap/PainterRenderer> 0017 #include <KOSMIndoorMap/SceneController> 0018 #include <KOSMIndoorMap/SceneGraph> 0019 #include <KOSMIndoorMap/View> 0020 0021 #include <QQuickPaintedItem> 0022 0023 namespace KOSMIndoorMap { 0024 0025 class MapData; 0026 0027 /** Map renderer for the IndoorMap QML item. 0028 * @internal Do not use directly! 0029 */ 0030 class MapItem : public QQuickPaintedItem 0031 { 0032 Q_OBJECT 0033 Q_PROPERTY(KOSMIndoorMap::MapLoader* loader READ loader CONSTANT) 0034 Q_PROPERTY(KOSMIndoorMap::View* view READ view CONSTANT) 0035 Q_PROPERTY(QString styleSheet READ styleSheetName WRITE setStylesheetName NOTIFY styleSheetChanged) 0036 Q_PROPERTY(KOSMIndoorMap::FloorLevelModel* floorLevels READ floorLevelModel CONSTANT) 0037 0038 /** There's a loading error (data not found, network issue, broken style sheet, etc). */ 0039 Q_PROPERTY(bool hasError READ hasError NOTIFY errorChanged) 0040 /** Details on the error. */ 0041 Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorChanged) 0042 0043 Q_PROPERTY(KOSMIndoorMap::MapData mapData READ mapData NOTIFY mapDataChanged) 0044 0045 /** Sources for overlays that should be rendered on top of the map. */ 0046 Q_PROPERTY(QVariant overlaySources READ overlaySources WRITE setOverlaySources NOTIFY overlaySourcesChanged) 0047 0048 /** ISO 3166-1/2 country or region code this map area is in. 0049 * Used for interpreting opening hours expressions. 0050 */ 0051 Q_PROPERTY(QString region READ region WRITE setRegion NOTIFY regionChanged) 0052 0053 /** IANA timezone id of the timezone this map area is in. 0054 * Used for interpreting opening hours expressions. 0055 */ 0056 Q_PROPERTY(QString timeZone READ timeZoneId WRITE setTimeZoneId NOTIFY timeZoneChanged) 0057 0058 /** Currently hovered element. */ 0059 Q_PROPERTY(KOSMIndoorMap::OSMElement hoveredElement READ hoveredElement WRITE setHoveredElement NOTIFY hoveredElementChanged) 0060 0061 public: 0062 explicit MapItem(QQuickItem *parent = nullptr); 0063 ~MapItem(); 0064 0065 void paint(QPainter *painter) override; 0066 0067 [[nodiscard]] MapLoader* loader() const; 0068 [[nodiscard]] View* view() const; 0069 0070 [[nodiscard]] QString styleSheetName() const; 0071 void setStylesheetName(const QString &styleSheet); 0072 0073 [[nodiscard]] FloorLevelModel *floorLevelModel() const; 0074 0075 [[nodiscard]] Q_INVOKABLE KOSMIndoorMap::OSMElement elementAt(double x, double y) const; 0076 0077 [[nodiscard]] bool hasError() const; 0078 [[nodiscard]] QString errorMessage() const; 0079 0080 [[nodiscard]] QString region() const; 0081 void setRegion(const QString ®ion); 0082 [[nodiscard]] QString timeZoneId() const; 0083 void setTimeZoneId(const QString &tz); 0084 0085 Q_SIGNALS: 0086 void mapDataChanged(); 0087 void styleSheetChanged(); 0088 void currentFloorLevelChanged(); 0089 void errorChanged(); 0090 void overlaySourcesChanged(); 0091 void regionChanged(); 0092 void timeZoneChanged(); 0093 void hoveredElementChanged(); 0094 0095 protected: 0096 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; 0097 0098 private: 0099 void clear(); 0100 void loaderDone(); 0101 [[nodiscard]] MapData mapData() const; 0102 [[nodiscard]] QVariant overlaySources() const; 0103 void setOverlaySources(const QVariant &overlays); 0104 0105 void addOverlaySource(std::vector<QPointer<AbstractOverlaySource>> &overlaySources, const QVariant &source); 0106 void overlayUpdate(); 0107 void overlayReset(); 0108 0109 [[nodiscard]] OSMElement hoveredElement() const; 0110 void setHoveredElement(const OSMElement &element); 0111 0112 MapLoader *m_loader = nullptr; 0113 MapData m_data; 0114 SceneGraph m_sg; 0115 View *m_view = nullptr; 0116 QString m_styleSheetName; 0117 MapCSSStyle m_style; 0118 SceneController m_controller; 0119 PainterRenderer m_renderer; 0120 FloorLevelModel *m_floorLevelModel = nullptr; 0121 QString m_errorMessage; 0122 QVariant m_overlaySources; 0123 std::vector<std::unique_ptr<AbstractOverlaySource>> m_ownedOverlaySources; 0124 }; 0125 0126 } 0127 0128 #endif // KOSMINDOORMAP_MAPITEM_H