Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgeotiledmappingmanagerengine.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
6#include "qgeotilefetcher_p.h"
7
8
9#include "qgeotiledmap_p.h"
11#include "qgeofiletilecache_p.h"
12#include "qgeotilespec_p.h"
13
14#include <QTimer>
15#include <QLocale>
16#include <QDir>
17#include <QStandardPaths>
18
20
26
34
39{
41
42 if (d->fetcher_)
43 d->fetcher_->deleteLater();
44 fetcher->setParent(this);
45 d->fetcher_ = fetcher;
46
47 qRegisterMetaType<QGeoTileSpec>();
48
55
57}
58
64
69
71{
73
74 QHash<QGeoTileSpec, QSet<QGeoTiledMap *> > newTileHash = d_ptr->tileHash_;
75 typedef QHash<QGeoTileSpec, QSet<QGeoTiledMap *> >::const_iterator h_iter;
76 h_iter hi = d_ptr->tileHash_.constBegin();
77 h_iter hend = d_ptr->tileHash_.constEnd();
78 for (; hi != hend; ++hi) {
79 QSet<QGeoTiledMap *> maps = hi.value();
80 if (maps.contains(map)) {
81 maps.remove(map);
82 if (maps.isEmpty())
83 newTileHash.remove(hi.key());
84 else
85 newTileHash.insert(hi.key(), maps);
86 }
87 }
88 d_ptr->tileHash_ = newTileHash;
89}
90
92 const QSet<QGeoTileSpec> &tilesAdded,
93 const QSet<QGeoTileSpec> &tilesRemoved)
94{
96
97 typedef QSet<QGeoTileSpec>::const_iterator tile_iter;
98
99 // add and remove tiles from tileset for this map
100
101 QSet<QGeoTileSpec> oldTiles = d->mapHash_.value(map);
102
103 tile_iter rem = tilesRemoved.constBegin();
104 tile_iter remEnd = tilesRemoved.constEnd();
105 for (; rem != remEnd; ++rem) {
106 oldTiles.remove(*rem);
107 }
108
109 tile_iter add = tilesAdded.constBegin();
110 tile_iter addEnd = tilesAdded.constEnd();
111 for (; add != addEnd; ++add) {
112 oldTiles.insert(*add);
113 }
114
115 d->mapHash_.insert(map, oldTiles);
116
117 // add and remove map from mapset for the tiles
118
119 QSet<QGeoTileSpec> reqTiles;
120 QSet<QGeoTileSpec> cancelTiles;
121
122 rem = tilesRemoved.constBegin();
123 for (; rem != remEnd; ++rem) {
124 QSet<QGeoTiledMap *> mapSet = d->tileHash_.value(*rem);
125 mapSet.remove(map);
126 if (mapSet.isEmpty()) {
127 cancelTiles.insert(*rem);
128 d->tileHash_.remove(*rem);
129 } else {
130 d->tileHash_.insert(*rem, mapSet);
131 }
132 }
133
134 add = tilesAdded.constBegin();
135 for (; add != addEnd; ++add) {
136 QSet<QGeoTiledMap *> mapSet = d->tileHash_.value(*add);
137 if (mapSet.isEmpty()) {
138 reqTiles.insert(*add);
139 }
140 mapSet.insert(map);
141 d->tileHash_.insert(*add, mapSet);
142 }
143
144 cancelTiles -= reqTiles;
145
146 QMetaObject::invokeMethod(d->fetcher_, "updateTileRequests",
148 Q_ARG(QSet<QGeoTileSpec>, reqTiles),
149 Q_ARG(QSet<QGeoTileSpec>, cancelTiles));
150}
151
153{
155
156 QSet<QGeoTiledMap *> maps = d->tileHash_.value(spec);
157
159
160 map_iter map = maps.constBegin();
161 map_iter mapEnd = maps.constEnd();
162 for (; map != mapEnd; ++map) {
163 QSet<QGeoTileSpec> tileSet = d->mapHash_.value(*map);
164 tileSet.remove(spec);
165 if (tileSet.isEmpty())
166 d->mapHash_.remove(*map);
167 else
168 d->mapHash_.insert(*map, tileSet);
169 }
170
171 d->tileHash_.remove(spec);
172 tileCache()->insert(spec, bytes, format, d->cacheHint_);
173
174 map = maps.constBegin();
175 mapEnd = maps.constEnd();
176 for (; map != mapEnd; ++map) {
177 (*map)->requestManager()->tileFetched(spec);
178 }
179}
180
182{
184
185 QSet<QGeoTiledMap *> maps = d->tileHash_.value(spec);
187 map_iter map = maps.constBegin();
188 map_iter mapEnd = maps.constEnd();
189 for (; map != mapEnd; ++map) {
190 QSet<QGeoTileSpec> tileSet = d->mapHash_.value(*map);
191
192 tileSet.remove(spec);
193 if (tileSet.isEmpty())
194 d->mapHash_.remove(*map);
195 else
196 d->mapHash_.insert(*map, tileSet);
197 }
198 d->tileHash_.remove(spec);
199
200 for (map = maps.constBegin(); map != mapEnd; ++map) {
201 (*map)->requestManager()->tileError(spec, errorString);
202 }
203
204 emit tileError(spec, errorString);
205}
206
212
214{
216 if (d->m_tileVersion != version) {
217 d->m_tileVersion = version;
219 }
220}
221
223{
225 return d->tileSize_;
226}
227
229{
231 return d->m_tileVersion;
232}
233
234QAbstractGeoTileCache::CacheAreas QGeoTiledMappingManagerEngine::cacheHint() const
235{
237 return d->cacheHint_;
238}
239
240void QGeoTiledMappingManagerEngine::setCacheHint(QAbstractGeoTileCache::CacheAreas cacheHint)
241{
243 d->cacheHint_ = cacheHint;
244}
245
250{
252 Q_ASSERT_X(!d->tileCache_, Q_FUNC_INFO, "This should be called only once");
253 cache->setParent(this);
254 d->tileCache_.reset(cache);
255 d->tileCache_->init();
256}
257
259{
261 if (!d->tileCache_) {
262 QString cacheDirectory;
263 if (!managerName().isEmpty())
265 d->tileCache_.reset(new QGeoFileTileCache(cacheDirectory));
266 d->tileCache_->init();
267 }
268 return d->tileCache_.get();
269}
270
271QSharedPointer<QGeoTileTexture> QGeoTiledMappingManagerEngine::getTileTexture(const QGeoTileSpec &spec)
272{
273 return d_ptr->tileCache_->get(spec);
274}
275
virtual void insert(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format, QAbstractGeoTileCache::CacheAreas areas=QAbstractGeoTileCache::AllCaches)=0
static QString baseLocationCacheDirectory()
\inmodule QtCore
Definition qbytearray.h:57
QString managerName() const
Returns the name which this engine implementation uses to distinguish itself from the implementations...
void engineInitialized()
Marks the engine as initialized.
void tileError(const QGeoTileSpec &spec, const QString &errorString)
void tileFinished(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format)
QHash< QGeoTiledMap *, QSet< QGeoTileSpec > > mapHash_
std::unique_ptr< QAbstractGeoTileCache > tileCache_
QHash< QGeoTileSpec, QSet< QGeoTiledMap * > > tileHash_
void setCacheHint(QAbstractGeoTileCache::CacheAreas cacheHint)
virtual void engineTileError(const QGeoTileSpec &spec, const QString &errorString)
void setTileFetcher(QGeoTileFetcher *fetcher)
Sets the tile fetcher.
QGeoTiledMappingManagerEngine(QObject *parent=nullptr)
virtual void updateTileRequests(QGeoTiledMap *map, const QSet< QGeoTileSpec > &tilesAdded, const QSet< QGeoTileSpec > &tilesRemoved)
void setTileCache(QAbstractGeoTileCache *cache)
Sets the tile cache.
virtual QSharedPointer< QGeoTileTexture > getTileTexture(const QGeoTileSpec &spec)
void tileError(const QGeoTileSpec &spec, const QString &errorString)
virtual void engineTileFinished(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format)
virtual ~QGeoTiledMappingManagerEngine()
Destroys this mapping manager.
QAbstractGeoTileCache::CacheAreas cacheHint() const
QGeoTiledMappingManagerEnginePrivate * d_ptr
bool remove(const Key &key)
Removes the item that has the key from the hash.
Definition qhash.h:958
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
Definition qhash.h:1219
const_iterator constBegin() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1215
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QMap< QString, QString > map
[6]
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
@ QueuedConnection
#define Q_FUNC_INFO
static QT_BEGIN_NAMESPACE const int tileSize
Definition qmemrotate.cpp:9
#define Q_ARG(Type, data)
Definition qobjectdefs.h:63
GLint GLsizei GLsizei GLenum format
static void add(QPainterPath &path, const QWingedEdge &list, int edge, QPathEdge::Traversal traversal)
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
#define emit
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...