1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2018-04-07 18:42:25 +02:00
parent c5256b25e9
commit c4915891e7
15 changed files with 76 additions and 52 deletions

View File

@ -33,3 +33,24 @@ CoordinateSystem::CoordinateSystem(int code)
break; break;
} }
} }
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const CoordinateSystem &cs)
{
QString ao;
switch (cs.axisOrder()) {
case CoordinateSystem::XY:
ao = "XY";
break;
case CoordinateSystem::YX:
ao = "YX";
break;
default:
ao = "Unknown";
}
dbg.nospace() << "CoordinateSystem(" << ao << ")";
return dbg.space();
}
#endif // QT_NO_DEBUG

View File

@ -1,12 +1,15 @@
#ifndef COORDINATESYSTEM_H #ifndef COORDINATESYSTEM_H
#define COORDINATESYSTEM_H #define COORDINATESYSTEM_H
#include <QDebug>
class CoordinateSystem class CoordinateSystem
{ {
public: public:
enum AxisOrder {Unknown, XY, YX}; enum AxisOrder {Unknown, XY, YX};
CoordinateSystem() : _axisOrder(Unknown) {} CoordinateSystem() : _axisOrder(Unknown) {}
CoordinateSystem(AxisOrder axisOrder) : _axisOrder(axisOrder) {}
CoordinateSystem(int code); CoordinateSystem(int code);
bool isValid() const {return (_axisOrder != Unknown);} bool isValid() const {return (_axisOrder != Unknown);}
@ -17,4 +20,8 @@ private:
AxisOrder _axisOrder; AxisOrder _axisOrder;
}; };
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const CoordinateSystem &cs);
#endif // QT_NO_DEBUG
#endif // COORDINATESYSTEM_H #endif // COORDINATESYSTEM_H

View File

