mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-03-16 11:37:46 +01:00
Code cleanup
This commit is contained in:
parent
e1e49b32e6
commit
46cefada94
@ -16,7 +16,7 @@ MapSource::TMSConfig::TMSConfig()
|
|||||||
Coordinates(BOUNDS_RIGHT, BOUNDS_BOTTOM)) {}
|
Coordinates(BOUNDS_RIGHT, BOUNDS_BOTTOM)) {}
|
||||||
|
|
||||||
|
|
||||||
void MapSource::zooms(QXmlStreamReader &reader, Range &val)
|
Range MapSource::zooms(QXmlStreamReader &reader)
|
||||||
{
|
{
|
||||||
const QXmlStreamAttributes &attr = reader.attributes();
|
const QXmlStreamAttributes &attr = reader.attributes();
|
||||||
int min, max;
|
int min, max;
|
||||||
@ -30,7 +30,7 @@ void MapSource::zooms(QXmlStreamReader &reader, Range &val)
|
|||||||
#endif // QT_VERSION < 5
|
#endif // QT_VERSION < 5
|
||||||
if (!res || (min < ZOOM_MIN || min > ZOOM_MAX)) {
|
if (!res || (min < ZOOM_MIN || min > ZOOM_MAX)) {
|
||||||
reader.raiseError("Invalid minimal zoom level");
|
reader.raiseError("Invalid minimal zoom level");
|
||||||
return;
|
return Range();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
min = ZOOM_MIN;
|
min = ZOOM_MIN;
|
||||||
@ -43,17 +43,20 @@ void MapSource::zooms(QXmlStreamReader &reader, Range &val)
|
|||||||
#endif // QT_VERSION < 5
|
#endif // QT_VERSION < 5
|
||||||
if (!res || (max < ZOOM_MIN || max > ZOOM_MAX)) {
|
if (!res || (max < ZOOM_MIN || max > ZOOM_MAX)) {
|
||||||
reader.raiseError("Invalid maximal zoom level");
|
reader.raiseError("Invalid maximal zoom level");
|
||||||
return;
|
return Range();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
max = ZOOM_MAX;
|
max = ZOOM_MAX;
|
||||||
|
|
||||||
val = Range(min, max);
|
if (min > max) {
|
||||||
if (!val.isValid())
|
|
||||||
reader.raiseError("Invalid maximal/minimal zoom level combination");
|
reader.raiseError("Invalid maximal/minimal zoom level combination");
|
||||||
|
return Range();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Range(min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapSource::bounds(QXmlStreamReader &reader, RectC &val)
|
RectC MapSource::bounds(QXmlStreamReader &reader)
|
||||||
{
|
{
|
||||||
const QXmlStreamAttributes &attr = reader.attributes();
|
const QXmlStreamAttributes &attr = reader.attributes();
|
||||||
double top, left, bottom, right;
|
double top, left, bottom, right;
|
||||||
@ -67,7 +70,7 @@ void MapSource::bounds(QXmlStreamReader &reader, RectC &val)
|
|||||||
#endif // QT_VERSION < 5
|
#endif // QT_VERSION < 5
|
||||||
if (!res || (top < BOUNDS_BOTTOM || top > BOUNDS_TOP)) {
|
if (!res || (top < BOUNDS_BOTTOM || top > BOUNDS_TOP)) {
|
||||||
reader.raiseError("Invalid bounds top value");
|
reader.raiseError("Invalid bounds top value");
|
||||||
return;
|
return RectC();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
top = BOUNDS_TOP;
|
top = BOUNDS_TOP;
|
||||||
@ -80,7 +83,7 @@ void MapSource::bounds(QXmlStreamReader &reader, RectC &val)
|
|||||||
#endif // QT_VERSION < 5
|
#endif // QT_VERSION < 5
|
||||||
if (!res || (bottom < BOUNDS_BOTTOM || bottom > BOUNDS_TOP)) {
|
if (!res || (bottom < BOUNDS_BOTTOM || bottom > BOUNDS_TOP)) {
|
||||||
reader.raiseError("Invalid bounds bottom value");
|
reader.raiseError("Invalid bounds bottom value");
|
||||||
return;
|
return RectC();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
bottom = BOUNDS_BOTTOM;
|
bottom = BOUNDS_BOTTOM;
|
||||||
@ -93,7 +96,7 @@ void MapSource::bounds(QXmlStreamReader &reader, RectC &val)
|
|||||||
#endif // QT_VERSION < 5
|
#endif // QT_VERSION < 5
|
||||||
if (!res || (left < BOUNDS_LEFT || left > BOUNDS_RIGHT)) {
|
if (!res || (left < BOUNDS_LEFT || left > BOUNDS_RIGHT)) {
|
||||||
reader.raiseError("Invalid bounds left value");
|
reader.raiseError("Invalid bounds left value");
|
||||||
return;
|
return RectC();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
left = BOUNDS_LEFT;
|
left = BOUNDS_LEFT;
|
||||||
@ -106,21 +109,21 @@ void MapSource::bounds(QXmlStreamReader &reader, RectC &val)
|
|||||||
#endif // QT_VERSION < 5
|
#endif // QT_VERSION < 5
|
||||||
if (!res || (right < BOUNDS_LEFT || right > BOUNDS_RIGHT)) {
|
if (!res || (right < BOUNDS_LEFT || right > BOUNDS_RIGHT)) {
|
||||||
reader.raiseError("Invalid bounds right value");
|
reader.raiseError("Invalid bounds right value");
|
||||||
return;
|
return RectC();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
right = BOUNDS_RIGHT;
|
right = BOUNDS_RIGHT;
|
||||||
|
|
||||||
if (bottom > top || top < bottom) {
|
if (bottom >= top) {
|
||||||
reader.raiseError("Invalid bottom/top bounds combination");
|
reader.raiseError("Invalid bottom/top bounds combination");
|
||||||
return;
|
return RectC();
|
||||||
}
|
}
|
||||||
if (left > right || right < left) {
|
if (left >= right) {
|
||||||
reader.raiseError("Invalid left/right bounds combination");
|
reader.raiseError("Invalid left/right bounds combination");
|
||||||
return;
|
return RectC();
|
||||||
}
|
}
|
||||||
|
|
||||||
val = RectC(Coordinates(left, top), Coordinates(right, bottom));
|
return RectC(Coordinates(left, top), Coordinates(right, bottom));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapSource::map(QXmlStreamReader &reader, Config &config)
|
void MapSource::map(QXmlStreamReader &reader, Config &config)
|
||||||
@ -131,44 +134,25 @@ void MapSource::map(QXmlStreamReader &reader, Config &config)
|
|||||||
if (reader.name() == "name")
|
if (reader.name() == "name")
|
||||||
config.name = reader.readElementText();
|
config.name = reader.readElementText();
|
||||||
else if (reader.name() == "url") {
|
else if (reader.name() == "url") {
|
||||||
if (config.type == WMTS)
|
config.wmts.rest = (reader.attributes().value("type") == "REST")
|
||||||
config.wmts.rest = (reader.attributes().value("type") == "REST")
|
? true : false;
|
||||||
? true : false;
|
|
||||||
config.url = reader.readElementText();
|
config.url = reader.readElementText();
|
||||||
} else if (reader.name() == "zoom") {
|
} else if (reader.name() == "zoom") {
|
||||||
if (config.type == TMS)
|
config.tms.zooms = zooms(reader);
|
||||||
zooms(reader, config.tms.zooms);
|
|
||||||
else
|
|
||||||
reader.raiseError("Illegal zoom element");
|
|
||||||
reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
} else if (reader.name() == "bounds") {
|
} else if (reader.name() == "bounds") {
|
||||||
if (config.type == TMS)
|
config.tms.bounds = bounds(reader);
|
||||||
bounds(reader, config.tms.bounds);
|
|
||||||
else
|
|
||||||
reader.raiseError("Illegal bounds element");
|
|
||||||
reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
} else if (reader.name() == "format") {
|
} else if (reader.name() == "format") {
|
||||||
if (config.type == WMTS)
|
config.wmts.format = reader.readElementText();
|
||||||
config.wmts.format = reader.readElementText();
|
|
||||||
else
|
|
||||||
reader.raiseError("Illegal format element");
|
|
||||||
} else if (reader.name() == "layer")
|
} else if (reader.name() == "layer")
|
||||||
if (config.type == WMTS)
|
config.wmts.layer = reader.readElementText();
|
||||||
config.wmts.layer = reader.readElementText();
|
|
||||||
else
|
|
||||||
reader.raiseError("Illegal layer element");
|
|
||||||
else if (reader.name() == "style")
|
else if (reader.name() == "style")
|
||||||
if (config.type == WMTS)
|
config.wmts.style = reader.readElementText();
|
||||||
config.wmts.style = reader.readElementText();
|
|
||||||
else
|
|
||||||
reader.raiseError("Illegal style element");
|
|
||||||
else if (reader.name() == "set") {
|
else if (reader.name() == "set") {
|
||||||
if (config.type == WMTS) {
|
config.wmts.yx = (reader.attributes().value("axis") == "yx")
|
||||||
config.wmts.yx = (reader.attributes().value("axis") == "yx")
|
? true : false;
|
||||||
? true : false;
|
config.wmts.set = reader.readElementText();
|
||||||
config.wmts.set = reader.readElementText();
|
|
||||||
} else
|
|
||||||
reader.raiseError("Illegal set element");
|
|
||||||
} else
|
} else
|
||||||
reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ private:
|
|||||||
Config() : type(TMS) {}
|
Config() : type(TMS) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
void bounds(QXmlStreamReader &reader, RectC &val);
|
RectC bounds(QXmlStreamReader &reader);
|
||||||
void zooms(QXmlStreamReader &reader, Range &val);
|
Range zooms(QXmlStreamReader &reader);
|
||||||
void map(QXmlStreamReader &reader, Config &config);
|
void map(QXmlStreamReader &reader, Config &config);
|
||||||
|
|
||||||
QString _errorString;
|
QString _errorString;
|
||||||
|
106
src/map/wmts.cpp
106
src/map/wmts.cpp
@ -5,6 +5,7 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QtAlgorithms>
|
#include <QtAlgorithms>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
#include "downloader.h"
|
#include "downloader.h"
|
||||||
#include "pcs.h"
|
#include "pcs.h"
|
||||||
#include "wmts.h"
|
#include "wmts.h"
|
||||||
@ -92,20 +93,20 @@ WMTS::TileMatrix WMTS::tileMatrix(QXmlStreamReader &reader, bool yx)
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMTS::tileMatrixSet(CTX &ctx)
|
void WMTS::tileMatrixSet(QXmlStreamReader &reader, CTX &ctx)
|
||||||
{
|
{
|
||||||
QString id, crs;
|
QString id, crs;
|
||||||
QSet<TileMatrix> matrixes;
|
QSet<TileMatrix> matrixes;
|
||||||
|
|
||||||
while (ctx.reader.readNextStartElement()) {
|
while (reader.readNextStartElement()) {
|
||||||
if (ctx.reader.name() == "Identifier")
|
if (reader.name() == "Identifier")
|
||||||
id = ctx.reader.readElementText();
|
id = reader.readElementText();
|
||||||
else if (ctx.reader.name() == "SupportedCRS")
|
else if (reader.name() == "SupportedCRS")
|
||||||
crs = ctx.reader.readElementText();
|
crs = reader.readElementText();
|
||||||
else if (ctx.reader.name() == "TileMatrix")
|
else if (reader.name() == "TileMatrix")
|
||||||
matrixes.insert(tileMatrix(ctx.reader, ctx.setup.yx));
|
matrixes.insert(tileMatrix(reader, ctx.setup.yx));
|
||||||
else
|
else
|
||||||
ctx.reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == ctx.setup.set) {
|
if (id == ctx.setup.set) {
|
||||||
@ -153,18 +154,18 @@ QSet<WMTS::MatrixLimits> WMTS::tileMatrixSetLimits(QXmlStreamReader &reader)
|
|||||||
return limits;
|
return limits;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMTS::tileMatrixSetLink(CTX &ctx)
|
void WMTS::tileMatrixSetLink(QXmlStreamReader &reader, CTX &ctx)
|
||||||
{
|
{
|
||||||
QString id;
|
QString id;
|
||||||
QSet<MatrixLimits> limits;
|
QSet<MatrixLimits> limits;
|
||||||
|
|
||||||
while (ctx.reader.readNextStartElement()) {
|
while (reader.readNextStartElement()) {
|
||||||
if (ctx.reader.name() == "TileMatrixSet")
|
if (reader.name() == "TileMatrixSet")
|
||||||
id = ctx.reader.readElementText();
|
id = reader.readElementText();
|
||||||
else if (ctx.reader.name() == "TileMatrixSetLimits")
|
else if (reader.name() == "TileMatrixSetLimits")
|
||||||
limits = tileMatrixSetLimits(ctx.reader);
|
limits = tileMatrixSetLimits(reader);
|
||||||
else
|
else
|
||||||
ctx.reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == ctx.setup.set) {
|
if (id == ctx.setup.set) {
|
||||||
@ -205,30 +206,30 @@ QString WMTS::style(QXmlStreamReader &reader)
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMTS::layer(CTX &ctx)
|
void WMTS::layer(QXmlStreamReader &reader, CTX &ctx)
|
||||||
{
|
{
|
||||||
QString id, tpl;
|
QString id, tpl;
|
||||||
RectC bounds;
|
RectC bounds;
|
||||||
QStringList formats, styles;
|
QStringList formats, styles;
|
||||||
|
|
||||||
while (ctx.reader.readNextStartElement()) {
|
while (reader.readNextStartElement()) {
|
||||||
if (ctx.reader.name() == "Identifier")
|
if (reader.name() == "Identifier")
|
||||||
id = ctx.reader.readElementText();
|
id = reader.readElementText();
|
||||||
else if (ctx.reader.name() == "TileMatrixSetLink")
|
else if (reader.name() == "TileMatrixSetLink")
|
||||||
tileMatrixSetLink(ctx);
|
tileMatrixSetLink(reader, ctx);
|
||||||
else if (ctx.reader.name() == "WGS84BoundingBox")
|
else if (reader.name() == "WGS84BoundingBox")
|
||||||
bounds = wgs84BoundingBox(ctx.reader);
|
bounds = wgs84BoundingBox(reader);
|
||||||
else if (ctx.reader.name() == "ResourceURL") {
|
else if (reader.name() == "ResourceURL") {
|
||||||
const QXmlStreamAttributes &attr = ctx.reader.attributes();
|
const QXmlStreamAttributes &attr = reader.attributes();
|
||||||
if (attr.value("resourceType") == "tile")
|
if (attr.value("resourceType") == "tile")
|
||||||
tpl = attr.value("template").toString();
|
tpl = attr.value("template").toString();
|
||||||
ctx.reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
} else if (ctx.reader.name() == "Style")
|
} else if (reader.name() == "Style")
|
||||||
styles.append(style(ctx.reader));
|
styles.append(style(reader));
|
||||||
else if (ctx.reader.name() == "Format")
|
else if (reader.name() == "Format")
|
||||||
formats.append(ctx.reader.readElementText());
|
formats.append(reader.readElementText());
|
||||||
else
|
else
|
||||||
ctx.reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == ctx.setup.layer) {
|
if (id == ctx.setup.layer) {
|
||||||
@ -243,25 +244,25 @@ void WMTS::layer(CTX &ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMTS::contents(CTX &ctx)
|
void WMTS::contents(QXmlStreamReader &reader, CTX &ctx)
|
||||||
{
|
{
|
||||||
while (ctx.reader.readNextStartElement()) {
|
while (reader.readNextStartElement()) {
|
||||||
if (ctx.reader.name() == "TileMatrixSet")
|
if (reader.name() == "TileMatrixSet")
|
||||||
tileMatrixSet(ctx);
|
tileMatrixSet(reader, ctx);
|
||||||
else if (ctx.reader.name() == "Layer")
|
else if (reader.name() == "Layer")
|
||||||
layer(ctx);
|
layer(reader, ctx);
|
||||||
else
|
else
|
||||||
ctx.reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMTS::capabilities(CTX &ctx)
|
void WMTS::capabilities(QXmlStreamReader &reader, CTX &ctx)
|
||||||
{
|
{
|
||||||
while (ctx.reader.readNextStartElement()) {
|
while (reader.readNextStartElement()) {
|
||||||
if (ctx.reader.name() == "Contents")
|
if (reader.name() == "Contents")
|
||||||
contents(ctx);
|
contents(reader, ctx);
|
||||||
else
|
else
|
||||||
ctx.reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,22 +270,23 @@ bool WMTS::parseCapabilities(const QString &path, const Setup &setup)
|
|||||||
{
|
{
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
CTX ctx(setup);
|
CTX ctx(setup);
|
||||||
|
QXmlStreamReader reader;
|
||||||
|
|
||||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
_errorString = file.errorString();
|
_errorString = file.errorString();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.reader.setDevice(&file);
|
reader.setDevice(&file);
|
||||||
if (ctx.reader.readNextStartElement()) {
|
if (reader.readNextStartElement()) {
|
||||||
if (ctx.reader.name() == "Capabilities")
|
if (reader.name() == "Capabilities")
|
||||||
capabilities(ctx);
|
capabilities(reader, ctx);
|
||||||
else
|
else
|
||||||
ctx.reader.raiseError("Not a Capabilities XML file");
|
reader.raiseError("Not a Capabilities XML file");
|
||||||
}
|
}
|
||||||
if (ctx.reader.error()) {
|
if (reader.error()) {
|
||||||
_errorString = QString("%1:%2: %3").arg(path).arg(
|
_errorString = QString("%1:%2: %3").arg(path).arg(reader.lineNumber())
|
||||||
ctx.reader.lineNumber()).arg(ctx.reader.errorString());
|
.arg(reader.errorString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QXmlStreamReader>
|
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "projection.h"
|
#include "projection.h"
|
||||||
|
|
||||||
class Downloader;
|
class Downloader;
|
||||||
|
class QXmlStreamReader;
|
||||||
|
|
||||||
class WMTS
|
class WMTS
|
||||||
{
|
{
|
||||||
@ -89,8 +89,6 @@ private:
|
|||||||
|
|
||||||
struct CTX {
|
struct CTX {
|
||||||
const Setup &setup;
|
const Setup &setup;
|
||||||
QXmlStreamReader reader;
|
|
||||||
|
|
||||||
QString crs;
|
QString crs;
|
||||||
bool layer;
|
bool layer;
|
||||||
bool style;
|
bool style;
|
||||||
@ -106,11 +104,11 @@ private:
|
|||||||
TileMatrix tileMatrix(QXmlStreamReader &reader, bool yx);
|
TileMatrix tileMatrix(QXmlStreamReader &reader, bool yx);
|
||||||
QSet<MatrixLimits> tileMatrixSetLimits(QXmlStreamReader &reader);
|
QSet<MatrixLimits> tileMatrixSetLimits(QXmlStreamReader &reader);
|
||||||
QString style(QXmlStreamReader &reader);
|
QString style(QXmlStreamReader &reader);
|
||||||
void tileMatrixSet(CTX &ctx);
|
void tileMatrixSet(QXmlStreamReader &reader, CTX &ctx);
|
||||||
void tileMatrixSetLink(CTX &ctx);
|
void tileMatrixSetLink(QXmlStreamReader &reader, CTX &ctx);
|
||||||
void layer(CTX &ctx);
|
void layer(QXmlStreamReader &reader, CTX &ctx);
|
||||||
void contents(CTX &ctx);
|
void contents(QXmlStreamReader &reader, CTX &ctx);
|
||||||
void capabilities(CTX &ctx);
|
void capabilities(QXmlStreamReader &reader, CTX &ctx);
|
||||||
bool parseCapabilities(const QString &path, const Setup &setup);
|
bool parseCapabilities(const QString &path, const Setup &setup);
|
||||||
bool getCapabilities(const QString &url, const QString &file);
|
bool getCapabilities(const QString &url, const QString &file);
|
||||||
bool createProjection(const QString &crs);
|
bool createProjection(const QString &crs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user