Map API refactoring
[GPXSee.git] / src / map / gemfmap.h
blob9b82fe5e60402ca50b4f1f62374df1fb4267f847
1 #ifndef GEMFMAP_H
2 #define GEMFMAP_H
4 #include <QFile>
5 #include <QDebug>
6 #include "map.h"
8 class GEMFMap : public Map
10 public:
11 Q_OBJECT
13 public:
14 GEMFMap(const QString &fileName, QObject *parent = 0);
16 QRectF bounds();
17 RectC llBounds(const Projection &) {return _bounds;}
19 int zoom() const {return _zi;}
20 void setZoom(int zoom) {_zi = zoom;}
21 int zoomFit(const QSize &size, const RectC &rect);
22 int zoomIn();
23 int zoomOut();
24 qreal resolution(const QRectF &rect);
26 QPointF ll2xy(const Coordinates &c);
27 Coordinates xy2ll(const QPointF &p);
29 void load(const Projection &in, const Projection &out, qreal deviceRatio,
30 bool hidpi);
31 void unload();
33 void draw(QPainter *painter, const QRectF &rect, Flags flags);
35 bool isValid() const {return _valid;}
36 QString errorString() const {return _errorString;}
38 static Map *create(const QString &path, bool *isDir);
40 private:
41 struct Region {
42 quint32 minX;
43 quint32 maxX;
44 quint32 minY;
45 quint32 maxY;
46 quint64 offset;
49 struct Zoom {
50 int level;
51 QList<Region> ranges;
53 Zoom(int level) : level(level) {}
55 bool operator==(const Zoom &other) const
56 {return level == other.level;}
57 bool operator<(const Zoom &other) const
58 {return level < other.level;}
61 QRect rect(const Zoom &zoom) const;
62 bool readHeader(QDataStream &stream);
63 bool readRegions(QDataStream &stream);
64 bool computeBounds();
65 qreal tileSize() const;
66 QByteArray tileData(const QPoint &tile);
67 void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
69 friend QDebug operator<<(QDebug dbg, const Region &region);
70 friend QDebug operator<<(QDebug dbg, const Zoom &zoom);
72 QFile _file;
73 int _zi;
74 RectC _bounds;
75 qreal _mapRatio;
76 int _tileSize;
77 QList<Zoom> _zooms;
79 bool _valid;
80 QString _errorString;
83 #ifndef QT_NO_DEBUG
84 QDebug operator<<(QDebug dbg, const GEMFMap::Region &region);
85 QDebug operator<<(QDebug dbg, const GEMFMap::Zoom &zoom);
86 #endif // QT_NO_DEBUG
88 #endif // GEMFMAP_H