Header includes cleanup
[GPXSee.git] / src / map / geotiffmap.cpp
blob89676c124ff27929aa43483382d06282a79f96cc
1 #include <QPainter>
2 #include <QImageReader>
3 #include "geotiff.h"
4 #include "image.h"
5 #include "geotiffmap.h"
8 GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent)
9 : Map(fileName, parent), _img(0), _ratio(1.0), _valid(false)
11 QImageReader ir(fileName);
12 if (!ir.canRead()) {
13 _errorString = "Unsupported/invalid image file";
14 return;
16 _size = ir.size();
18 GeoTIFF gt(fileName);
19 if (!gt.isValid()) {
20 _errorString = gt.errorString();
21 return;
22 } else {
23 _projection = gt.projection();
24 _transform = gt.transform();
27 _valid = true;
30 GeoTIFFMap::~GeoTIFFMap()
32 delete _img;
35 QPointF GeoTIFFMap::ll2xy(const Coordinates &c)
37 return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;
40 Coordinates GeoTIFFMap::xy2ll(const QPointF &p)
42 return _projection.xy2ll(_transform.img2proj(p * _ratio));
45 QRectF GeoTIFFMap::bounds()
47 return QRectF(QPointF(0, 0), _size / _ratio);
50 void GeoTIFFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
52 if (_img)
53 _img->draw(painter, rect, flags);
56 void GeoTIFFMap::load(const Projection &in, const Projection &out,
57 qreal deviceRatio, bool hidpi)
59 Q_UNUSED(in);
60 Q_UNUSED(out);
62 _ratio = hidpi ? deviceRatio : 1.0;
64 _img = new Image(path());
65 if (_img)
66 _img->setDevicePixelRatio(_ratio);
69 void GeoTIFFMap::unload()
71 delete _img;
72 _img = 0;
75 Map *GeoTIFFMap::create(const QString &path, const Projection &proj, bool *isDir)
77 Q_UNUSED(proj);
79 if (isDir)
80 *isDir = false;
82 return new GeoTIFFMap(path);