File indexing completed on 2024-04-14 03:48:10

0001 /*
0002     SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004     SPDX-FileCopyrightText: 2012 Ander Pijoan <ander.pijoan@deusto.es>
0005     SPDX-FileCopyrightText: 2013 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0006 */
0007 
0008 #ifndef MARBLE_VECTORTILEMODEL_H
0009 #define MARBLE_VECTORTILEMODEL_H
0010 
0011 #include <QObject>
0012 #include <QRunnable>
0013 
0014 #include <QMap>
0015 
0016 #include "TileId.h"
0017 #include "GeoDataLatLonBox.h"
0018 
0019 class QThreadPool;
0020 
0021 namespace Marble
0022 {
0023 
0024 class GeoDataDocument;
0025 class GeoDataTreeModel;
0026 class GeoSceneVectorTileDataset;
0027 class GeoDataObject;
0028 class TileLoader;
0029 
0030 class TileRunner : public QObject, public QRunnable
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     TileRunner( TileLoader *loader, const GeoSceneVectorTileDataset *texture, const TileId &id );
0036     void run() override;
0037 
0038 Q_SIGNALS:
0039     void documentLoaded( const TileId &id, GeoDataDocument *document );
0040 
0041 private:
0042     TileLoader *const m_loader;
0043     const GeoSceneVectorTileDataset *const m_tileDataset;
0044     const TileId m_id;
0045 };
0046 
0047 class VectorTileModel : public QObject
0048 {
0049     Q_OBJECT
0050 
0051 public:
0052     explicit VectorTileModel( TileLoader *loader, const GeoSceneVectorTileDataset *layer, GeoDataTreeModel *treeModel, QThreadPool *threadPool );
0053 
0054     void setViewport(const GeoDataLatLonBox &bbox);
0055 
0056     QString name() const;
0057 
0058     const GeoSceneVectorTileDataset *layer() const;
0059 
0060     void removeTile(GeoDataDocument* document);
0061 
0062     int tileZoomLevel() const;
0063 
0064     int cachedDocuments() const;
0065 
0066     void reload();
0067 
0068 public Q_SLOTS:
0069     void updateTile( const TileId &id, GeoDataDocument *document );
0070 
0071     void clear();
0072 
0073 Q_SIGNALS:
0074     void tileCompleted( const TileId &tileId );
0075     void tileAdded(GeoDataDocument *document);
0076     void tileRemoved(GeoDataDocument *document);
0077 
0078 private Q_SLOTS:
0079     void cleanupTile(GeoDataObject* feature);
0080 
0081 private:
0082     void removeTilesOutOfView(const GeoDataLatLonBox &boundingBox);
0083     void queryTiles(int tileZoomLevel, const QRect &rect);
0084 
0085 private:
0086     struct CacheDocument
0087     {
0088         /** The CacheDocument takes ownership of doc */
0089         CacheDocument(GeoDataDocument *doc, VectorTileModel* vectorTileModel, const GeoDataLatLonBox &boundingBox);
0090 
0091         /** Remove the document from the tree and delete the document */
0092         ~CacheDocument();
0093 
0094         GeoDataLatLonBox latLonBox() const { return m_boundingBox; }
0095 
0096     private:
0097         Q_DISABLE_COPY( CacheDocument )
0098 
0099         GeoDataDocument *const m_document;
0100         VectorTileModel *const m_vectorTileModel;
0101         GeoDataLatLonBox m_boundingBox;
0102     };
0103 
0104     TileLoader *const m_loader;
0105     const GeoSceneVectorTileDataset *const m_layer;
0106     GeoDataTreeModel *const m_treeModel;
0107     QThreadPool *const m_threadPool;
0108     int m_tileLoadLevel;
0109     int m_tileZoomLevel;
0110     QList<TileId> m_pendingDocuments;
0111     QList<GeoDataDocument*> m_garbageQueue;
0112     QMap<TileId, QSharedPointer<CacheDocument> > m_documents;
0113     bool m_deleteDocumentsLater;
0114 };
0115 
0116 }
0117 
0118 #endif // MARBLE_VECTORTILEMODEL_H