@ -15,11 +15,10 @@
MapSource::Config::Config() : type(TMS), zooms(ZOOM_MIN, ZOOM_MAX), MapSource::Config::Config() : type(TMS), zooms(ZOOM_MIN, ZOOM_MAX),
bounds(Coordinates(BOUNDS_LEFT, BOUNDS_TOP), Coordinates(BOUNDS_RIGHT, bounds(Coordinates(BOUNDS_LEFT, BOUNDS_TOP), Coordinates(BOUNDS_RIGHT,
BOUNDS_BOTTOM)), format("image/png"), axisOrder(CoordinateSystem::Unknown), BOUNDS_BOTTOM)), format("image/png"), rest(false) {}
rest(false) {}
static CoordinateSystem::AxisOrder axisOrder(QXmlStreamReader &reader) static CoordinateSystem coordinateSystem(QXmlStreamReader &reader)
{ {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
if (attr.value("axis") == "yx") if (attr.value("axis") == "yx")
@ -142,7 +141,7 @@ void MapSource::map(QXmlStreamReader &reader, Config &config)
else if (reader.name() == "style") else if (reader.name() == "style")
config.style = reader.readElementText(); config.style = reader.readElementText();
else if (reader.name() == "set") { else if (reader.name() == "set") {
config.axisOrder = axisOrder(reader); config.coordinateSystem = coordinateSystem(reader);
config.set = reader.readElementText(); config.set = reader.readElementText();
} else if (reader.name() == "dimension") { } else if (reader.name() == "dimension") {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
@ -152,7 +151,7 @@ void MapSource::map(QXmlStreamReader &reader, Config &config)
config.dimensions.append(QPair<QString, QString>( config.dimensions.append(QPair<QString, QString>(
attr.value("id").toString(), reader.readElementText())); attr.value("id").toString(), reader.readElementText()));
} else if (reader.name() == "crs") { } else if (reader.name() == "crs") {
config.axisOrder = axisOrder(reader); config.coordinateSystem = coordinateSystem(reader);
config.crs = reader.readElementText(); config.crs = reader.readElementText();
} else if (reader.name() == "authorization") { } else if (reader.name() == "authorization") {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
@ -224,11 +223,11 @@ Map *MapSource::loadFile(const QString &path)
if (config.type == WMTS) if (config.type == WMTS)
m = new WMTSMap(config.name, WMTS::Setup(config.url, config.layer, m = new WMTSMap(config.name, WMTS::Setup(config.url, config.layer,
config.set, config.style, config.format, config.rest, config.axisOrder, config.set, config.style, config.format, config.rest,
config.dimensions, config.authorization)); config.coordinateSystem, config.dimensions, config.authorization));
else if (config.type == WMS) else if (config.type == WMS)
m = new WMSMap(config.name, WMS::Setup(config.url, config.layer, m = new WMSMap(config.name, WMS::Setup(config.url, config.layer,
config.style, config.format, config.crs, config.axisOrder, config.style, config.format, config.crs, config.coordinateSystem,
config.authorization)); config.authorization));
else else
m = new OnlineMap(config.name, config.url, config.zooms, config.bounds); m = new OnlineMap(config.name, config.url, config.zooms, config.bounds);

View File

@ -34,7 +34,7 @@ private:
QString set; QString set;
QString format; QString format;
QString crs; QString crs;
CoordinateSystem::AxisOrder axisOrder; CoordinateSystem coordinateSystem;
bool rest; bool rest;
QList<QPair<QString, QString> > dimensions; QList<QPair<QString, QString> > dimensions;
Authorization authorization; Authorization authorization;

View File

@ -29,7 +29,7 @@ Projection::Method::Method(int id)
} }
Projection::Projection(const PCS *pcs) : _gcs(pcs->gcs()), _units(pcs->units()), Projection::Projection(const PCS *pcs) : _gcs(pcs->gcs()), _units(pcs->units()),
_geographic(false) _cs(pcs->coordinateSystem()), _geographic(false)
{ {
const Ellipsoid *ellipsoid = _gcs->datum().ellipsoid(); const Ellipsoid *ellipsoid = _gcs->datum().ellipsoid();
const Projection::Setup &setup = pcs->setup(); const Projection::Setup &setup = pcs->setup();
@ -70,15 +70,12 @@ Projection::Projection(const PCS *pcs) : _gcs(pcs->gcs()), _units(pcs->units()),
default: default:
_ct = 0; _ct = 0;
} }
_axisOrder = pcs->coordinateSystem().axisOrder();
} }
Projection::Projection(const GCS *gcs, CoordinateSystem::AxisOrder axisOrder) Projection::Projection(const GCS *gcs, const CoordinateSystem &cs)
: _gcs(gcs), _axisOrder(axisOrder), _geographic(true) : _gcs(gcs), _units(LinearUnits(9001)), _cs(cs), _geographic(true)
{ {
_ct = new LatLon(gcs->angularUnits()); _ct = new LatLon(gcs->angularUnits());
_units = LinearUnits(9001);
} }
Projection::Projection(const Projection &p) Projection::Projection(const Projection &p)
@ -87,7 +84,7 @@ Projection::Projection(const Projection &p)
_units = p._units; _units = p._units;
_ct = p._ct ? p._ct->clone() : 0; _ct = p._ct ? p._ct->clone() : 0;
_geographic = p._geographic; _geographic = p._geographic;
_axisOrder = p._axisOrder; _cs = p._cs;
} }
Projection::~Projection() Projection::~Projection()
@ -101,7 +98,7 @@ Projection &Projection::operator=(const Projection &p)
_units = p._units; _units = p._units;
_ct = p._ct ? p._ct->clone() : 0; _ct = p._ct ? p._ct->clone() : 0;
_geographic = p._geographic; _geographic = p._geographic;
_axisOrder = p._axisOrder; _cs = p._cs;
return *this; return *this;
} }

View File

