Code cleanup
[GPXSee.git] / src / map / geotiffmap.cpp
blobbc756eb60204d35c2667b7bceb9d8f470720f733
1 #include <QFileInfo>
2 #include <QPainter>
3 #include <QImageReader>
4 #include "config.h"
5 #include "geotiff.h"
6 #include "image.h"
7 #include "geotiffmap.h"
10 GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent)
11 : Map(parent), _fileName(fileName), _img(0), _ratio(1.0), _valid(false)
13 QImageReader ir(fileName);
14 if (!ir.canRead()) {
15 _errorString = "Unsupported/invalid image file";
16 return;
18 _size = ir.size();
20 GeoTIFF gt(fileName);
21 if (!gt.isValid()) {
22 _errorString = gt.errorString();
23 return;
24 } else {
25 _projection = gt.projection();
26 _transform = gt.transform();
29 _valid = true;
32 GeoTIFFMap::~GeoTIFFMap()
34 delete _img;
37 QString GeoTIFFMap::name() const
39 QFileInfo fi(_fileName);
40 return fi.fileName();
43 QPointF GeoTIFFMap::ll2xy(const Coordinates &c)
45 return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;
48 Coordinates GeoTIFFMap::xy2ll(const QPointF &p)
50 return _projection.xy2ll(_transform.img2proj(p * _ratio));
53 QRectF GeoTIFFMap::bounds()
55 return QRectF(QPointF(0, 0), _size / _ratio);
58 void GeoTIFFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
60 if (_img)
61 _img->draw(painter, rect, flags);
64 void GeoTIFFMap::setDevicePixelRatio(qreal ratio)
66 _ratio = ratio;
67 if (_img)
68 _img->setDevicePixelRatio(_ratio);
71 void GeoTIFFMap::load()
73 if (!_img)
74 _img = new Image(_fileName);
77 void GeoTIFFMap::unload()
79 delete _img;
80 _img = 0;