1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-25 18:49:16 +02:00

Only allow one map per file

This commit is contained in:
2018-01-29 00:19:57 +01:00
parent aa07b20aa4
commit fbc0fd86cf
14 changed files with 70 additions and 78 deletions

View File

@ -4,25 +4,26 @@
#include "atlas.h"
#include "offlinemap.h"
#include "onlinemap.h"
#include "omd.h"
#include "mapsource.h"
#include "maplist.h"
bool MapList::loadList(const QString &path, bool dir)
bool MapList::loadSource(const QString &path, bool dir)
{
OMD omd;
MapSource ms;
Map *map;
if (!omd.loadFile(path)) {
if (!ms.loadFile(path)) {
if (dir)
_errorString += path + ": " + omd.errorString() + "\n";
_errorString += path + ": " + ms.errorString() + "\n";
else
_errorString = omd.errorString();
_errorString = ms.errorString();
return false;
}
_maps += omd.maps();
for (int i = 0; i < omd.maps().size(); i++)
omd.maps()[i]->setParent(this);
map = ms.map();
map->setParent(this);
_maps.append(map);
return true;
}
@ -71,7 +72,7 @@ bool MapList::loadFile(const QString &path, bool *atlas, bool dir)
return loadAtlas(path, dir);
} else if (suffix == "xml") {
*atlas = false;
return loadList(path, dir);
return loadSource(path, dir);
} else {
*atlas = false;
return loadMap(path, dir);
@ -123,7 +124,7 @@ QString MapList::formats()
+ tr("OziExplorer maps (*.map)") + ";;"
+ tr("TrekBuddy maps/atlases (*.tar *.tba)") + ";;"
+ tr("GeoTIFF images (*.tif *.tiff)") + ";;"
+ tr("Online map definitions (*.xml)");
+ tr("Online map sources (*.xml)");
}
QStringList MapList::filter()

View File

@ -29,7 +29,7 @@ private:
Map *loadListEntry(const QByteArray &line);
bool loadList(const QString &path, bool dir);
bool loadSource(const QString &path, bool dir);
bool loadMap(const QString &path, bool dir);
bool loadAtlas(const QString &path, bool dir);

View File

@ -1,7 +1,7 @@
#include <QFile>
#include <QXmlStreamReader>
#include "onlinemap.h"
#include "omd.h"
#include "mapsource.h"
#define ZOOM_MAX 19
@ -11,7 +11,7 @@
#define BOUNDS_RIGHT 180
#define BOUNDS_BOTTOM -85.0511
Range OMD::zooms(QXmlStreamReader &reader)
Range MapSource::zooms(QXmlStreamReader &reader)
{
const QXmlStreamAttributes &attr = reader.attributes();
int min, max;
@ -51,7 +51,7 @@ Range OMD::zooms(QXmlStreamReader &reader)
return Range(min, max);
}
RectC OMD::bounds(QXmlStreamReader &reader)
RectC MapSource::bounds(QXmlStreamReader &reader)
{
const QXmlStreamAttributes &attr = reader.attributes();
double top, left, bottom, right;
@ -121,7 +121,7 @@ RectC OMD::bounds(QXmlStreamReader &reader)
return RectC(Coordinates(left, top), Coordinates(right, bottom));
}
void OMD::map(QXmlStreamReader &reader)
void MapSource::map(QXmlStreamReader &reader)
{
QString name, url;
Range z(ZOOM_MIN, ZOOM_MAX);
@ -143,20 +143,10 @@ void OMD::map(QXmlStreamReader &reader)
reader.skipCurrentElement();
}
_maps.append(new OnlineMap(name, url, z, b));
_map = new OnlineMap(name, url, z, b);
}
void OMD::omd(QXmlStreamReader &reader)
{
while (reader.readNextStartElement()) {
if (reader.name() == "map")
map(reader);
else
reader.skipCurrentElement();
}
}
bool OMD::loadFile(const QString &path)
bool MapSource::loadFile(const QString &path)
{
QFile file(path);
QXmlStreamReader reader;
@ -169,10 +159,10 @@ bool OMD::loadFile(const QString &path)
reader.setDevice(&file);
if (reader.readNextStartElement()) {
if (reader.name() == "omd")
omd(reader);
if (reader.name() == "map")
map(reader);
else
reader.raiseError("Not an online map definitions file");
reader.raiseError("Not an online map source file");
}
if (reader.error())
@ -182,9 +172,8 @@ bool OMD::loadFile(const QString &path)
return !reader.error();
}
OMD::~OMD()
{
for (int i = 0; i < _maps.size(); i++)
if (!_maps.at(i)->parent())
delete _maps.at(i);
MapSource::~MapSource()
{
if (_map && !_map->parent())
delete _map;
}

View File

@ -1,5 +1,5 @@
#ifndef OMD_H
#define OMD_H
#ifndef MAPSOURCE_H
#define MAPSOURCE_H
#include <QList>
#include "common/range.h"
@ -8,24 +8,24 @@
class Map;
class QXmlStreamReader;
class OMD
class MapSource
{
public:
~OMD();
MapSource() : _map(0) {}
~MapSource();
bool loadFile(const QString &path);
const QString &errorString() const {return _errorString;}
const QList<Map*> &maps() const {return _maps;}
Map* map() const {return _map;}
private:
RectC bounds(QXmlStreamReader &reader);
Range zooms(QXmlStreamReader &reader);
void map(QXmlStreamReader &reader);
void omd(QXmlStreamReader &reader);
QString _errorString;
QList<Map*> _maps;
Map* _map;
};
#endif // OMD_H
#endif // MAPSOURCE_H