@ -73,8 +73,8 @@ public:
Projection() : _gcs(0), _ct(0), _geographic(false) {} Projection() : _gcs(0), _ct(0), _geographic(false) {}
Projection(const Projection &p); Projection(const Projection &p);
Projection(const PCS *pcs); Projection(const PCS *pcs);
Projection(const GCS *gcs, CoordinateSystem::AxisOrder axisOrder Projection(const GCS *gcs, const CoordinateSystem &cs
= CoordinateSystem::YX); = CoordinateSystem(CoordinateSystem::YX));
~Projection(); ~Projection();
Projection &operator=(const Projection &p); Projection &operator=(const Projection &p);
@ -87,13 +87,13 @@ public:
Coordinates xy2ll(const QPointF &p) const; Coordinates xy2ll(const QPointF &p) const;
const LinearUnits &units() const {return _units;} const LinearUnits &units() const {return _units;}
CoordinateSystem::AxisOrder axisOrder() const {return _axisOrder;} const CoordinateSystem &coordinateSystem() const {return _cs;}
private: private:
const GCS *_gcs; const GCS *_gcs;
const CT *_ct; const CT *_ct;
LinearUnits _units; LinearUnits _units;
CoordinateSystem::AxisOrder _axisOrder; CoordinateSystem _cs;
bool _geographic; bool _geographic;
}; };

View File

@ -64,7 +64,7 @@ void TileLoader::loadTilesSync(QList<Tile> &list)
if (t.pixmap().isNull()) { if (t.pixmap().isNull()) {
QString file = tileFile(t); QString file = tileFile(t);
if (QFileInfo(file).exists()) if (QFileInfo::exists(file))
loadTileFile(t, file); loadTileFile(t, file);
} }
} }

View File

