diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-09-04 14:02:09 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-09-07 17:58:16 +0000 |
commit | dcac944e0bf04e8fbe56c0c00d5ceb6d22980494 (patch) | |
tree | e2d3d0b39fc1393d25ddb502910a2bdf828671c2 /src | |
parent | 8fb58aa448de42ebeb17bc5d9c74e6ee78319292 (diff) | |
download | qtlocation-dcac944e0bf04e8fbe56c0c00d5ceb6d22980494.tar.gz |
Fix disfunctional disk cache with OSM
The MapQuest servers use JPEG, not PNG. The disk cache, unlike the memory
one, passed in the extension as the format to loadFromData(). This failed
for JPEG files with an extension of .png.
In addition, using split('.')[1] to determine the file extension is bogus.
On Linux for example, a directory of "$HOME/.cache/QtLocation/..." results
in putting "cache/..." into format which is then conveniently ignored by
QImageReader. On OS X however there is no dot, so it "correctly" picks
"png" for the JPEG data, hence the console is flooded with warnings about
failed tile loading.
On top of the above, the disk cache is made more robust by not relying on the
format string. As long as only formats supported by QImageReader are in use,
it can recognize the correct format from the data. (the memory cache does this
already anyway)
Change-Id: I90ece5bd157d457afa0025527c84070427a60313
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/location/maps/qgeotilecache.cpp | 6 | ||||
-rw-r--r-- | src/plugins/geoservices/osm/qgeomapreplyosm.cpp | 6 | ||||
-rw-r--r-- | src/plugins/geoservices/osm/qgeotilefetcherosm.cpp | 5 |
3 files changed, 12 insertions, 5 deletions
diff --git a/src/location/maps/qgeotilecache.cpp b/src/location/maps/qgeotilecache.cpp index aa76735f..4e15504d 100644 --- a/src/location/maps/qgeotilecache.cpp +++ b/src/location/maps/qgeotilecache.cpp @@ -297,19 +297,19 @@ QSharedPointer<QGeoTileTexture> QGeoTileCache::get(const QGeoTileSpec &spec) QSharedPointer<QGeoCachedTileDisk> td = diskCache_.object(spec); if (td) { - QStringList parts = td->filename.split('.'); + const QString format = QFileInfo(td->filename).suffix(); QFile file(td->filename); file.open(QIODevice::ReadOnly); QByteArray bytes = file.readAll(); file.close(); QPixmap pixmap; - if (!pixmap.loadFromData(bytes, (parts.size() == 2 ? parts.at(1).toLocal8Bit().constData() : 0))) { + if (!pixmap.loadFromData(bytes)) { handleError(spec, QLatin1String("Problem with tile image")); return QSharedPointer<QGeoTileTexture>(0); } - addToMemoryCache(spec, bytes, (parts.size() == 2 ? parts.at(1) : QLatin1String(""))); + addToMemoryCache(spec, bytes, format); QSharedPointer<QGeoTileTexture> tt = addToTextureCache(td->spec, pixmap); if (tt) return tt; diff --git a/src/plugins/geoservices/osm/qgeomapreplyosm.cpp b/src/plugins/geoservices/osm/qgeomapreplyosm.cpp index b540683b..d020716e 100644 --- a/src/plugins/geoservices/osm/qgeomapreplyosm.cpp +++ b/src/plugins/geoservices/osm/qgeomapreplyosm.cpp @@ -75,7 +75,11 @@ void QGeoMapReplyOsm::networkReplyFinished() QByteArray a = m_reply->readAll(); setMapImageData(a); - setMapImageFormat("png"); + int mapId = tileSpec().mapId(); + if (mapId == 1 || mapId == 2) + setMapImageFormat(QStringLiteral("jpg")); + else + setMapImageFormat(QStringLiteral("png")); setFinished(true); diff --git a/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp b/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp index 95a4355e..9d2a83fa 100644 --- a/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp +++ b/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp @@ -62,13 +62,16 @@ QGeoTiledMapReply *QGeoTileFetcherOsm::getTileImage(const QGeoTileSpec &spec) request.setRawHeader("User-Agent", m_userAgent); QString urlPrefix; + QString suffix = QStringLiteral(".png"); switch (spec.mapId()) { case 1: urlPrefix = QStringLiteral("http://otile1.mqcdn.com/tiles/1.0.0/map/"); + suffix = QStringLiteral(".jpg"); break; case 2: urlPrefix = QStringLiteral("http://otile1.mqcdn.com/tiles/1.0.0/sat/"); + suffix = QStringLiteral(".jpg"); break; case 3: urlPrefix = QStringLiteral("http://a.tile.thunderforest.com/cycle/"); @@ -94,7 +97,7 @@ QGeoTiledMapReply *QGeoTileFetcherOsm::getTileImage(const QGeoTileSpec &spec) request.setUrl(QUrl(urlPrefix + QString::number(spec.zoom()) + QLatin1Char('/') + QString::number(spec.x()) + QLatin1Char('/') + - QString::number(spec.y()) + QStringLiteral(".png"))); + QString::number(spec.y()) + suffix)); QNetworkReply *reply = m_networkManager->get(request); |