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
qgeofiletilecacheohosmapkit.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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
4#include <QtCore/qdir.h>
5#include <QtCore/qregularexpression.h>
6#include <QtLocation/private/qgeotilespec_p.h>
7#include <algorithm>
8#include <qgeofiletilecacheohosmapkit.h>
9#include <unordered_map>
10
11QT_BEGIN_NAMESPACE
12
13namespace {
14
15constexpr int minScaleFactor = 1;
16constexpr int maxScaleFactor = 2;
17
18constexpr int fixedMapId = 0;
19
21{
22public:
24 int scaleFactor, const QString &directory, QObject *parent);
25
26protected:
28 const QGeoTileSpec &spec, const QString &format, const QString &directory) const override;
29 QGeoTileSpec filenameToTileSpec(const QString &filename) const override;
30
31private:
32 int m_scaleFactor;
33};
34
36 int scaleFactor, const QString &directory, QObject *parent)
38 , m_scaleFactor(qBound(minScaleFactor, scaleFactor, maxScaleFactor))
39{
40}
41
43 const QGeoTileSpec &spec, const QString &format, const QString &outputDir) const
44{
45 return QDir(outputDir).filePath(
46 QString("%1-%2-%3-%4-%5-@%6x.%7")
47 .arg(spec.plugin())
48 .arg(fixedMapId)
49 .arg(spec.zoom())
50 .arg(spec.x())
51 .arg(spec.y())
52 .arg(m_scaleFactor)
53 .arg(format));
54}
55
57{
58 QRegularExpression tileCacheFilenameMatchingRegexp(
59 QStringLiteral(
60 R"(^(?<pluginName>.*?)-(?<mapId>\d+)-(?<zoom>\d+)-(?<x>\d+)-(?<y>\d+)-@(?<scale>\d+)x)"));
61
62 std::unordered_map<const char *, int> matchIntegerValues = {
63 {"mapId", 0},
64 {"zoom", 0},
65 {"x", 0},
66 {"y", 0},
67 {"scale", 0},
68 };
69
70 QRegularExpressionMatch match = tileCacheFilenameMatchingRegexp.match(filename);
71
72 bool matchValuesValid = false;
73 if (match.hasMatch()) {
74 matchValuesValid = true;
75 for (auto &kv : matchIntegerValues) {
76 bool ok;
77 kv.second = match.captured(kv.first).toInt(&ok);
78 if (!ok) {
79 matchValuesValid = false;
80 break;
81 }
82 }
83 }
84
85 constexpr int noVersionSpecified = -1;
86 return matchValuesValid && matchIntegerValues["scale"] == m_scaleFactor
87 ? QGeoTileSpec(
88 match.captured("pluginName"),
89 matchIntegerValues["mapId"],
90 matchIntegerValues["zoom"],
91 matchIntegerValues["x"],
92 matchIntegerValues["y"],
93 noVersionSpecified)
94 : QGeoTileSpec();
95}
96
97}
98
99QGeoFileTileCache *makeGeoFileTileCacheOhosMapKit(int scaleFactor, const QString &directory, QObject *parent)
100{
101 return new QGeoFileTileCacheOhosMapKit(scaleFactor, directory, parent);
102}
103
104QT_END_NAMESPACE
QGeoTileSpec filenameToTileSpec(const QString &filename) const override
QGeoFileTileCacheOhosMapKit(int scaleFactor, const QString &directory, QObject *parent)
QString tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) const override
QGeoFileTileCache * makeGeoFileTileCacheOhosMapKit(int scaleFactor, const QString &directory, QObject *parent)