Code cleanup
[GPXSee.git] / src / map / wmts.h
blob9e92caeb1f0fefd78a5597cbdda6bfb7f76d3ff7
1 #ifndef WMTS_H
2 #define WMTS_H
4 #include <QSize>
5 #include <QRect>
6 #include <QSet>
7 #include <QList>
8 #include <QHash>
9 #include "common/rectc.h"
10 #include "projection.h"
11 #include "downloader.h"
12 #include "coordinatesystem.h"
14 class QXmlStreamReader;
16 class WMTS
18 public:
19 class Setup
21 public:
22 Setup(const QString &url, const QString &layer, const QString &set,
23 const QString &style, const QString &format, bool rest,
24 const CoordinateSystem &cs,
25 const QList<QPair<QString, QString> > &dimensions,
26 const Authorization &authorization = Authorization())
27 : _url(url), _layer(layer), _set(set), _style(style),
28 _format(format), _rest(rest), _cs(cs), _dimensions(dimensions),
29 _authorization(authorization) {}
31 const QString &url() const {return _url;}
32 const Authorization &authorization() const {return _authorization;}
33 const QString &layer() const {return _layer;}
34 const QString &set() const {return _set;}
35 const QString &style() const {return _style;}
36 const QString &format() const {return _format;}
37 bool rest() const {return _rest;}
38 const CoordinateSystem &coordinateSystem() const {return _cs;}
39 const QList<QPair<QString, QString> > &dimensions() const
40 {return _dimensions;}
42 private:
43 QString _url;
44 QString _layer;
45 QString _set;
46 QString _style;
47 QString _format;
48 bool _rest;
49 CoordinateSystem _cs;
50 QList<QPair<QString, QString> > _dimensions;
51 Authorization _authorization;
54 class Zoom
56 public:
57 Zoom(const QString &id, double scaleDenominator, const PointD &topLeft,
58 const QSize &tile, const QSize &matrix, const QRect &limits) :
59 _id(id), _scaleDenominator(scaleDenominator), _topLeft(topLeft),
60 _tile(tile), _matrix(matrix), _limits(limits) {}
61 bool operator<(const Zoom &other) const
62 {return _scaleDenominator > other._scaleDenominator;}
64 const QString &id() const {return _id;}
65 double scaleDenominator() const {return _scaleDenominator;}
66 const PointD &topLeft() const {return _topLeft;}
67 const QSize &tile() const {return _tile;}
68 const QSize &matrix() const {return _matrix;}
69 const QRect &limits() const {return _limits;}
71 private:
72 QString _id;
73 double _scaleDenominator;
74 PointD _topLeft;
75 QSize _tile;
76 QSize _matrix;
77 QRect _limits;
81 WMTS(const QString &path, const Setup &setup);
83 const RectC &bounds() const {return _bounds;}
84 QList<Zoom> zooms() const;
85 const Projection &projection() const {return _projection;}
86 const QString &tileUrl() const {return _tileUrl;}
88 bool isValid() const {return _valid;}
89 const QString &errorString() const {return _errorString;}
91 private:
92 struct TileMatrix {
93 QString id;
94 double scaleDenominator;
95 PointD topLeft;
96 QSize tile;
97 QSize matrix;
99 TileMatrix() : scaleDenominator(0) {}
100 bool operator==(const TileMatrix &other) const
101 {return this->id == other.id;}
102 bool isValid() const
103 {return !id.isEmpty() && scaleDenominator > 0 && tile.isValid()
104 && matrix.isValid();}
107 struct MatrixLimits {
108 QString id;
109 QRect rect;
111 MatrixLimits() {}
112 MatrixLimits(const QString &id) : id(id) {}
113 bool operator==(const MatrixLimits &other) const
114 {return this->id == other.id;}
115 bool isValid() const
116 {return !id.isEmpty() && rect.isValid();}
119 struct CTX {
120 const Setup &setup;
121 QString crs;
122 bool hasLayer;
123 bool hasStyle;
124 bool hasFormat;
125 bool hasSet;
127 CTX(const Setup &setup) : setup(setup), hasLayer(false), hasStyle(false),
128 hasFormat(false), hasSet(false) {}
131 RectC wgs84BoundingBox(QXmlStreamReader &reader);
132 MatrixLimits tileMatrixLimits(QXmlStreamReader &reader);
133 TileMatrix tileMatrix(QXmlStreamReader &reader);
134 QSet<MatrixLimits> tileMatrixSetLimits(QXmlStreamReader &reader);
135 QString style(QXmlStreamReader &reader);
136 void tileMatrixSet(QXmlStreamReader &reader, CTX &ctx);
137 void tileMatrixSetLink(QXmlStreamReader &reader, CTX &ctx);
138 void layer(QXmlStreamReader &reader, CTX &ctx);
139 void contents(QXmlStreamReader &reader, CTX &ctx);
140 void capabilities(QXmlStreamReader &reader, CTX &ctx);
141 bool parseCapabilities(const QString &path, const Setup &setup);
142 bool downloadCapabilities(const QString &url, const QString &file,
143 const Authorization &authorization);
145 QSet<TileMatrix> _matrixes;
146 QSet<MatrixLimits> _limits;
147 RectC _bounds;
148 Projection _projection;
149 QString _tileUrl;
151 bool _valid;
152 QString _errorString;
154 friend uint qHash(const WMTS::TileMatrix &key);
155 friend uint qHash(const WMTS::MatrixLimits &key);
158 inline uint qHash(const WMTS::TileMatrix &key)
160 return ::qHash(key.id);
163 inline uint qHash(const WMTS::MatrixLimits &key)
165 return ::qHash(key.id);
168 #ifndef QT_NO_DEBUG
169 QDebug operator<<(QDebug dbg, const WMTS::Setup &setup);
170 QDebug operator<<(QDebug dbg, const WMTS::Zoom &zoom);
171 #endif // QT_NO_DEBUG
173 #endif // WMTS_H