File indexing completed on 2024-11-24 04:15:37

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_MAPLOADER_H
0008 #define KOSMINDOORMAP_MAPLOADER_H
0009 
0010 #include "kosmindoormap_export.h"
0011 
0012 #include <QObject>
0013 
0014 #include <memory>
0015 
0016 namespace OSM {
0017 class BoundingBox;
0018 }
0019 
0020 /** OSM-based multi-floor indoor maps for buildings. */
0021 namespace KOSMIndoorMap {
0022 
0023 class MapData;
0024 class MapLoaderPrivate;
0025 class Tile;
0026 
0027 /** Loader for OSM data for a single station or airport. */
0028 class KOSMINDOORMAP_EXPORT MapLoader : public QObject
0029 {
0030     Q_OBJECT
0031     /** Indicates we are downloading content. Use for progress display. */
0032     Q_PROPERTY(bool isLoading READ isLoading NOTIFY isLoadingChanged)
0033 public:
0034     explicit MapLoader(QObject *parent = nullptr);
0035     ~MapLoader();
0036 
0037     /** Load a single O5M or OSM PBF file. */
0038     Q_INVOKABLE void loadFromFile(const QString &fileName);
0039     /** Load map for the given coordinates.
0040      *  This can involve online access.
0041      */
0042     Q_INVOKABLE void loadForCoordinate(double lat, double lon);
0043     /** Same as the above, but ensureing the requested data is cached until @p ttl. */
0044     void loadForCoordinate(double lat, double lon, const QDateTime &ttl);
0045 
0046     /** Load map data for the given bounding box, without applying the boundary search. */
0047     void loadForBoundingBox(OSM::BoundingBox box);
0048     /** Load map data for the given tile. */
0049     void loadForTile(Tile tile);
0050 
0051     /** Take out the completely loaded result.
0052      *  Do this before loading the next map with the same loader.
0053      */
0054     MapData&& takeData();
0055 
0056     bool isLoading() const;
0057 
0058     bool hasError() const;
0059     QString errorMessage() const;
0060 
0061 Q_SIGNALS:
0062     /** Emitted when the requested data has been loaded. */
0063     void done();
0064     void isLoadingChanged();
0065 
0066 private:
0067     void downloadTiles();
0068     void downloadFinished();
0069     void downloadFailed(Tile tile, const QString &errorMessage);
0070     void loadTiles();
0071     Tile makeTile(uint32_t x, uint32_t y) const;
0072 
0073     std::unique_ptr<MapLoaderPrivate> d;
0074 };
0075 
0076 }
0077 
0078 #endif // KOSMINDOORMAP_MAPLOADER_H