void QGeoTileCache::loadTiles() { QStringList formats; formats << QLatin1String("*.*"); QDir dir(directory_); QStringList files = dir.entryList(formats, QDir::Files); // Method: // 1. read each queue file then, if each file exists, deserialize the data into the appropriate // cache queue. for (int i = 1; i<=4; i++) { QString filename = dir.filePath(QString::fromLatin1("queue") + QString::number(i)); QFile file(filename); if (!file.open(QIODevice::ReadOnly)) continue; QList<QSharedPointer<QGeoCachedTileDisk> > queue; QList<QGeoTileSpec> specs; QList<int> costs; while (!file.atEnd()) { QByteArray line = file.readLine().trimmed(); QString filename = QString::fromLatin1(line.constData(), line.length()); if (dir.exists(filename)){ files.removeOne(filename); QGeoTileSpec spec = filenameToTileSpec(filename); if (spec.zoom() == -1) continue; QSharedPointer<QGeoCachedTileDisk> tileDisk(new QGeoCachedTileDisk); tileDisk->filename = dir.filePath(filename); tileDisk->cache = this; tileDisk->spec = spec; QFileInfo fi(tileDisk->filename); specs.append(spec); queue.append(tileDisk); costs.append(fi.size()); } } diskCache_.deserializeQueue(i, specs, queue, costs); file.close(); } // 2. remaining tiles that aren't registered in a queue get pushed into cache here // this is a backup, in case the queue manifest files get deleted or out of sync due to // the application not closing down properly for (int i = 0; i < files.size(); ++i) { QGeoTileSpec spec = filenameToTileSpec(files.at(i)); if (spec.zoom() == -1) continue; QString filename = dir.filePath(files.at(i)); addToDiskCache(spec, filename); } }
QString QGeoTileCache::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) { QString filename = spec.plugin(); filename += QLatin1String("-"); filename += QString::number(spec.mapId()); filename += QLatin1String("-"); filename += QString::number(spec.zoom()); filename += QLatin1String("-"); filename += QString::number(spec.x()); filename += QLatin1String("-"); filename += QString::number(spec.y()); //Append version if real version number to ensure backwards compatibility and eviction of old tiles if (spec.version() != -1) { filename += QLatin1String("-"); filename += QString::number(spec.version()); } filename += QLatin1String("."); filename += format; QDir dir = QDir(directory); return dir.filePath(filename); }
unsigned int qHash(const QGeoTileSpec &spec) { unsigned int result = (qHash(spec.plugin()) * 13) % 31; result += ((spec.mapId() * 17) % 31) << 5; result += ((spec.zoom() * 19) % 31) << 10; result += ((spec.x() * 23) % 31) << 15; result += ((spec.y() * 29) % 31) << 20; result += (spec.version() % 3) << 25; return result; }
void QGeoCameraTilesPrivate::updateMetadata() { typedef QSet<QGeoTileSpec>::const_iterator iter; QSet<QGeoTileSpec> newTiles; iter i = tiles_.constBegin(); iter end = tiles_.constEnd(); for (; i != end; ++i) { QGeoTileSpec tile = *i; newTiles.insert(QGeoTileSpec(pluginString_, mapType_.mapId(), tile.zoom(), tile.x(), tile.y(), mapVersion_)); } tiles_ = newTiles; }
QString QGeoTileCache::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) { QString filename = spec.plugin(); filename += QLatin1String("-"); filename += QString::number(spec.mapId()); filename += QLatin1String("-"); filename += QString::number(spec.zoom()); filename += QLatin1String("-"); filename += QString::number(spec.x()); filename += QLatin1String("-"); filename += QString::number(spec.y()); filename += QLatin1String("."); filename += format; QDir dir = QDir(directory); return dir.filePath(filename); }
QString QGeoTileFetcherNokia::getRequestString(const QGeoTileSpec &spec) { static const QString http("http://"); static const QString path("/maptiler/v2/maptile/newest/"); static const QChar slash('/'); QString requestString = http; requestString += m_uriProvider->getCurrentHost(); requestString += path; requestString += mapIdToStr(spec.mapId()); requestString += slash; requestString += QString::number(spec.zoom()); requestString += slash; requestString += QString::number(spec.x()); requestString += slash; requestString += QString::number(spec.y()); requestString += slash; requestString += sizeToStr(m_tileSize); static const QString slashpng("/png8"); requestString += slashpng; if (!m_token.isEmpty() && !m_applicationId.isEmpty()) { requestString += "?token="; requestString += m_token; requestString += "&app_id="; requestString += m_applicationId; } requestString += "&lg="; requestString += getLanguageString(); return requestString; }
QDebug operator<< (QDebug dbg, const QGeoTileSpec &spec) { dbg << spec.plugin() << spec.mapId() << spec.zoom() << spec.x() << spec.y() << spec.version(); return dbg; }
//----------------------------------------------------------------------------- QGeoTiledMapReplyQGC::QGeoTiledMapReplyQGC(QNetworkAccessManager *networkManager, const QNetworkRequest &request, const QGeoTileSpec &spec, QObject *parent) : QGeoTiledMapReply(spec, parent) , _reply(NULL) , _request(request) , _networkManager(networkManager) { if(_request.url().isEmpty()) { if(!_badMapBox.size()) { QFile b(":/res/notile.png"); if(b.open(QFile::ReadOnly)) _badMapBox = b.readAll(); } setMapImageData(_badMapBox); setMapImageFormat("png"); setFinished(true); setCached(false); } else { QGCFetchTileTask* task = getQGCMapEngine()->createFetchTileTask((UrlFactory::MapType)spec.mapId(), spec.x(), spec.y(), spec.zoom()); connect(task, &QGCFetchTileTask::tileFetched, this, &QGeoTiledMapReplyQGC::cacheReply); connect(task, &QGCMapTask::error, this, &QGeoTiledMapReplyQGC::cacheError); getQGCMapEngine()->addTask(task); } }