diff --git a/src/map/maplist.cpp b/src/map/maplist.cpp index c176e085..ad79f83e 100644 --- a/src/map/maplist.cpp +++ b/src/map/maplist.cpp @@ -20,13 +20,11 @@ bool MapList::loadMap(Map* map, const QString &path, bool dir) _errorString += path + ": " + map->errorString() + "\n"; else _errorString = map->errorString(); - - delete map; return false; } } -bool MapList::loadSource(const QString &path, bool dir) +Map *MapList::loadSource(const QString &path, bool dir) { QString err; Map *map = MapSource::loadMap(path, err); @@ -36,31 +34,39 @@ bool MapList::loadSource(const QString &path, bool dir) _errorString += path + ": " + err + "\n"; else _errorString = err; - return false; - } - map->setParent(this); + } else + map->setParent(this); - return loadMap(map, path, dir); + return map; } bool MapList::loadFile(const QString &path, bool *atlas, bool dir) { QFileInfo fi(path); QString suffix = fi.suffix().toLower(); + Map *map; if (Atlas::isAtlas(path)) { *atlas = true; - return loadMap(new Atlas(path, this), path, dir); - } else if (suffix == "xml") - return loadSource(path, dir); - else if (suffix == "jnx") - return loadMap(new JNXMap(path, this), path, dir); + map = new Atlas(path, this); + } else if (suffix == "xml") { + if (!(map = loadSource(path, dir))) + return false; + } else if (suffix == "jnx") + map = new JNXMap(path, this); else if (suffix == "tif" || suffix == "tiff") - return loadMap(new GeoTIFFMap(path, this), path, dir); + map = new GeoTIFFMap(path, this); else if (suffix == "mbtiles") - return loadMap(new MBTilesMap(path, this), path, dir); + map = new MBTilesMap(path, this); else - return loadMap(new OziMap(path, this), path, dir); + map = new OziMap(path, this); + + if (!loadMap(map, path, dir)) { + delete map; + return false; + } + + return true; } bool MapList::loadDirR(const QString &path) @@ -104,13 +110,6 @@ bool MapList::loadDir(const QString &path) return loadDirR(path); } -void MapList::clear() -{ - for (int i = 0; i < _maps.count(); i++) - delete _maps.at(i); - _maps.clear(); -} - QString MapList::formats() { return diff --git a/src/map/maplist.h b/src/map/maplist.h index 0672598a..87426a90 100644 --- a/src/map/maplist.h +++ b/src/map/maplist.h @@ -15,7 +15,6 @@ public: bool loadFile(const QString &path); bool loadDir(const QString &path); - void clear(); const QList &maps() const {return _maps;} const QString &errorString() const {return _errorString;} @@ -26,7 +25,7 @@ public: private: bool loadFile(const QString &path, bool *atlas, bool dir); bool loadDirR(const QString &path); - bool loadSource(const QString &path, bool dir); + Map *loadSource(const QString &path, bool dir); bool loadMap(Map *map, const QString &path, bool dir); QList _maps;