Improve/fix GCS search
[GPXSee.git] / src / map / encmap.h
blobb257d10ef8cf503738b05995fa2b035cce200121
1 #ifndef ENCMAP_H
2 #define ENCMAP_H
4 #include <climits>
5 #include <QtConcurrent>
6 #include "common/range.h"
7 #include "map.h"
8 #include "projection.h"
9 #include "transform.h"
10 #include "ENC/iso8211.h"
11 #include "ENC/mapdata.h"
12 #include "ENC/style.h"
14 class ENCJob;
16 class ENCMap : public Map
18 Q_OBJECT
20 public:
21 ENCMap(const QString &fileName, QObject *parent = 0);
22 ~ENCMap();
24 QString name() const {return _name;}
26 QRectF bounds() {return _bounds;}
27 RectC llBounds() {return _llBounds;}
29 int zoom() const {return _zoom;}
30 void setZoom(int zoom);
31 int zoomFit(const QSize &size, const RectC &rect);
32 int zoomIn();
33 int zoomOut();
35 void load(const Projection &in, const Projection &out, qreal deviceRatio,
36 bool hidpi);
37 void unload();
39 QPointF ll2xy(const Coordinates &c)
40 {return _transform.proj2img(_projection.ll2xy(c));}
41 Coordinates xy2ll(const QPointF &p)
42 {return _projection.xy2ll(_transform.img2proj(p));}
44 void draw(QPainter *painter, const QRectF &rect, Flags flags);
46 bool isValid() const {return _valid;}
47 QString errorString() const {return _errorString;}
49 static Map *create(const QString &path, const Projection &proj, bool *isMap);
51 private slots:
52 void jobFinished(ENCJob *job);
54 private:
55 class Rect {
56 public:
57 Rect()
58 : _minX(INT_MAX), _maxX(INT_MIN), _minY(INT_MAX), _maxY(INT_MIN) {}
59 Rect(int minX, int maxX, int minY, int maxY)
60 : _minX(minX), _maxX(maxX), _minY(minY), _maxY(maxY) {}
62 int minX() const {return _minX;}
63 int maxX() const {return _maxX;}
64 int minY() const {return _minY;}
65 int maxY() const {return _maxY;}
67 void unite(int x, int y) {
68 if (x < _minX)
69 _minX = x;
70 if (x > _maxX)
71 _maxX = x;
72 if (y < _minY)
73 _minY = y;
74 if (y > _maxY)
75 _maxY = y;
78 Rect &operator|=(const Rect &r) {*this = *this | r; return *this;}
79 Rect operator|(const Rect &r) const
81 return Rect(qMin(_minX, r._minX), qMax(_maxX, r._maxX),
82 qMin(_minY, r._minY), qMax(_maxY, r._maxY));
85 private:
86 int _minX, _maxX, _minY, _maxY;
89 Transform transform(int zoom) const;
90 void updateTransform();
91 bool isRunning(int zoom, const QPoint &xy) const;
92 void runJob(ENCJob *job);
93 void removeJob(ENCJob *job);
94 void cancelJobs(bool wait);
95 QString key(int zoom, const QPoint &xy) const;
97 static bool bounds(const ENC::ISO8211::Record &record, Rect &rect);
98 static bool bounds(const QVector<ENC::ISO8211::Record> &gv, Rect &b);
99 static bool processRecord(const ENC::ISO8211::Record &record,
100 QVector<ENC::ISO8211::Record> &rv, uint &COMF, QString &name);
102 QString _name;
103 ENC::MapData *_data;
104 ENC::Style *_style;
105 Projection _projection;
106 Transform _transform;
107 qreal _tileRatio;
108 RectC _llBounds;
109 QRectF _bounds;
110 Range _zooms;
111 int _zoom;
113 QList<ENCJob*> _jobs;
115 bool _valid;
116 QString _errorString;
119 #endif // ENCMAP_H