1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00
GPXSee/src/map/encmap.h

118 lines
2.7 KiB
C
Raw Normal View History

2022-11-04 09:03:36 +01:00
#ifndef ENCMAP_H
#define ENCMAP_H
#include <climits>
#include <QtConcurrent>
#include "common/range.h"
2022-11-04 09:03:36 +01:00
#include "map.h"
#include "projection.h"
#include "transform.h"
#include "ENC/mapdata.h"
#include "ENC/iso8211.h"
2022-11-04 09:03:36 +01:00
class ENCJob;
2022-11-04 09:03:36 +01:00
class ENCMap : public Map
{
Q_OBJECT
public:
ENCMap(const QString &fileName, QObject *parent = 0);
~ENCMap() {delete _data;}
2022-11-04 09:03:36 +01:00
QString name() const {return _name;}
2022-11-04 09:03:36 +01:00
QRectF bounds() {return _bounds;}
RectC llBounds() {return _llBounds;}
2022-11-04 09:03:36 +01:00
int zoom() const {return _zoom;}
void setZoom(int zoom);
int zoomFit(const QSize &size, const RectC &rect);
int zoomIn();
int zoomOut();
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
2022-11-04 09:03:36 +01:00
void unload();
QPointF ll2xy(const Coordinates &c)
{return _transform.proj2img(_projection.ll2xy(c));}
Coordinates xy2ll(const QPointF &p)
{return _projection.xy2ll(_transform.img2proj(p));}
void draw(QPainter *painter, const QRectF &rect, Flags flags);
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
2022-11-04 09:03:36 +01:00
static Map *create(const QString &path, const Projection &proj, bool *isMap);
2022-11-04 09:03:36 +01:00
private slots:
void jobFinished(ENCJob *job);
2022-11-04 09:03:36 +01:00
private:
class Rect {
public:
Rect()
: _minX(INT_MAX), _maxX(INT_MIN), _minY(INT_MAX), _maxY(INT_MIN) {}
Rect(int minX, int maxX, int minY, int maxY)
: _minX(minX), _maxX(maxX), _minY(minY), _maxY(maxY) {}
int minX() const {return _minX;}
int maxX() const {return _maxX;}
int minY() const {return _minY;}
int maxY() const {return _maxY;}
void unite(int x, int y) {
if (x < _minX)
_minX = x;
if (x > _maxX)
_maxX = x;
if (y < _minY)
_minY = y;
if (y > _maxY)
_maxY = y;
}
Rect &operator|=(const Rect &r) {*this = *this | r; return *this;}
Rect operator|(const Rect &r) const
{
return Rect(qMin(_minX, r._minX), qMax(_maxX, r._maxX),
qMin(_minY, r._minY), qMax(_maxY, r._maxY));
}
private:
int _minX, _maxX, _minY, _maxY;
};
2022-11-04 09:03:36 +01:00
Transform transform(int zoom) const;
void updateTransform();
bool isRunning(int zoom, const QPoint &xy) const;
void runJob(ENCJob *job);
void removeJob(ENCJob *job);
2022-11-09 21:37:05 +01:00
void cancelJobs(bool wait);
2022-11-04 09:03:36 +01:00
QString key(int zoom, const QPoint &xy) const;
static bool bounds(const ENC::ISO8211::Record &record, Rect &rect);
static bool bounds(const QVector<ENC::ISO8211::Record> &gv, Rect &b);
static bool processRecord(const ENC::ISO8211::Record &record,
QVector<ENC::ISO8211::Record> &rv, uint &COMF, QString &name);
QString _name;
ENC::MapData *_data;
2022-11-04 09:03:36 +01:00
Projection _projection;
Transform _transform;
qreal _tileRatio;
RectC _llBounds;
QRectF _bounds;
Range _zooms;
2022-11-04 09:03:36 +01:00
int _zoom;
QList<ENCJob*> _jobs;
2022-11-04 09:03:36 +01:00
bool _valid;
QString _errorString;
};
#endif // ENCMAP_H