@ -63,7 +63,7 @@ QString WMS::style(QXmlStreamReader &reader)
RectC WMS::geographicBoundingBox(QXmlStreamReader &reader) RectC WMS::geographicBoundingBox(QXmlStreamReader &reader)
{ {
qreal left, top, right, bottom; qreal left = NAN, top = NAN, right = NAN, bottom = NAN;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "westBoundLongitude") if (reader.name() == "westBoundLongitude")
@ -265,7 +265,7 @@ bool WMS::getCapabilities(const QString &url, const QString &file,
if (_downloader->get(dl, authorization)) if (_downloader->get(dl, authorization))
wait.exec(); wait.exec();
if (QFileInfo(file).exists()) if (QFileInfo::exists(file))
return true; return true;
else { else {
_errorString = "Error downloading capabilities XML file"; _errorString = "Error downloading capabilities XML file";
@ -278,7 +278,7 @@ WMS::WMS(const QString &file, const WMS::Setup &setup) : _valid(false)
QString capaUrl = QString("%1?service=WMS&request=GetCapabilities") QString capaUrl = QString("%1?service=WMS&request=GetCapabilities")
.arg(setup.url()); .arg(setup.url());
if (!QFileInfo(file).exists()) if (!QFileInfo::exists(file))
if (!getCapabilities(capaUrl, file, setup.authorization())) if (!getCapabilities(capaUrl, file, setup.authorization()))
return; return;
if (!parseCapabilities(file, setup)) if (!parseCapabilities(file, setup))

View File

@ -19,10 +19,10 @@ public:
public: public:
Setup(const QString &url, const QString &layer, const QString &style, Setup(const QString &url, const QString &layer, const QString &style,
const QString &format, const QString &crs, const QString &format, const QString &crs,
CoordinateSystem::AxisOrder axisOrder, const CoordinateSystem &cs, const Authorization &authorization
const Authorization &authorization = Authorization()) = Authorization())
: _url(url), _layer(layer), _style(style), _format(format), _crs(crs), : _url(url), _layer(layer), _style(style), _format(format),
_axisOrder(axisOrder), _authorization(authorization) {} _crs(crs), _cs(cs), _authorization(authorization) {}
const QString &url() const {return _url;} const QString &url() const {return _url;}
const Authorization &authorization() const {return _authorization;} const Authorization &authorization() const {return _authorization;}
@ -30,7 +30,7 @@ public:
const QString &style() const {return _style;} const QString &style() const {return _style;}
const QString &format() const {return _format;} const QString &format() const {return _format;}
const QString &crs() const {return _crs;} const QString &crs() const {return _crs;}
CoordinateSystem::AxisOrder axisOrder() const {return _axisOrder;} const CoordinateSystem &coordinateSystem() const {return _cs;}
private: private:
QString _url; QString _url;
@ -38,7 +38,7 @@ public:
QString _style; QString _style;
QString _format; QString _format;
QString _crs; QString _crs;
CoordinateSystem::AxisOrder _axisOrder; CoordinateSystem _cs;
Authorization _authorization; Authorization _authorization;
}; };

View File

@ -87,12 +87,12 @@ bool WMSMap::loadWMS()
_setup.authorization()); _setup.authorization());
if (wms.version() >= "1.3.0") { if (wms.version() >= "1.3.0") {
if (_setup.axisOrder() == CoordinateSystem::Unknown) if (_setup.coordinateSystem().axisOrder() == CoordinateSystem::Unknown)
_axisOrder = _projection.axisOrder(); _cs = _projection.coordinateSystem();
else else
_axisOrder = _setup.axisOrder(); _cs = _setup.coordinateSystem();
} else } else
_axisOrder = CoordinateSystem::XY; _cs = CoordinateSystem::XY;
computeZooms(wms.scaleDenominator()); computeZooms(wms.scaleDenominator());
updateTransform(); updateTransform();
@ -221,7 +221,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect)
j * TILE_SIZE))); j * TILE_SIZE)));
QPointF tbr(_transform.img2proj(QPointF(i * TILE_SIZE + TILE_SIZE QPointF tbr(_transform.img2proj(QPointF(i * TILE_SIZE + TILE_SIZE
- 1, j * TILE_SIZE + TILE_SIZE - 1))); - 1, j * TILE_SIZE + TILE_SIZE - 1)));
QRectF bbox = (_axisOrder == CoordinateSystem::YX) QRectF bbox = (_cs.axisOrder() == CoordinateSystem::YX)
? QRectF(QPointF(tbr.y(), tbr.x()), QPointF(ttl.y(), ttl.x())) ? QRectF(QPointF(tbr.y(), tbr.x()), QPointF(ttl.y(), ttl.x()))
: QRectF(ttl, tbr); : QRectF(ttl, tbr);

View File

@ -61,10 +61,10 @@ private:
TileLoader _tileLoader; TileLoader _tileLoader;
Projection _projection; Projection _projection;
Transform _transform; Transform _transform;
CoordinateSystem _cs;
QVector<qreal> _zooms; QVector<qreal> _zooms;
int _zoom;
QRectF _boundingBox; QRectF _boundingBox;
CoordinateSystem::AxisOrder _axisOrder; int _zoom;
bool _block; bool _block;
bool _valid; bool _valid;

View File

