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
qabstractgeotilecache.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 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
4
6
8
9#include <QDir>
10#include <QStandardPaths>
11#include <QMetaType>
12#include <QPixmap>
13#include <QDebug>
14#include <QtCore/qtemporaryfile.h>
15
17
18using namespace Qt::StringLiterals;
19
20QAbstractGeoTileCache::QAbstractGeoTileCache(QObject *parent)
21 : QObject(parent)
22{
23 qRegisterMetaType<QGeoTileSpec>();
24 qRegisterMetaType<QList<QGeoTileSpec> >();
25 qRegisterMetaType<QSet<QGeoTileSpec> >();
26}
27
28QAbstractGeoTileCache::~QAbstractGeoTileCache()
29{
30}
31
32void QAbstractGeoTileCache::printStats()
33{
34}
35
36void QAbstractGeoTileCache::handleError(const QGeoTileSpec &, const QString &error)
37{
38 qWarning() << "tile request error " << error;
39}
40
41void QAbstractGeoTileCache::setMaxDiskUsage(int diskUsage)
42{
43 Q_UNUSED(diskUsage);
44}
45
46int QAbstractGeoTileCache::maxDiskUsage() const
47{
48 return 0;
49}
50
51int QAbstractGeoTileCache::diskUsage() const
52{
53 return 0;
54}
55
56void QAbstractGeoTileCache::setMaxMemoryUsage(int memoryUsage)
57{
58 Q_UNUSED(memoryUsage);
59}
60
61int QAbstractGeoTileCache::maxMemoryUsage() const
62{
63 return 0;
64}
65
66int QAbstractGeoTileCache::memoryUsage() const
67{
68 return 0;
69}
70
71QString QAbstractGeoTileCache::baseCacheDirectory()
72{
73 QString dir;
74
75 // Try the shared cache first and use a specific directory. (e.g. ~/.cache/QtLocation)
76 // If this is not supported by the platform, use the application-specific cache
77 // location. (e.g. ~/.cache/<app_name>/QtLocation)
78 dir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
79
80 if (!dir.isEmpty()) {
81 // The shared cache may not be writable when application isolation is enforced.
82 static bool writable = false;
83 static bool writableChecked = false;
84 if (!writableChecked) {
85 writableChecked = true;
86 auto mkpath = [] (const QString &dir) {
87 const auto rt = QDir::root();
88 return rt.mkpath(dir);
89 };
90 if (mkpath(dir)) {
91 QTemporaryFile tmp(QDir(dir).filePath(u"qt_cache_check.XXXXXX"_s));
92 writable = tmp.open();
93 } else {
94 writable = false;
95 }
96 }
97 if (!writable)
98 dir = QString();
99 }
100
101 if (dir.isEmpty())
102 dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
103
104 if (!dir.endsWith(QLatin1Char('/')))
105 dir += QLatin1Char('/');
106
107 return dir;
108}
109
110QString QAbstractGeoTileCache::baseLocationCacheDirectory()
111{
112 // This scheme allows to have the "tiles" prefix hardcoded here
113 // NOTE: changing the Qt version here requires changing it also in QGeoFileTileCache::init,
114 // in the code that remove old version tiles !
115 return baseCacheDirectory() + QLatin1String("QtLocation/5.8/tiles/");
116}
117
118QT_END_NAMESPACE