Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qgeofiletilecachemapbox.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 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
"qgeofiletilecachemapbox.h"
5
#
include
<
QtLocation
/
private
/
qgeotilespec_p
.
h
>
6
#
include
<
QDir
>
7
8
QT_BEGIN_NAMESPACE
9
10
QGeoFileTileCacheMapbox::QGeoFileTileCacheMapbox(
const
QList<QGeoMapType> &mapTypes,
11
int
scaleFactor,
const
QString &directory,
12
QObject *parent)
13
:QGeoFileTileCache(directory, parent), m_mapTypes(mapTypes)
14
{
15
m_scaleFactor = qBound(1, scaleFactor, 2);
16
for
(qsizetype i = 0; i < mapTypes.size(); i++)
17
m_mapNameToId.insert(mapTypes[i].name(), i + 1);
18
}
19
20
QGeoFileTileCacheMapbox::~QGeoFileTileCacheMapbox()
21
{
22
23
}
24
25
QString QGeoFileTileCacheMapbox::tileSpecToFilename(
const
QGeoTileSpec &spec,
const
QString &format,
26
const
QString &directory)
const
27
{
28
QString filename = spec.plugin();
29
filename += QLatin1String(
"-"
);
30
filename += m_mapTypes[spec.mapId()-1].name();
31
filename += QLatin1String(
"-"
);
32
filename += QString::number(spec.zoom());
33
filename += QLatin1String(
"-"
);
34
filename += QString::number(spec.x());
35
filename += QLatin1String(
"-"
);
36
filename += QString::number(spec.y());
37
38
//Append version if real version number to ensure backwards compatibility and eviction of old tiles
39
if
(spec.version() != -1) {
40
filename += QLatin1String(
"-"
);
41
filename += QString::number(spec.version());
42
}
43
44
filename += QLatin1String(
"-@"
);
45
filename += QString::number(m_scaleFactor);
46
filename += QLatin1Char(
'x'
);
47
48
filename += QLatin1String(
"."
);
49
filename += format;
50
51
QDir dir = QDir(directory);
52
53
return
dir.filePath(filename);
54
}
55
56
QGeoTileSpec QGeoFileTileCacheMapbox::filenameToTileSpec(
const
QString &filename)
const
57
{
58
QStringList parts = filename.split(
'.'
);
59
60
if
(parts.length() != 3)
// 3 because the map name has always a dot in it.
61
return
QGeoTileSpec();
62
63
const
QString name = parts.at(0) + QChar(
'.'
) + parts.at(1);
64
const
QStringList fields = name.split(
'-'
);
65
66
const
qsizetype length = fields.length();
67
if
(length != 6 && length != 7)
68
return
QGeoTileSpec();
69
const
qsizetype scaleIdx = fields.last().indexOf(
"@"
);
70
if
(scaleIdx < 0 || fields.last().size() <= (scaleIdx + 2))
71
return
QGeoTileSpec();
72
const
int
scaleFactor = fields.last()[scaleIdx + 1].digitValue();
73
if
(scaleFactor != m_scaleFactor)
74
return
QGeoTileSpec();
75
76
QList<
int
> numbers;
77
78
bool
ok =
false
;
79
for
(qsizetype i = 2; i < length - 1; ++i) {
// skipping -@_X
80
ok =
false
;
81
int
value = fields.at(i).toInt(&ok);
82
if
(!ok)
83
return
QGeoTileSpec();
84
numbers.append(value);
85
}
86
87
//File name without version, append default
88
if
(numbers.length() < 4)
89
numbers.append(-1);
90
91
return
QGeoTileSpec(fields.at(0),
92
m_mapNameToId[fields.at(1)],
93
numbers.at(0),
94
numbers.at(1),
95
numbers.at(2),
96
numbers.at(3));
97
}
98
99
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtlocation
src
plugins
geoservices
mapbox
qgeofiletilecachemapbox.cpp
Generated on
for Qt by
1.18.0