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