From 44d84bf19e041f78097820fcd7a9cadd96e90248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 31 Jan 2018 20:03:50 +0100 Subject: [PATCH] API cleanup --- src/map/maplist.cpp | 3 +-- src/map/mapsource.cpp | 19 ++++++------------- src/map/mapsource.h | 10 ++-------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/map/maplist.cpp b/src/map/maplist.cpp index 732b5573..fc605c3f 100644 --- a/src/map/maplist.cpp +++ b/src/map/maplist.cpp @@ -13,7 +13,7 @@ bool MapList::loadSource(const QString &path, bool dir) MapSource ms; Map *map; - if (!ms.loadFile(path)) { + if (!ms.loadFile(path, &map)) { if (dir) _errorString += path + ": " + ms.errorString() + "\n"; else @@ -21,7 +21,6 @@ bool MapList::loadSource(const QString &path, bool dir) return false; } - map = ms.map(); map->setParent(this); _maps.append(map); diff --git a/src/map/mapsource.cpp b/src/map/mapsource.cpp index f78ff248..26a0da18 100644 --- a/src/map/mapsource.cpp +++ b/src/map/mapsource.cpp @@ -121,7 +121,7 @@ RectC MapSource::bounds(QXmlStreamReader &reader) return RectC(Coordinates(left, top), Coordinates(right, bottom)); } -void MapSource::map(QXmlStreamReader &reader) +void MapSource::map(QXmlStreamReader &reader, Map **map) { QString name, url; Range z(ZOOM_MIN, ZOOM_MAX); @@ -143,10 +143,10 @@ void MapSource::map(QXmlStreamReader &reader) reader.skipCurrentElement(); } - _map = new OnlineMap(name, url, z, b); + *map = reader.error() ? 0 : new OnlineMap(name, url, z, b); } -bool MapSource::loadFile(const QString &path) +bool MapSource::loadFile(const QString &path, Map **map) { QFile file(path); QXmlStreamReader reader; @@ -160,20 +160,13 @@ bool MapSource::loadFile(const QString &path) if (reader.readNextStartElement()) { if (reader.name() == "map") - map(reader); + MapSource::map(reader, map); else reader.raiseError("Not an online map source file"); } - if (reader.error()) - _errorString = QString("%1: %2").arg(reader.lineNumber()) - .arg(reader.errorString()); + _errorString = reader.error() ? QString("%1: %2").arg(reader.lineNumber()) + .arg(reader.errorString()) : QString(); return !reader.error(); } - -MapSource::~MapSource() -{ - if (_map && !_map->parent()) - delete _map; -} diff --git a/src/map/mapsource.h b/src/map/mapsource.h index c3d3e6e7..24bade0c 100644 --- a/src/map/mapsource.h +++ b/src/map/mapsource.h @@ -11,21 +11,15 @@ class QXmlStreamReader; class MapSource { public: - MapSource() : _map(0) {} - ~MapSource(); - - bool loadFile(const QString &path); + bool loadFile(const QString &path, Map **map); const QString &errorString() const {return _errorString;} - Map* map() const {return _map;} - private: RectC bounds(QXmlStreamReader &reader); Range zooms(QXmlStreamReader &reader); - void map(QXmlStreamReader &reader); + void map(QXmlStreamReader &reader, Map **map); QString _errorString; - Map *_map; }; #endif // MAPSOURCE_H