From ed4e201b0830ab847513e2857e768b86f8b7ed8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 4 Oct 2018 23:02:43 +0200 Subject: [PATCH] Cosmetics --- src/map/downloader.cpp | 16 ++++++++-------- src/map/downloader.h | 4 ++-- src/map/tileloader.cpp | 35 +++++++++++++++++++---------------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/map/downloader.cpp b/src/map/downloader.cpp index 0f4f9f3d..a6d41ee7 100644 --- a/src/map/downloader.cpp +++ b/src/map/downloader.cpp @@ -89,9 +89,10 @@ bool Downloader::_http2 = true; bool Downloader::doDownload(const Download &dl, const QByteArray &authorization, const Redirect *redirect) { - QUrl url(dl.url()); + const QUrl &url = dl.url(); - if (!url.isValid() || !(url.scheme() == "http" || url.scheme() == "https")) { + if (!url.isValid() || !(url.scheme() == QLatin1String("http") + || url.scheme() == QLatin1String("https"))) { qWarning("%s: Invalid URL", qPrintable(url.toString())); if (redirect) _errorDownloads.insert(redirect->origin(), RETRIES); @@ -161,11 +162,11 @@ void Downloader::insertError(const QUrl &url, QNetworkReply::NetworkError error) void Downloader::downloadFinished(QNetworkReply *reply) { - QUrl url = reply->request().url(); + QUrl url(reply->request().url()); QNetworkReply::NetworkError error = reply->error(); if (error) { - QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl(); + QUrl origin(reply->request().attribute(ATTR_ORIGIN).toUrl()); if (origin.isEmpty()) { insertError(url, error); qWarning("Error downloading file: %s: %s", @@ -177,12 +178,11 @@ void Downloader::downloadFinished(QNetworkReply *reply) qPrintable(reply->errorString())); } } else { - QUrl location = reply->attribute(ATTR_REDIRECT).toUrl(); - QString filename = reply->request().attribute(ATTR_FILE) - .toString(); + QUrl location(reply->attribute(ATTR_REDIRECT).toUrl()); + QString filename(reply->request().attribute(ATTR_FILE).toString()); if (!location.isEmpty()) { - QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl(); + QUrl origin(reply->request().attribute(ATTR_ORIGIN).toUrl()); int level = reply->request().attribute(ATTR_LEVEL).toInt(); if (level >= MAX_REDIRECT_LEVEL) { diff --git a/src/map/downloader.h b/src/map/downloader.h index 16ecfd43..c94c982a 100644 --- a/src/map/downloader.h +++ b/src/map/downloader.h @@ -15,8 +15,8 @@ class Download public: Download(const QUrl &url, const QString &file) : _url(url), _file(file) {} - const QUrl& url() const {return _url;} - const QString& file() const {return _file;} + const QUrl &url() const {return _url;} + const QString &file() const {return _file;} private: QUrl _url; diff --git a/src/map/tileloader.cpp b/src/map/tileloader.cpp index 061a9e98..6bfca12d 100644 --- a/src/map/tileloader.cpp +++ b/src/map/tileloader.cpp @@ -32,14 +32,16 @@ void TileLoader::loadTilesAsync(QList &list) Tile &t = list[i]; QString file(tileFile(t)); QFileInfo fi(file); - QUrl url(tileUrl(t)); - if (url.isLocalFile()) - loadTileFile(t, url.toLocalFile()); - else if (fi.exists()) + if (fi.exists()) loadTileFile(t, file); - else - dl.append(Download(url, file)); + else { + QUrl url(tileUrl(t)); + if (url.isLocalFile()) + loadTileFile(t, url.toLocalFile()); + else + dl.append(Download(url, file)); + } } if (!dl.empty()) @@ -54,14 +56,16 @@ void TileLoader::loadTilesSync(QList &list) Tile &t = list[i]; QString file(tileFile(t)); QFileInfo fi(file); - QUrl url(tileUrl(t)); - if (url.isLocalFile()) - loadTileFile(t, url.toLocalFile()); - else if (fi.exists()) + if (fi.exists()) loadTileFile(t, file); - else - dl.append(Download(url, file)); + else { + QUrl url(tileUrl(t)); + if (url.isLocalFile()) + loadTileFile(t, url.toLocalFile()); + else + dl.append(Download(url, file)); + } } if (dl.empty()) @@ -116,8 +120,7 @@ QUrl TileLoader::tileUrl(const Tile &tile) const QString TileLoader::tileFile(const Tile &tile) const { - QString file = _dir + QString("/%1-%2-%3").arg(tile.zoom().toString()) - .arg(tile.xy().x()).arg(tile.xy().y()); - - return file; + return _dir + QLatin1Char('/') + tile.zoom().toString() + QLatin1Char('-') + + QString::number(tile.xy().x()) + QLatin1Char('-') + + QString::number(tile.xy().y()); }