@ -291,7 +291,7 @@ bool WMTS::getCapabilities(const QString &url, const QString &file,
if (_downloader->get(dl, authorization)) if (_downloader->get(dl, authorization))
wait.exec(); wait.exec();
if (QFileInfo(file).exists()) if (QFileInfo::exists(file))
return true; return true;
else { else {
_errorString = "Error downloading capabilities XML file"; _errorString = "Error downloading capabilities XML file";
@ -305,7 +305,7 @@ WMTS::WMTS(const QString &file, const WMTS::Setup &setup) : _valid(false)
QString("%1?service=WMTS&Version=1.0.0&request=GetCapabilities") QString("%1?service=WMTS&Version=1.0.0&request=GetCapabilities")
.arg(setup.url()); .arg(setup.url());
if (!QFileInfo(file).exists()) if (!QFileInfo::exists(file))
if (!getCapabilities(capaUrl, file, setup.authorization())) if (!getCapabilities(capaUrl, file, setup.authorization()))
return; return;
if (!parseCapabilities(file, setup)) if (!parseCapabilities(file, setup))

View File

@ -21,12 +21,12 @@ public:
public: public:
Setup(const QString &url, const QString &layer, const QString &set, Setup(const QString &url, const QString &layer, const QString &set,
const QString &style, const QString &format, bool rest, const QString &style, const QString &format, bool rest,
CoordinateSystem::AxisOrder axisOrder, const CoordinateSystem &cs,
const QList<QPair<QString, QString> > &dimensions, const QList<QPair<QString, QString> > &dimensions,
const Authorization &authorization = Authorization()) : const Authorization &authorization = Authorization())
_url(url), _layer(layer), _set(set), _style(style), _format(format), : _url(url), _layer(layer), _set(set), _style(style),
_rest(rest), _axisOrder(axisOrder), _dimensions(dimensions), _format(format), _rest(rest), _cs(cs), _dimensions(dimensions),
_authorization(authorization) {} _authorization(authorization) {}
const QString &url() const {return _url;} const QString &url() const {return _url;}
const Authorization &authorization() const {return _authorization;} const Authorization &authorization() const {return _authorization;}
@ -35,7 +35,7 @@ public:
const QString &style() const {return _style;} const QString &style() const {return _style;}
const QString &format() const {return _format;} const QString &format() const {return _format;}
bool rest() const {return _rest;} bool rest() const {return _rest;}
CoordinateSystem::AxisOrder axisOrder() const {return _axisOrder;} const CoordinateSystem &coordinateSystem() const {return _cs;}
const QList<QPair<QString, QString> > &dimensions() const const QList<QPair<QString, QString> > &dimensions() const
{return _dimensions;} {return _dimensions;}
@ -46,7 +46,7 @@ public:
QString _style; QString _style;
QString _format; QString _format;
bool _rest; bool _rest;
CoordinateSystem::AxisOrder _axisOrder; CoordinateSystem _cs;
QList<QPair<QString, QString> > _dimensions; QList<QPair<QString, QString> > _dimensions;
Authorization _authorization; Authorization _authorization;
}; };

View File

@ -26,10 +26,10 @@ bool WMTSMap::loadWMTS()
_tileLoader = TileLoader(wmts.tileUrl(), tilesDir(), _tileLoader = TileLoader(wmts.tileUrl(), tilesDir(),
_setup.authorization()); _setup.authorization());
if (_setup.axisOrder() == CoordinateSystem::Unknown) if (_setup.coordinateSystem().axisOrder() == CoordinateSystem::Unknown)
_axisOrder = _projection.axisOrder(); _cs = _projection.coordinateSystem();
else else
_axisOrder = _setup.axisOrder(); _cs = _setup.coordinateSystem();
updateTransform(); updateTransform();
@ -72,7 +72,7 @@ void WMTSMap::updateTransform()
const WMTS::Zoom &z = _zooms.at(_zoom); const WMTS::Zoom &z = _zooms.at(_zoom);
ReferencePoint tl, br; ReferencePoint tl, br;
QPointF topLeft = (_axisOrder == CoordinateSystem::YX) QPointF topLeft = (_cs.axisOrder() == CoordinateSystem::YX)
? QPointF(z.topLeft().y(), z.topLeft().x()) : z.topLeft(); ? QPointF(z.topLeft().y(), z.topLeft().x()) : z.topLeft();
qreal pixelSpan = sd2res(z.scaleDenominator()); qreal pixelSpan = sd2res(z.scaleDenominator());

View File

@ -60,8 +60,8 @@ private:
QList<WMTS::Zoom> _zooms; QList<WMTS::Zoom> _zooms;
Projection _projection; Projection _projection;
Transform _transform; Transform _transform;
CoordinateSystem _cs;
int _zoom; int _zoom;
CoordinateSystem::AxisOrder _axisOrder;
bool _block; bool _block;
bool _valid; bool _valid;