mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-28 03:59:15 +02:00
30
src/map/invalidmap.h
Normal file
30
src/map/invalidmap.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef INVALIDMAP_H
|
||||
#define INVALIDMAP_H
|
||||
|
||||
#include "map.h"
|
||||
|
||||
class InvalidMap : public Map
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InvalidMap(const QString &fileName, const QString &error, QObject *parent = 0)
|
||||
: Map(fileName, parent), _errorString(error) {}
|
||||
|
||||
QString name() const {return QString();}
|
||||
|
||||
QRectF bounds() {return QRectF();}
|
||||
|
||||
QPointF ll2xy(const Coordinates &) {return QPointF();}
|
||||
Coordinates xy2ll(const QPointF &) {return Coordinates();}
|
||||
|
||||
void draw(QPainter *, const QRectF &, Flags) {}
|
||||
|
||||
bool isValid() const {return false;}
|
||||
QString errorString() const {return _errorString;}
|
||||
|
||||
private:
|
||||
QString _errorString;
|
||||
};
|
||||
|
||||
#endif // INVALIDMAP_H
|
@ -11,11 +11,11 @@
|
||||
#include "imgmap.h"
|
||||
#include "IMG/gmap.h"
|
||||
#include "bsbmap.h"
|
||||
#include "invalidmap.h"
|
||||
#include "maplist.h"
|
||||
|
||||
|
||||
Map *MapList::loadFile(const QString &path, QString &errorString,
|
||||
bool *terminate)
|
||||
Map *MapList::loadFile(const QString &path, bool *terminate)
|
||||
{
|
||||
QFileInfo fi(path);
|
||||
QString suffix = fi.suffix().toLower();
|
||||
@ -27,12 +27,11 @@ Map *MapList::loadFile(const QString &path, QString &errorString,
|
||||
map = new Atlas(path);
|
||||
} else if (suffix == "xml") {
|
||||
if (MapSource::isMap(path)) {
|
||||
if (!(map = MapSource::loadMap(path, errorString)))
|
||||
return 0;
|
||||
map = MapSource::loadMap(path);
|
||||
} else if (GMAP::isGMAP(path)) {
|
||||
map = new IMGMap(path);
|
||||
if (terminate)
|
||||
*terminate = true;
|
||||
map = new IMGMap(path);
|
||||
}
|
||||
} else if (suffix == "jnx")
|
||||
map = new JNXMap(path);
|
||||
@ -49,16 +48,10 @@ Map *MapList::loadFile(const QString &path, QString &errorString,
|
||||
else if (suffix == "kap")
|
||||
map = new BSBMap(path);
|
||||
|
||||
if (map && map->isValid())
|
||||
return map;
|
||||
else {
|
||||
errorString = (map) ? map->errorString() : "Unknown file format";
|
||||
delete map;
|
||||
return 0;
|
||||
}
|
||||
return map ? map : new InvalidMap(path, "Unknown file format");
|
||||
}
|
||||
|
||||
QList<Map*> MapList::loadDir(const QString &path, QString &errorString)
|
||||
QList<Map*> MapList::loadDir(const QString &path)
|
||||
{
|
||||
QDir md(path);
|
||||
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
@ -72,14 +65,9 @@ QList<Map*> MapList::loadDir(const QString &path, QString &errorString)
|
||||
bool terminate = false;
|
||||
|
||||
if (fi.isDir() && fi.fileName() != "set")
|
||||
list.append(loadDir(fi.absoluteFilePath(), errorString));
|
||||
list.append(loadDir(fi.absoluteFilePath()));
|
||||
else if (filter().contains("*." + suffix)) {
|
||||
Map *map = loadFile(fi.absoluteFilePath(), errorString, &terminate);
|
||||
if (map)
|
||||
list.append(map);
|
||||
else
|
||||
qWarning("%s: %s", qPrintable(fi.absoluteFilePath()),
|
||||
qPrintable(errorString));
|
||||
list.append(loadFile(fi.absoluteFilePath(), &terminate));
|
||||
if (terminate)
|
||||
break;
|
||||
}
|
||||
@ -88,15 +76,13 @@ QList<Map*> MapList::loadDir(const QString &path, QString &errorString)
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<Map*> MapList::loadMaps(const QString &path, QString &errorString)
|
||||
QList<Map*> MapList::loadMaps(const QString &path)
|
||||
{
|
||||
if (QFileInfo(path).isDir())
|
||||
return loadDir(path, errorString);
|
||||
return loadDir(path);
|
||||
else {
|
||||
QList<Map*> list;
|
||||
Map *map = loadFile(path, errorString, 0);
|
||||
if (map)
|
||||
list.append(map);
|
||||
list.append(loadFile(path, 0));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,13 @@ class Map;
|
||||
class MapList
|
||||
{
|
||||
public:
|
||||
static QList<Map*> loadMaps(const QString &path, QString &errorString);
|
||||
static QList<Map*> loadMaps(const QString &path);
|
||||
static QString formats();
|
||||
static QStringList filter();
|
||||
|
||||
private:
|
||||
static Map *loadFile(const QString &path, QString &errorString,
|
||||
bool *terminate);
|
||||
static QList<Map*> loadDir(const QString &path, QString &errorString);
|
||||
static Map *loadFile(const QString &path, bool *terminate);
|
||||
static QList<Map*> loadDir(const QString &path);
|
||||
};
|
||||
|
||||
#endif // MAPLIST_H
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "wmtsmap.h"
|
||||
#include "wmsmap.h"
|
||||
#include "osm.h"
|
||||
#include "invalidmap.h"
|
||||
#include "mapsource.h"
|
||||
|
||||
|
||||
@ -236,16 +237,14 @@ bool MapSource::isMap(const QString &path)
|
||||
return false;
|
||||
}
|
||||
|
||||
Map *MapSource::loadMap(const QString &path, QString &errorString)
|
||||
Map *MapSource::loadMap(const QString &path)
|
||||
{
|
||||
Config config;
|
||||
QFile file(path);
|
||||
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
errorString = file.errorString();
|
||||
return 0;
|
||||
}
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text))
|
||||
return new InvalidMap(path, file.errorString());
|
||||
|
||||
QXmlStreamReader reader(&file);
|
||||
if (reader.readNextStartElement()) {
|
||||
@ -254,41 +253,27 @@ Map *MapSource::loadMap(const QString &path, QString &errorString)
|
||||
else
|
||||
reader.raiseError("Not an online map source file");
|
||||
}
|
||||
if (reader.error()) {
|
||||
errorString = QString("%1: %2").arg(reader.lineNumber())
|
||||
.arg(reader.errorString());
|
||||
return 0;
|
||||
}
|
||||
if (reader.error())
|
||||
return new InvalidMap(path, QString("%1: %2").arg(reader.lineNumber())
|
||||
.arg(reader.errorString()));
|
||||
|
||||
if (config.name.isEmpty()) {
|
||||
errorString = "Missing name definition";
|
||||
return 0;
|
||||
}
|
||||
if (config.url.isEmpty()) {
|
||||
errorString = "Missing URL definition";
|
||||
return 0;
|
||||
}
|
||||
if (config.name.isEmpty())
|
||||
return new InvalidMap(path, "Missing name definition");
|
||||
if (config.url.isEmpty())
|
||||
return new InvalidMap(path, "Missing URL definition");
|
||||
if (config.type == WMTS || config.type == WMS) {
|
||||
if (config.layer.isEmpty()) {
|
||||
errorString = "Missing layer definition";
|
||||
return 0;
|
||||
}
|
||||
if (config.format.isEmpty()) {
|
||||
errorString = "Missing format definition";
|
||||
return 0;
|
||||
}
|
||||
if (config.layer.isEmpty())
|
||||
return new InvalidMap(path, "Missing layer definition");
|
||||
if (config.format.isEmpty())
|
||||
return new InvalidMap(path, "Missing format definition");
|
||||
}
|
||||
if (config.type == WMTS) {
|
||||
if (config.set.isEmpty()) {
|
||||
errorString = "Missing set definiton";
|
||||
return 0;
|
||||
}
|
||||
if (config.set.isEmpty())
|
||||
return new InvalidMap(path, "Missing set definiton");
|
||||
}
|
||||
if (config.type == WMS) {
|
||||
if (config.crs.isEmpty()) {
|
||||
errorString = "Missing CRS definiton";
|
||||
return 0;
|
||||
}
|
||||
if (config.crs.isEmpty())
|
||||
return new InvalidMap(path, "Missing CRS definiton");
|
||||
}
|
||||
|
||||
switch (config.type) {
|
||||
@ -315,6 +300,6 @@ Map *MapSource::loadMap(const QString &path, QString &errorString)
|
||||
config.bounds, config.tileRatio, config.authorization,
|
||||
config.tileSize, config.scalable, false, true);
|
||||
default:
|
||||
return 0;
|
||||
return new InvalidMap(path, "Invalid map type");
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class QXmlStreamReader;
|
||||
class MapSource
|
||||
{
|
||||
public:
|
||||
static Map *loadMap(const QString &path, QString &errorString);
|
||||
static Map *loadMap(const QString &path);
|
||||
static bool isMap(const QString &path);
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user