1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

API cleanup

This commit is contained in:
Martin Tůma 2018-01-31 20:03:50 +01:00
parent 4ca9c79dc4
commit 44d84bf19e
3 changed files with 9 additions and 23 deletions

View File

@ -13,7 +13,7 @@ bool MapList::loadSource(const QString &path, bool dir)
MapSource ms; MapSource ms;
Map *map; Map *map;
if (!ms.loadFile(path)) { if (!ms.loadFile(path, &map)) {
if (dir) if (dir)
_errorString += path + ": " + ms.errorString() + "\n"; _errorString += path + ": " + ms.errorString() + "\n";
else else
@ -21,7 +21,6 @@ bool MapList::loadSource(const QString &path, bool dir)
return false; return false;
} }
map = ms.map();
map->setParent(this); map->setParent(this);
_maps.append(map); _maps.append(map);

View File

@ -121,7 +121,7 @@ RectC MapSource::bounds(QXmlStreamReader &reader)
return RectC(Coordinates(left, top), Coordinates(right, bottom)); return RectC(Coordinates(left, top), Coordinates(right, bottom));
} }
void MapSource::map(QXmlStreamReader &reader) void MapSource::map(QXmlStreamReader &reader, Map **map)
{ {
QString name, url; QString name, url;
Range z(ZOOM_MIN, ZOOM_MAX); Range z(ZOOM_MIN, ZOOM_MAX);
@ -143,10 +143,10 @@ void MapSource::map(QXmlStreamReader &reader)
reader.skipCurrentElement(); 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); QFile file(path);
QXmlStreamReader reader; QXmlStreamReader reader;
@ -160,20 +160,13 @@ bool MapSource::loadFile(const QString &path)
if (reader.readNextStartElement()) { if (reader.readNextStartElement()) {
if (reader.name() == "map") if (reader.name() == "map")
map(reader); MapSource::map(reader, map);
else else
reader.raiseError("Not an online map source file"); reader.raiseError("Not an online map source file");
} }
if (reader.error()) _errorString = reader.error() ? QString("%1: %2").arg(reader.lineNumber())
_errorString = QString("%1: %2").arg(reader.lineNumber()) .arg(reader.errorString()) : QString();
.arg(reader.errorString());
return !reader.error(); return !reader.error();
} }
MapSource::~MapSource()
{
if (_map && !_map->parent())
delete _map;
}

View File

@ -11,21 +11,15 @@ class QXmlStreamReader;
class MapSource class MapSource
{ {
public: public:
MapSource() : _map(0) {} bool loadFile(const QString &path, Map **map);
~MapSource();
bool loadFile(const QString &path);
const QString &errorString() const {return _errorString;} const QString &errorString() const {return _errorString;}
Map* map() const {return _map;}
private: private:
RectC bounds(QXmlStreamReader &reader); RectC bounds(QXmlStreamReader &reader);
Range zooms(QXmlStreamReader &reader); Range zooms(QXmlStreamReader &reader);
void map(QXmlStreamReader &reader); void map(QXmlStreamReader &reader, Map **map);
QString _errorString; QString _errorString;
Map *_map;
}; };
#endif // MAPSOURCE_H #endif // MAPSOURCE_H