From 99ea19e35a1c7723599a825dabe099fd9e27fc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 21 Sep 2018 00:19:30 +0200 Subject: [PATCH] Use the map name from the metadata table if available --- src/map/mbtilesmap.cpp | 15 +++++++++------ src/map/mbtilesmap.h | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/map/mbtilesmap.cpp b/src/map/mbtilesmap.cpp index ad5e29c5..251503d5 100644 --- a/src/map/mbtilesmap.cpp +++ b/src/map/mbtilesmap.cpp @@ -76,22 +76,25 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent) qMax(0, query.value(3).toInt())) + 1, _zooms.min()); Coordinates tl(osm::m2ll(QPointF(minX, maxY))); Coordinates br(osm::m2ll(QPointF(maxX, minY))); - // Workaround of broken zoom level 0 and 1 due to numerical instability + // Workaround of broken zoom levels 0 and 1 due to numerical instability tl.rlat() = qMin(tl.lat(), 85.0511); br.rlat() = qMax(br.lat(), -85.0511); _bounds = RectC(tl, br); } + { + QSqlQuery query("SELECT value FROM metadata WHERE name = 'name'", _db); + if (query.first()) + _name = query.value(0).toString(); + else + _name = QFileInfo(_fileName).fileName(); + } + _db.close(); _valid = true; } -QString MBTilesMap::name() const -{ - return QFileInfo(_fileName).fileName();; -} - void MBTilesMap::load() { _db.open(); diff --git a/src/map/mbtilesmap.h b/src/map/mbtilesmap.h index 44530f79..a3eb7755 100644 --- a/src/map/mbtilesmap.h +++ b/src/map/mbtilesmap.h @@ -11,7 +11,7 @@ class MBTilesMap : public Map public: MBTilesMap(const QString &fileName, QObject *parent = 0); - QString name() const; + QString name() const {return _name;} QRectF bounds(); qreal resolution(const QRectF &rect); @@ -43,7 +43,7 @@ private: QSqlDatabase _db; - QString _fileName; + QString _fileName, _name; RectC _bounds; Range _zooms; int _zoom;