Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgeofiletilecache_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4#ifndef QGEOFILETILECACHE_P_H
5#define QGEOFILETILECACHE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtLocation/private/qlocationglobal_p.h>
19
20#include <QObject>
21#include "qcache3q_p.h"
22
24
25QT_BEGIN_NAMESPACE
26
27class QGeoMappingManager;
28
29class QGeoTile;
31class QGeoFileTileCache;
32
33class QImage;
34
35/* This would be internal to qgeofiletilecache.cpp except that the eviction
36 * policy can't be defined without it being concrete here */
38{
39public:
41
45 QGeoFileTileCache *cache = nullptr;
46};
47
48/* Custom eviction policy for the disk cache, to avoid deleting all the files
49 * when the application closes */
50class Q_LOCATION_EXPORT QCache3QTileEvictionPolicy : public QCache3QDefaultEvictionPolicy<QGeoTileSpec,QGeoCachedTileDisk>
51{
52protected:
53 void aboutToBeRemoved(const QGeoTileSpec &key, QSharedPointer<QGeoCachedTileDisk> obj);
54 void aboutToBeEvicted(const QGeoTileSpec &key, QSharedPointer<QGeoCachedTileDisk> obj);
55};
56
57class Q_LOCATION_EXPORT QGeoFileTileCache : public QAbstractGeoTileCache
58{
59 Q_OBJECT
60public:
61 QGeoFileTileCache(const QString &directory = QString(), QObject *parent = nullptr);
62 ~QGeoFileTileCache();
63
64 void setMaxDiskUsage(int diskUsage) override;
65 int maxDiskUsage() const override;
66 int diskUsage() const override;
67
68 void setMaxMemoryUsage(int memoryUsage) override;
69 int maxMemoryUsage() const override;
70 int memoryUsage() const override;
71
72 void setMinTextureUsage(int textureUsage) override;
73 void setExtraTextureUsage(int textureUsage) override;
74 int maxTextureUsage() const override;
75 int minTextureUsage() const override;
76 int textureUsage() const override;
77 void clearAll() override;
78 void clearMapId(int mapId);
79 void setCostStrategyDisk(CostStrategy costStrategy) override;
80 CostStrategy costStrategyDisk() const override;
81 void setCostStrategyMemory(CostStrategy costStrategy) override;
82 CostStrategy costStrategyMemory() const override;
83 void setCostStrategyTexture(CostStrategy costStrategy) override;
84 CostStrategy costStrategyTexture() const override;
85
86
87 QSharedPointer<QGeoTileTexture> get(const QGeoTileSpec &spec) override;
88
89 // can be called without a specific tileCache pointer
90 static void evictFromDiskCache(QGeoCachedTileDisk *td);
91 static void evictFromMemoryCache(QGeoCachedTileMemory *tm);
92
93 void insert(const QGeoTileSpec &spec,
94 const QByteArray &bytes,
95 const QString &format,
96 QAbstractGeoTileCache::CacheAreas areas = QAbstractGeoTileCache::AllCaches) override;
97
98 static QString tileSpecToFilenameDefault(const QGeoTileSpec &spec, const QString &format, const QString &directory);
99 static QGeoTileSpec filenameToTileSpecDefault(const QString &filename);
100
101protected:
102 void init() override;
103 void printStats() override;
104 void loadTiles();
105
106 QString directory() const;
107
108 QSharedPointer<QGeoCachedTileDisk> addToDiskCache(const QGeoTileSpec &spec, const QString &filename);
109 bool addToDiskCache(const QGeoTileSpec &spec, const QString &filename, const QByteArray &bytes);
110 void addToMemoryCache(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format);
111 QSharedPointer<QGeoTileTexture> addToTextureCache(const QGeoTileSpec &spec, const QImage &image);
112 QSharedPointer<QGeoTileTexture> getFromMemory(const QGeoTileSpec &spec);
113 QSharedPointer<QGeoTileTexture> getFromDisk(const QGeoTileSpec &spec);
114
115 virtual bool isTileBogus(const QByteArray &bytes) const;
116 virtual QString tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) const;
117 virtual QGeoTileSpec filenameToTileSpec(const QString &filename) const;
118
119 QCache3Q<QGeoTileSpec, QGeoCachedTileDisk, QCache3QTileEvictionPolicy> diskCache_;
120 QCache3Q<QGeoTileSpec, QGeoCachedTileMemory> memoryCache_;
121 QCache3Q<QGeoTileSpec, QGeoTileTexture> textureCache_;
122
123 QString directory_;
124
125 int minTextureUsage_ = 0;
126 int extraTextureUsage_ = 0;
127 CostStrategy costStrategyDisk_ = ByteSize;
128 CostStrategy costStrategyMemory_ = ByteSize;
129 CostStrategy costStrategyTexture_ = ByteSize;
130 bool isDiskCostSet_ = false;
131 bool isMemoryCostSet_ = false;
132 bool isTextureCostSet_ = false;
133};
134
135QT_END_NAMESPACE
136
137#endif // QGEOFILETILECACHE_P_H
QGeoFileTileCache * cache
QGeoFileTileCache * cache
Combined button and popup list for selecting options.