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

0001 /*
0002     SPDX-FileCopyrightText: 2005-2007 Torsten Rahn <tackat@kde.org>
0003     SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0004     SPDX-FileCopyrightText: 2009 Jens-Michael Hoffmann <jensmh@gmx.de>
0005     SPDX-FileCopyrightText: 2010-2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef MARBLE_STACKEDTILELOADER_H
0011 #define MARBLE_STACKEDTILELOADER_H
0012 
0013 #include <QObject>
0014 
0015 #include "RenderState.h"
0016 
0017 class QImage;
0018 class QString;
0019 class QSize;
0020 
0021 namespace Marble
0022 {
0023 
0024 class GeoSceneAbstractTileProjection;
0025 class MergedLayerDecorator;
0026 class StackedTile;
0027 class TileId;
0028 
0029 class StackedTileLoaderPrivate;
0030 
0031 /**
0032  * @short Tile loading from a quad tree
0033  *
0034  * This class loads tiles into memory. For faster access
0035  * we keep the tileIDs and their respective pointers to 
0036  * the tiles in a hashtable.
0037  * The class also contains convenience methods to remove entries 
0038  * from the hashtable and to return more detailed properties
0039  * about each tile level and their tiles.
0040  *
0041  * @author Torsten Rahn <rahn@kde.org>
0042  **/
0043 
0044 class StackedTileLoader : public QObject
0045 {
0046     Q_OBJECT
0047 
0048     public:
0049         /**
0050          * Creates a new tile loader.
0051          *
0052          * @param mergedLayerDecorator The decorator that shall be used to decorate
0053          *                        the layer.
0054          * @param parent The parent widget.
0055          */
0056         explicit StackedTileLoader( MergedLayerDecorator *mergedLayerDecorator, QObject *parent = nullptr );
0057         ~StackedTileLoader() override;
0058 
0059         int tileColumnCount( int level ) const;
0060 
0061         int tileRowCount( int level ) const;
0062 
0063         const GeoSceneAbstractTileProjection *tileProjection() const;
0064 
0065         QSize tileSize() const;
0066 
0067         /**
0068          * Loads a tile and returns it.
0069          *
0070          * @param stackedTileId The Id of the requested tile, containing the x and y coordinate
0071          *                      and the zoom level.
0072          */
0073         const StackedTile* loadTile( TileId const &stackedTileId );
0074 
0075         /**
0076          * Resets the internal tile hash.
0077          */
0078         void resetTilehash();
0079 
0080         /**
0081          * Cleans up the internal tile hash.
0082          *
0083          * Removes all superfluous tiles from the hash.
0084          */
0085         void cleanupTilehash();
0086 
0087         /**
0088          * @brief  Returns the limit of the volatile (in RAM) cache.
0089          * @return the cache limit in kilobytes
0090          */
0091         quint64 volatileCacheLimit() const;
0092 
0093         /**
0094          * @brief Reloads the tiles that are currently displayed.
0095          */
0096         QList<TileId> visibleTiles() const;
0097 
0098         /**
0099          * @brief Return the number of tiles in the cache.
0100          * @return number of tiles in cache
0101          */
0102         int tileCount() const;
0103 
0104         /**
0105          * @brief Set the limit of the volatile (in RAM) cache.
0106          * @param kiloBytes The limit in kilobytes.
0107          */
0108         void setVolatileCacheLimit( quint64 kiloBytes );
0109 
0110         /**
0111          * Effectively triggers a reload of all tiles that are currently in use
0112          * and clears the tile cache in physical memory.
0113          */
0114         void clear();
0115 
0116         /**
0117          */
0118         void updateTile(TileId const & tileId, QImage const &tileImage );
0119 
0120         RenderState renderState() const;
0121 
0122     Q_SIGNALS:
0123         void tileLoaded( TileId const &tileId );
0124         void cleared();
0125 
0126     private:
0127         Q_DISABLE_COPY( StackedTileLoader )
0128 
0129         friend class StackedTileLoaderPrivate;
0130         StackedTileLoaderPrivate* const d;
0131 };
0132 
0133 }
0134 
0135 #endif