mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Code/API cleanup
This commit is contained in:
parent
27886ea96a
commit
1f71b3a3b2
@ -140,7 +140,8 @@ HEADERS += src/config.h \
|
|||||||
src/GUI/kv.h \
|
src/GUI/kv.h \
|
||||||
src/data/locparser.h \
|
src/data/locparser.h \
|
||||||
src/data/slfparser.h \
|
src/data/slfparser.h \
|
||||||
src/map/geotiffmap.h
|
src/map/geotiffmap.h \
|
||||||
|
src/map/image.h
|
||||||
SOURCES += src/main.cpp \
|
SOURCES += src/main.cpp \
|
||||||
src/common/coordinates.cpp \
|
src/common/coordinates.cpp \
|
||||||
src/common/rectc.cpp \
|
src/common/rectc.cpp \
|
||||||
@ -244,7 +245,8 @@ SOURCES += src/main.cpp \
|
|||||||
src/map/map.cpp \
|
src/map/map.cpp \
|
||||||
src/data/locparser.cpp \
|
src/data/locparser.cpp \
|
||||||
src/data/slfparser.cpp \
|
src/data/slfparser.cpp \
|
||||||
src/map/geotiffmap.cpp
|
src/map/geotiffmap.cpp \
|
||||||
|
src/map/image.cpp
|
||||||
|
|
||||||
RESOURCES += gpxsee.qrc
|
RESOURCES += gpxsee.qrc
|
||||||
TRANSLATIONS = lang/gpxsee_cs.ts \
|
TRANSLATIONS = lang/gpxsee_cs.ts \
|
||||||
|
@ -27,7 +27,6 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
|
|||||||
Q_ASSERT(map != 0);
|
Q_ASSERT(map != 0);
|
||||||
Q_ASSERT(poi != 0);
|
Q_ASSERT(poi != 0);
|
||||||
|
|
||||||
_opengl = false;
|
|
||||||
_scene = new QGraphicsScene(this);
|
_scene = new QGraphicsScene(this);
|
||||||
setScene(_scene);
|
setScene(_scene);
|
||||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||||
@ -42,11 +41,11 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
|
|||||||
_scene->addItem(_mapScale);
|
_scene->addItem(_mapScale);
|
||||||
|
|
||||||
_map = map;
|
_map = map;
|
||||||
|
_map->load();
|
||||||
#ifdef ENABLE_HIDPI
|
#ifdef ENABLE_HIDPI
|
||||||
_ratio = devicePixelRatioF();
|
_ratio = devicePixelRatioF();
|
||||||
_map->setDevicePixelRatio(_ratio);
|
_map->setDevicePixelRatio(_ratio);
|
||||||
#endif // ENABLE_HIDPI
|
#endif // ENABLE_HIDPI
|
||||||
_map->load();
|
|
||||||
connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
||||||
|
|
||||||
_poi = poi;
|
_poi = poi;
|
||||||
@ -76,6 +75,7 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
|
|||||||
_poiSize = 8;
|
_poiSize = 8;
|
||||||
_poiColor = Qt::black;
|
_poiColor = Qt::black;
|
||||||
|
|
||||||
|
_opengl = false;
|
||||||
_plot = false;
|
_plot = false;
|
||||||
_digitalZoom = 0;
|
_digitalZoom = 0;
|
||||||
|
|
||||||
@ -269,11 +269,10 @@ void MapView::setMap(Map *map)
|
|||||||
disconnect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
disconnect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
||||||
|
|
||||||
_map = map;
|
_map = map;
|
||||||
|
_map->load();
|
||||||
#ifdef ENABLE_HIDPI
|
#ifdef ENABLE_HIDPI
|
||||||
_map->setDevicePixelRatio(_ratio);
|
_map->setDevicePixelRatio(_ratio);
|
||||||
#endif // ENABLE_HIDPI
|
#endif // ENABLE_HIDPI
|
||||||
_map->setOpenGLEnabled(_opengl);
|
|
||||||
_map->load();
|
|
||||||
connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
|
||||||
|
|
||||||
digitalZoom(0);
|
digitalZoom(0);
|
||||||
@ -509,7 +508,6 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
|
|||||||
#ifdef ENABLE_HIDPI
|
#ifdef ENABLE_HIDPI
|
||||||
_map->setDevicePixelRatio(1.0);
|
_map->setDevicePixelRatio(1.0);
|
||||||
#endif // ENABLE_HIDPI
|
#endif // ENABLE_HIDPI
|
||||||
_map->setOpenGLEnabled(false);
|
|
||||||
|
|
||||||
// Compute sizes & ratios
|
// Compute sizes & ratios
|
||||||
orig = viewport()->rect();
|
orig = viewport()->rect();
|
||||||
@ -571,7 +569,6 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
|
|||||||
#ifdef ENABLE_HIDPI
|
#ifdef ENABLE_HIDPI
|
||||||
_map->setDevicePixelRatio(_ratio);
|
_map->setDevicePixelRatio(_ratio);
|
||||||
#endif // ENABLE_HIDPI
|
#endif // ENABLE_HIDPI
|
||||||
_map->setOpenGLEnabled(_opengl);
|
|
||||||
_plot = false;
|
_plot = false;
|
||||||
setUpdatesEnabled(true);
|
setUpdatesEnabled(true);
|
||||||
}
|
}
|
||||||
@ -769,9 +766,17 @@ void MapView::drawBackground(QPainter *painter, const QRectF &rect)
|
|||||||
|
|
||||||
if (_showMap) {
|
if (_showMap) {
|
||||||
QRectF ir = rect.intersected(_map->bounds());
|
QRectF ir = rect.intersected(_map->bounds());
|
||||||
|
Map::Flags flags = Map::NoFlags;
|
||||||
|
|
||||||
if (_opacity < 1.0)
|
if (_opacity < 1.0)
|
||||||
painter->setOpacity(_opacity);
|
painter->setOpacity(_opacity);
|
||||||
_map->draw(painter, ir, _plot);
|
|
||||||
|
if (_plot)
|
||||||
|
flags = Map::Block;
|
||||||
|
else if (_opengl)
|
||||||
|
flags = Map::OpenGL;
|
||||||
|
|
||||||
|
_map->draw(painter, ir, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -818,8 +823,6 @@ void MapView::useOpenGL(bool use)
|
|||||||
setViewport(new OPENGL_WIDGET);
|
setViewport(new OPENGL_WIDGET);
|
||||||
else
|
else
|
||||||
setViewport(new QWidget);
|
setViewport(new QWidget);
|
||||||
|
|
||||||
_map->setOpenGLEnabled(_opengl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapView::useAntiAliasing(bool use)
|
void MapView::useAntiAliasing(bool use)
|
||||||
|
@ -255,14 +255,12 @@ Coordinates Atlas::xy2ll(const QPointF &p)
|
|||||||
return _maps.at(idx)->xy2ll(p2);
|
return _maps.at(idx)->xy2ll(p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Atlas::draw(QPainter *painter, const QRectF &rect, bool block)
|
void Atlas::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
Q_UNUSED(block);
|
|
||||||
|
|
||||||
// All in one map
|
// All in one map
|
||||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).last; i++) {
|
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).last; i++) {
|
||||||
if (_bounds.at(i).xy.contains(rect)) {
|
if (_bounds.at(i).xy.contains(rect)) {
|
||||||
draw(painter, rect, i);
|
draw(painter, rect, i, flags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,11 +269,12 @@ void Atlas::draw(QPainter *painter, const QRectF &rect, bool block)
|
|||||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).last; i++) {
|
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).last; i++) {
|
||||||
QRectF ir = rect.intersected(_bounds.at(i).xy);
|
QRectF ir = rect.intersected(_bounds.at(i).xy);
|
||||||
if (!ir.isNull())
|
if (!ir.isNull())
|
||||||
draw(painter, ir, i);
|
draw(painter, ir, i, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Atlas::draw(QPainter *painter, const QRectF &rect, int mapIndex)
|
void Atlas::draw(QPainter *painter, const QRectF &rect, int mapIndex,
|
||||||
|
Flags flags)
|
||||||
{
|
{
|
||||||
OziMap *map = _maps.at(mapIndex);
|
OziMap *map = _maps.at(mapIndex);
|
||||||
const QPointF offset = _bounds.at(mapIndex).xy.topLeft();
|
const QPointF offset = _bounds.at(mapIndex).xy.topLeft();
|
||||||
@ -284,7 +283,7 @@ void Atlas::draw(QPainter *painter, const QRectF &rect, int mapIndex)
|
|||||||
map->load();
|
map->load();
|
||||||
|
|
||||||
painter->translate(offset);
|
painter->translate(offset);
|
||||||
map->draw(painter, pr, true);
|
map->draw(painter, pr, flags);
|
||||||
painter->translate(-offset);
|
painter->translate(-offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
QPointF ll2xy(const Coordinates &c);
|
QPointF ll2xy(const Coordinates &c);
|
||||||
Coordinates xy2ll(const QPointF &p);
|
Coordinates xy2ll(const QPointF &p);
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||||
|
|
||||||
void setDevicePixelRatio(qreal ratio);
|
void setDevicePixelRatio(qreal ratio);
|
||||||
void unload();
|
void unload();
|
||||||
@ -53,7 +53,7 @@ private:
|
|||||||
Bounds(const RectD &pp, const QRectF &xy) : pp(pp), xy(xy) {}
|
Bounds(const RectD &pp, const QRectF &xy) : pp(pp), xy(xy) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRectF &rect, int mapIndex);
|
void draw(QPainter *painter, const QRectF &rect, int mapIndex, Flags flags);
|
||||||
void computeZooms();
|
void computeZooms();
|
||||||
void computeBounds();
|
void computeBounds();
|
||||||
|
|
||||||
|
@ -85,11 +85,11 @@ int EmptyMap::zoomOut()
|
|||||||
return _zoom;
|
return _zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmptyMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
void EmptyMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
Q_UNUSED(painter);
|
Q_UNUSED(painter);
|
||||||
Q_UNUSED(rect);
|
Q_UNUSED(rect);
|
||||||
Q_UNUSED(block);
|
Q_UNUSED(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF EmptyMap::ll2xy(const Coordinates &c)
|
QPointF EmptyMap::ll2xy(const Coordinates &c)
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
QPointF ll2xy(const Coordinates &c);
|
QPointF ll2xy(const Coordinates &c);
|
||||||
Coordinates xy2ll(const QPointF &p);
|
Coordinates xy2ll(const QPointF &p);
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _zoom;
|
int _zoom;
|
||||||
|
@ -3,29 +3,29 @@
|
|||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "geotiff.h"
|
#include "geotiff.h"
|
||||||
|
#include "image.h"
|
||||||
#include "geotiffmap.h"
|
#include "geotiffmap.h"
|
||||||
|
|
||||||
|
|
||||||
GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent)
|
GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent)
|
||||||
: Map(parent), _img(0), _ratio(1.0), _opengl(false), _valid(false)
|
: Map(parent), _fileName(fileName), _img(0), _ratio(1.0), _valid(false)
|
||||||
{
|
{
|
||||||
|
QImageReader ir(fileName);
|
||||||
|
if (!ir.canRead()) {
|
||||||
|
_errorString = "Unsupported/invalid image file";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_size = ir.size();
|
||||||
|
|
||||||
GeoTIFF gt(fileName);
|
GeoTIFF gt(fileName);
|
||||||
if (!gt.isValid()) {
|
if (!gt.isValid()) {
|
||||||
_errorString = gt.errorString();
|
_errorString = gt.errorString();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
_path = fileName;
|
|
||||||
_projection = gt.projection();
|
_projection = gt.projection();
|
||||||
_transform = gt.transform();
|
_transform = gt.transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
QImageReader img(_path);
|
|
||||||
_size = img.size();
|
|
||||||
if (!_size.isValid()) {
|
|
||||||
_errorString = QString("%1: Invalid image file").arg(_path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_valid = true;
|
_valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,30 +36,10 @@ GeoTIFFMap::~GeoTIFFMap()
|
|||||||
|
|
||||||
QString GeoTIFFMap::name() const
|
QString GeoTIFFMap::name() const
|
||||||
{
|
{
|
||||||
QFileInfo fi(_path);
|
QFileInfo fi(_fileName);
|
||||||
return fi.fileName();
|
return fi.fileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeoTIFFMap::load()
|
|
||||||
{
|
|
||||||
if (!_img) {
|
|
||||||
_img = new QImage(_path);
|
|
||||||
if (!_img || _img->isNull()) {
|
|
||||||
qWarning("%s: error loading map image", qPrintable(_path));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#ifdef ENABLE_HIDPI
|
|
||||||
_img->setDevicePixelRatio(_ratio);
|
|
||||||
#endif // ENABLE_HIDPI
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeoTIFFMap::unload()
|
|
||||||
{
|
|
||||||
delete _img;
|
|
||||||
_img = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF GeoTIFFMap::ll2xy(const Coordinates &c)
|
QPointF GeoTIFFMap::ll2xy(const Coordinates &c)
|
||||||
{
|
{
|
||||||
return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;
|
return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;
|
||||||
@ -75,16 +55,27 @@ QRectF GeoTIFFMap::bounds()
|
|||||||
return QRectF(QPointF(0, 0), _size / _ratio);
|
return QRectF(QPointF(0, 0), _size / _ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeoTIFFMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
void GeoTIFFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
Q_UNUSED(block)
|
if (_img)
|
||||||
|
_img->draw(painter, rect, flags);
|
||||||
if (_img && !_img->isNull()) {
|
}
|
||||||
QRectF sr(rect.topLeft() * _ratio, rect.size() * _ratio);
|
|
||||||
if (_opengl) {
|
void GeoTIFFMap::setDevicePixelRatio(qreal ratio)
|
||||||
QImage img(_img->copy(sr.toRect()));
|
{
|
||||||
painter->drawImage(rect.topLeft(), img);
|
_ratio = ratio;
|
||||||
} else
|
if (_img)
|
||||||
painter->drawImage(rect.topLeft(), *_img, sr);
|
_img->setDevicePixelRatio(_ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeoTIFFMap::load()
|
||||||
|
{
|
||||||
|
if (!_img)
|
||||||
|
_img = new Image(_fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeoTIFFMap::unload()
|
||||||
|
{
|
||||||
|
delete _img;
|
||||||
|
_img = 0;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include "projection.h"
|
#include "projection.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
|
class Image;
|
||||||
|
|
||||||
class GeoTIFFMap : public Map
|
class GeoTIFFMap : public Map
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -26,24 +28,22 @@ public:
|
|||||||
QPointF ll2xy(const Coordinates &c);
|
QPointF ll2xy(const Coordinates &c);
|
||||||
Coordinates xy2ll(const QPointF &p);
|
Coordinates xy2ll(const QPointF &p);
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||||
|
|
||||||
void setDevicePixelRatio(qreal ratio) {_ratio = ratio;}
|
|
||||||
void setOpenGLEnabled(bool enabled) {_opengl = enabled;}
|
|
||||||
void load();
|
void load();
|
||||||
void unload();
|
void unload();
|
||||||
|
void setDevicePixelRatio(qreal ratio);
|
||||||
|
|
||||||
bool isValid() const {return _valid;}
|
bool isValid() const {return _valid;}
|
||||||
QString errorString() const {return _errorString;}
|
QString errorString() const {return _errorString;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _path;
|
QString _fileName;
|
||||||
Projection _projection;
|
Projection _projection;
|
||||||
Transform _transform;
|
Transform _transform;
|
||||||
QImage *_img;
|
Image *_img;
|
||||||
QSize _size;
|
QSize _size;
|
||||||
qreal _ratio;
|
qreal _ratio;
|
||||||
bool _opengl;
|
|
||||||
|
|
||||||
bool _valid;
|
bool _valid;
|
||||||
QString _errorString;
|
QString _errorString;
|
||||||
|
29
src/map/image.cpp
Normal file
29
src/map/image.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <QPainter>
|
||||||
|
#include "config.h"
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define TILE_SIZE 256
|
||||||
|
|
||||||
|
Image::Image(const QString &fileName) : _img(fileName), _ratio(1.0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Image::draw(QPainter *painter, const QRectF &rect, Map::Flags flags)
|
||||||
|
{
|
||||||
|
QRectF sr(rect.topLeft() * _ratio, rect.size() * _ratio);
|
||||||
|
|
||||||
|
if (flags & Map::OpenGL) {
|
||||||
|
QImage img(_img.copy(sr.toRect()));
|
||||||
|
painter->drawImage(rect.topLeft(), img);
|
||||||
|
} else
|
||||||
|
painter->drawImage(rect.topLeft(), _img, sr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Image::setDevicePixelRatio(qreal ratio)
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_HIDPI
|
||||||
|
_ratio = ratio;
|
||||||
|
_img.setDevicePixelRatio(_ratio);
|
||||||
|
#endif // ENABLE_HIDPI
|
||||||
|
}
|
23
src/map/image.h
Normal file
23
src/map/image.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef IMAGE_H
|
||||||
|
#define IMAGE_H
|
||||||
|
|
||||||
|
#include <QImage>
|
||||||
|
#include "map.h"
|
||||||
|
|
||||||
|
class QPainter;
|
||||||
|
|
||||||
|
class Image
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Image(const QString &fileName);
|
||||||
|
|
||||||
|
QSize size() const {return _img.size();}
|
||||||
|
void draw(QPainter *painter, const QRectF &rect, Map::Flags flags);
|
||||||
|
void setDevicePixelRatio(qreal ratio);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QImage _img;
|
||||||
|
qreal _ratio;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // IMAGE_H
|
@ -245,9 +245,9 @@ bool JNXMap::cb(Tile *tile, void *context)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JNXMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
void JNXMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
Q_UNUSED(block);
|
Q_UNUSED(flags);
|
||||||
const RTree<Tile*, qreal, 2> &tree = _zooms.at(_zoom).tree;
|
const RTree<Tile*, qreal, 2> &tree = _zooms.at(_zoom).tree;
|
||||||
Ctx ctx(painter, &_file, _ratio);
|
Ctx ctx(painter, &_file, _ratio);
|
||||||
QRectF rr(rect.topLeft() * _ratio, rect.size() * _ratio);
|
QRectF rr(rect.topLeft() * _ratio, rect.size() * _ratio);
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
QPointF ll2xy(const Coordinates &c);
|
QPointF ll2xy(const Coordinates &c);
|
||||||
Coordinates xy2ll(const QPointF &p);
|
Coordinates xy2ll(const QPointF &p);
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||||
|
|
||||||
void setDevicePixelRatio(qreal ratio) {_ratio = ratio;}
|
void setDevicePixelRatio(qreal ratio) {_ratio = ratio;}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
|
#include <QFlags>
|
||||||
#include "common/coordinates.h"
|
#include "common/coordinates.h"
|
||||||
|
|
||||||
class QPainter;
|
class QPainter;
|
||||||
@ -14,6 +15,13 @@ class Map : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum Flag {
|
||||||
|
NoFlags = 0,
|
||||||
|
Block = 1,
|
||||||
|
OpenGL = 2
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(Flags, Flag)
|
||||||
|
|
||||||
Map(QObject *parent = 0) : QObject(parent) {}
|
Map(QObject *parent = 0) : QObject(parent) {}
|
||||||
virtual ~Map() {}
|
virtual ~Map() {}
|
||||||
|
|
||||||
@ -31,13 +39,12 @@ public:
|
|||||||
virtual QPointF ll2xy(const Coordinates &c) = 0;
|
virtual QPointF ll2xy(const Coordinates &c) = 0;
|
||||||
virtual Coordinates xy2ll(const QPointF &p) = 0;
|
virtual Coordinates xy2ll(const QPointF &p) = 0;
|
||||||
|
|
||||||
virtual void draw(QPainter *painter, const QRectF &rect, bool block) = 0;
|
virtual void draw(QPainter *painter, const QRectF &rect, Flags flags) = 0;
|
||||||
|
|
||||||
virtual void clearCache() {}
|
virtual void clearCache() {}
|
||||||
virtual void load() {}
|
virtual void load() {}
|
||||||
virtual void unload() {}
|
virtual void unload() {}
|
||||||
virtual void setDevicePixelRatio(qreal ratio) {Q_UNUSED(ratio);}
|
virtual void setDevicePixelRatio(qreal ratio) {Q_UNUSED(ratio);}
|
||||||
virtual void setOpenGLEnabled(bool enabled) {Q_UNUSED(enabled);}
|
|
||||||
|
|
||||||
virtual bool isValid() const {return true;}
|
virtual bool isValid() const {return true;}
|
||||||
virtual QString errorString() const {return QString();}
|
virtual QString errorString() const {return QString();}
|
||||||
@ -46,4 +53,6 @@ signals:
|
|||||||
void loaded();
|
void loaded();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Map::Flags)
|
||||||
|
|
||||||
#endif // MAP_H
|
#endif // MAP_H
|
||||||
|
@ -126,7 +126,7 @@ qreal OnlineMap::tileSize() const
|
|||||||
return (TILE_SIZE / coordinatesRatio());
|
return (TILE_SIZE / coordinatesRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnlineMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
qreal scale = zoom2scale(_zoom);
|
qreal scale = zoom2scale(_zoom);
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
|||||||
for (int j = 0; j < ceil(s.height() / tileSize()); j++)
|
for (int j = 0; j < ceil(s.height() / tileSize()); j++)
|
||||||
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
|
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
|
||||||
|
|
||||||
if (block)
|
if (flags & Map::Block)
|
||||||
_tileLoader->loadTilesSync(tiles);
|
_tileLoader->loadTilesSync(tiles);
|
||||||
else
|
else
|
||||||
_tileLoader->loadTilesAsync(tiles);
|
_tileLoader->loadTilesAsync(tiles);
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
QPointF ll2xy(const Coordinates &c);
|
QPointF ll2xy(const Coordinates &c);
|
||||||
Coordinates xy2ll(const QPointF &p);
|
Coordinates xy2ll(const QPointF &p);
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||||
|
|
||||||
void setDevicePixelRatio(qreal ratio) {_deviceRatio = ratio;}
|
void setDevicePixelRatio(qreal ratio) {_deviceRatio = ratio;}
|
||||||
void clearCache() {_tileLoader->clearCache();}
|
void clearCache() {_tileLoader->clearCache();}
|
||||||
|
@ -3,21 +3,20 @@
|
|||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QImage>
|
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include "common/coordinates.h"
|
#include "common/coordinates.h"
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "tar.h"
|
#include "tar.h"
|
||||||
#include "ozf.h"
|
#include "ozf.h"
|
||||||
|
#include "image.h"
|
||||||
#include "mapfile.h"
|
#include "mapfile.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ozimap.h"
|
#include "ozimap.h"
|
||||||
|
|
||||||
|
|
||||||
OziMap::OziMap(const QString &fileName, QObject *parent)
|
OziMap::OziMap(const QString &fileName, QObject *parent)
|
||||||
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0),
|
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0), _valid(false)
|
||||||
_opengl(false), _valid(false)
|
|
||||||
{
|
{
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
QString suffix = fi.suffix().toLower();
|
QString suffix = fi.suffix().toLower();
|
||||||
@ -79,8 +78,7 @@ OziMap::OziMap(const QString &fileName, QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
OziMap::OziMap(const QString &fileName, Tar &tar, QObject *parent)
|
OziMap::OziMap(const QString &fileName, Tar &tar, QObject *parent)
|
||||||
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0),
|
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0), _valid(false)
|
||||||
_opengl(false), _valid(false)
|
|
||||||
{
|
{
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
QFileInfo map(fi.absolutePath());
|
QFileInfo map(fi.absolutePath());
|
||||||
@ -140,20 +138,19 @@ bool OziMap::setImageInfo(const QString &path)
|
|||||||
|
|
||||||
if (OZF::isOZF(_map.path)) {
|
if (OZF::isOZF(_map.path)) {
|
||||||
_ozf = new OZF(_map.path);
|
_ozf = new OZF(_map.path);
|
||||||
if (!_ozf->open()) {
|
if (!_ozf || !_ozf->open()) {
|
||||||
_errorString = QString("%1: Error loading OZF file")
|
_errorString = QString("%1: Error loading OZF file").arg(_map.path);
|
||||||
.arg(_ozf->fileName());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_scale = _ozf->scale(_zoom);
|
_scale = _ozf->scale(_zoom);
|
||||||
} else {
|
} else {
|
||||||
QImageReader img(_map.path);
|
QImageReader ir(_map.path);
|
||||||
_map.size = img.size();
|
if (!ir.canRead()) {
|
||||||
if (!_map.size.isValid()) {
|
_errorString = QString("%1: Unsupported/invalid image file")
|
||||||
_errorString = QString("%1: Error reading map image")
|
.arg(_map.path);
|
||||||
.arg(QFileInfo(_map.path).fileName());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
_map.size = ir.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -208,16 +205,8 @@ void OziMap::load()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_ozf && !_img && _map.isValid()) {
|
if (!_tile.isValid() && !_ozf && !_img)
|
||||||
_img = new QImage(_map.path);
|
_img = new Image(_map.path);
|
||||||
if (!_img || _img->isNull()) {
|
|
||||||
qWarning("%s: error loading map image", qPrintable(_map.path));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#ifdef ENABLE_HIDPI
|
|
||||||
_img->setDevicePixelRatio(_ratio);
|
|
||||||
#endif // ENABLE_HIDPI
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OziMap::unload()
|
void OziMap::unload()
|
||||||
@ -302,26 +291,16 @@ void OziMap::drawOZF(QPainter *painter, const QRectF &rect) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OziMap::drawImage(QPainter *painter, const QRectF &rect) const
|
void OziMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
QRectF sr(rect.topLeft() * _ratio, rect.size() * _ratio);
|
Q_UNUSED(flags);
|
||||||
if (_opengl) {
|
|
||||||
QImage img(_img->copy(sr.toRect()));
|
|
||||||
painter->drawImage(rect.topLeft(), img);
|
|
||||||
} else
|
|
||||||
painter->drawImage(rect.topLeft(), *_img, sr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OziMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
|
||||||
{
|
|
||||||
Q_UNUSED(block);
|
|
||||||
|
|
||||||
if (_ozf)
|
if (_ozf)
|
||||||
drawOZF(painter, rect);
|
drawOZF(painter, rect);
|
||||||
|
else if (_img)
|
||||||
|
_img->draw(painter, rect, flags);
|
||||||
else if (_tile.isValid())
|
else if (_tile.isValid())
|
||||||
drawTiled(painter, rect);
|
drawTiled(painter, rect);
|
||||||
else if (_img && !_img->isNull())
|
|
||||||
drawImage(painter, rect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF OziMap::ll2xy(const Coordinates &c)
|
QPointF OziMap::ll2xy(const Coordinates &c)
|
||||||
@ -391,3 +370,10 @@ void OziMap::rescale(int zoom)
|
|||||||
_zoom = zoom;
|
_zoom = zoom;
|
||||||
_scale = _ozf->scale(zoom);
|
_scale = _ozf->scale(zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OziMap::setDevicePixelRatio(qreal ratio)
|
||||||
|
{
|
||||||
|
_ratio = ratio;
|
||||||
|
if (_img)
|
||||||
|
_img->setDevicePixelRatio(_ratio);
|
||||||
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
class Tar;
|
class Tar;
|
||||||
class OZF;
|
class OZF;
|
||||||
class QImage;
|
class Image;
|
||||||
|
|
||||||
class OziMap : public Map
|
class OziMap : public Map
|
||||||
{
|
{
|
||||||
@ -31,10 +31,9 @@ public:
|
|||||||
QPointF ll2xy(const Coordinates &c);
|
QPointF ll2xy(const Coordinates &c);
|
||||||
Coordinates xy2ll(const QPointF &p);
|
Coordinates xy2ll(const QPointF &p);
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||||
|
|
||||||
void setDevicePixelRatio(qreal ratio) {_ratio = ratio;}
|
void setDevicePixelRatio(qreal ratio);
|
||||||
void setOpenGLEnabled(bool enabled) {_opengl = enabled;}
|
|
||||||
void load();
|
void load();
|
||||||
void unload();
|
void unload();
|
||||||
|
|
||||||
@ -61,21 +60,20 @@ private:
|
|||||||
|
|
||||||
void drawTiled(QPainter *painter, const QRectF &rect) const;
|
void drawTiled(QPainter *painter, const QRectF &rect) const;
|
||||||
void drawOZF(QPainter *painter, const QRectF &rect) const;
|
void drawOZF(QPainter *painter, const QRectF &rect) const;
|
||||||
void drawImage(QPainter *painter, const QRectF &rect) const;
|
void drawImage(QPainter *painter, const QRectF &rect, Flags flags) const;
|
||||||
|
|
||||||
void rescale(int zoom);
|
void rescale(int zoom);
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
Projection _projection;
|
Projection _projection;
|
||||||
Transform _transform;
|
Transform _transform;
|
||||||
QImage *_img;
|
Image *_img;
|
||||||
Tar *_tar;
|
Tar *_tar;
|
||||||
OZF *_ozf;
|
OZF *_ozf;
|
||||||
ImageInfo _map, _tile;
|
ImageInfo _map, _tile;
|
||||||
int _zoom;
|
int _zoom;
|
||||||
QPointF _scale;
|
QPointF _scale;
|
||||||
qreal _ratio;
|
qreal _ratio;
|
||||||
bool _opengl;
|
|
||||||
|
|
||||||
bool _valid;
|
bool _valid;
|
||||||
QString _errorString;
|
QString _errorString;
|
||||||
|
@ -192,7 +192,7 @@ qreal WMSMap::tileSize() const
|
|||||||
return (TILE_SIZE / _ratio);
|
return (TILE_SIZE / _ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMSMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
QPoint tl = QPoint((int)floor(rect.left() / tileSize()),
|
QPoint tl = QPoint((int)floor(rect.left() / tileSize()),
|
||||||
(int)floor(rect.top() / tileSize()));
|
(int)floor(rect.top() / tileSize()));
|
||||||
@ -214,7 +214,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block)
|
if (flags & Map::Block)
|
||||||
_tileLoader->loadTilesSync(tiles);
|
_tileLoader->loadTilesSync(tiles);
|
||||||
else
|
else
|
||||||
_tileLoader->loadTilesAsync(tiles);
|
_tileLoader->loadTilesAsync(tiles);
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
QPointF ll2xy(const Coordinates &c);
|
QPointF ll2xy(const Coordinates &c);
|
||||||
Coordinates xy2ll(const QPointF &p);
|
Coordinates xy2ll(const QPointF &p);
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||||
|
|
||||||
void setDevicePixelRatio(qreal ratio) {_ratio = ratio;}
|
void setDevicePixelRatio(qreal ratio) {_ratio = ratio;}
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
@ -169,7 +169,7 @@ QSizeF WMTSMap::tileSize(const WMTS::Zoom &zoom) const
|
|||||||
zoom.tile().height() / coordinatesRatio());
|
zoom.tile().height() / coordinatesRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMTSMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
void WMTSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
const WMTS::Zoom &z = _zooms.at(_zoom);
|
const WMTS::Zoom &z = _zooms.at(_zoom);
|
||||||
QSizeF ts(tileSize(z));
|
QSizeF ts(tileSize(z));
|
||||||
@ -184,7 +184,7 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
|||||||
for (int j = tl.y(); j < br.y(); j++)
|
for (int j = tl.y(); j < br.y(); j++)
|
||||||
tiles.append(Tile(QPoint(i, j), z.id()));
|
tiles.append(Tile(QPoint(i, j), z.id()));
|
||||||
|
|
||||||
if (block)
|
if (flags & Map::Block)
|
||||||
_tileLoader->loadTilesSync(tiles);
|
_tileLoader->loadTilesSync(tiles);
|
||||||
else
|
else
|
||||||
_tileLoader->loadTilesAsync(tiles);
|
_tileLoader->loadTilesAsync(tiles);
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
QPointF ll2xy(const Coordinates &c);
|
QPointF ll2xy(const Coordinates &c);
|
||||||
Coordinates xy2ll(const QPointF &p);
|
Coordinates xy2ll(const QPointF &p);
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
||||||
|
|
||||||
void setDevicePixelRatio(qreal ratio) {_deviceRatio = ratio;}
|
void setDevicePixelRatio(qreal ratio) {_deviceRatio = ratio;}
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
Loading…
Reference in New Issue
Block a user