mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-27 21:24:47 +01:00
API cleanup
This commit is contained in:
parent
4ca9c79dc4
commit
44d84bf19e
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user