diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index dc705580..85245a5d 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -27,6 +27,7 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent) Q_ASSERT(map != 0); Q_ASSERT(poi != 0); + _opengl = false; _scene = new QGraphicsScene(this); setScene(_scene); setDragMode(QGraphicsView::ScrollHandDrag); @@ -271,6 +272,7 @@ void MapView::setMap(Map *map) #ifdef ENABLE_HIDPI _map->setDevicePixelRatio(_ratio); #endif // ENABLE_HIDPI + _map->setOpenGLEnabled(_opengl); _map->load(); connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap())); @@ -507,6 +509,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale, #ifdef ENABLE_HIDPI _map->setDevicePixelRatio(1.0); #endif // ENABLE_HIDPI + _map->setOpenGLEnabled(false); // Compute sizes & ratios orig = viewport()->rect(); @@ -568,6 +571,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale, #ifdef ENABLE_HIDPI _map->setDevicePixelRatio(_ratio); #endif // ENABLE_HIDPI + _map->setOpenGLEnabled(_opengl); _plot = false; setUpdatesEnabled(true); } @@ -808,10 +812,14 @@ void MapView::scrollContentsBy(int dx, int dy) void MapView::useOpenGL(bool use) { + _opengl = use; + if (use) setViewport(new OPENGL_WIDGET); else setViewport(new QWidget); + + _map->setOpenGLEnabled(_opengl); } void MapView::useAntiAliasing(bool use) diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index d8d9581a..677138b4 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -142,6 +142,7 @@ private: #ifdef ENABLE_HIDPI qreal _ratio; #endif // ENABLE_HIDPI + bool _opengl; }; #endif // MAPVIEW_H diff --git a/src/map/geotiffmap.cpp b/src/map/geotiffmap.cpp index 6f439594..d89fdca3 100644 --- a/src/map/geotiffmap.cpp +++ b/src/map/geotiffmap.cpp @@ -7,7 +7,7 @@ GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent) - : Map(parent), _img(0), _ratio(1.0), _valid(false) + : Map(parent), _img(0), _ratio(1.0), _opengl(false), _valid(false) { GeoTIFF gt(fileName); if (!gt.isValid()) { @@ -80,11 +80,11 @@ void GeoTIFFMap::draw(QPainter *painter, const QRectF &rect, bool block) Q_UNUSED(block) if (_img && !_img->isNull()) { - /* Drawing directly a sub-rectangle without an image copy does not work - for big images under OpenGL. The image is most probably loaded as - whole which exceeds the texture size limit. */ QRectF sr(rect.topLeft() * _ratio, rect.size() * _ratio); - QImage img(_img->copy(sr.toRect())); - painter->drawImage(rect.topLeft(), img); + if (_opengl) { + QImage img(_img->copy(sr.toRect())); + painter->drawImage(rect.topLeft(), img); + } else + painter->drawImage(rect.topLeft(), *_img, sr); } } diff --git a/src/map/geotiffmap.h b/src/map/geotiffmap.h index 775068a9..c5ec942c 100644 --- a/src/map/geotiffmap.h +++ b/src/map/geotiffmap.h @@ -29,6 +29,7 @@ public: void draw(QPainter *painter, const QRectF &rect, bool block); void setDevicePixelRatio(qreal ratio) {_ratio = ratio;} + void setOpenGLEnabled(bool enabled) {_opengl = enabled;} void load(); void unload(); @@ -42,6 +43,7 @@ private: QImage *_img; QSize _size; qreal _ratio; + bool _opengl; bool _valid; QString _errorString; diff --git a/src/map/map.h b/src/map/map.h index 3fe809e4..4fc01d24 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -37,6 +37,7 @@ public: virtual void load() {} virtual void unload() {} virtual void setDevicePixelRatio(qreal ratio) {Q_UNUSED(ratio);} + virtual void setOpenGLEnabled(bool enabled) {Q_UNUSED(enabled);} virtual bool isValid() const {return true;} virtual QString errorString() const {return QString();} diff --git a/src/map/ozimap.cpp b/src/map/ozimap.cpp index 0f1ab262..41274942 100644 --- a/src/map/ozimap.cpp +++ b/src/map/ozimap.cpp @@ -15,6 +15,107 @@ #include "ozimap.h" +OziMap::OziMap(const QString &fileName, QObject *parent) + : Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0), + _opengl(false), _valid(false) +{ + QFileInfo fi(fileName); + QString suffix = fi.suffix().toLower(); + + + if (suffix == "tar") { + _tar = new Tar(fileName); + if (!_tar->open()) { + _errorString = "Error reading tar file"; + return; + } + + QString mapFileName = fi.completeBaseName() + ".map"; + QByteArray ba = _tar->file(mapFileName); + if (ba.isNull()) { + _errorString = "Map file not found"; + return; + } + QBuffer buffer(&ba); + MapFile mf(buffer); + if (!mf.isValid()) { + _errorString = mf.errorString(); + return; + } else { + _name = mf.name(); + _map.size = mf.size(); + _map.path = mf.image(); + _projection = mf.projection(); + _transform = mf.transform(); + } + + if (!setTileInfo(_tar->files())) + return; + } else { + QFile file(fileName); + MapFile mf(file); + if (!mf.isValid()) { + _errorString = mf.errorString(); + return; + } else { + _name = mf.name(); + _map.size = mf.size(); + _map.path = mf.image(); + _projection = mf.projection(); + _transform = mf.transform(); + } + + QDir set(fi.absolutePath() + "/" + "set"); + if (set.exists()) { + if (!setTileInfo(set.entryList(), set.absolutePath())) + return; + } else { + if (!setImageInfo(fi.absolutePath())) + return; + } + } + + _valid = true; +} + +OziMap::OziMap(const QString &fileName, Tar &tar, QObject *parent) + : Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0), + _opengl(false), _valid(false) +{ + QFileInfo fi(fileName); + QFileInfo map(fi.absolutePath()); + QFileInfo layer(map.absolutePath()); + QString mapFile = layer.fileName() + "/" + map.fileName() + "/" + + fi.fileName(); + + QByteArray ba = tar.file(mapFile); + if (ba.isNull()) { + _errorString = "Map file not found"; + return; + } + QBuffer buffer(&ba); + MapFile mf(buffer); + if (!mf.isValid()) { + _errorString = mf.errorString(); + return; + } + + _name = mf.name(); + _map.size = mf.size(); + _projection = mf.projection(); + _transform = mf.transform(); + _tar = new Tar(fi.absolutePath() + "/" + fi.completeBaseName() + ".tar"); + + _valid = true; +} + +OziMap::~OziMap() +{ + delete _img; + delete _tar; + delete _ozf; +} + bool OziMap::setImageInfo(const QString &path) { QFileInfo ii(_map.path); @@ -93,105 +194,6 @@ bool OziMap::setTileInfo(const QStringList &tiles, const QString &path) return false; } -OziMap::OziMap(const QString &fileName, QObject *parent) - : Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0), _valid(false) -{ - QFileInfo fi(fileName); - QString suffix = fi.suffix().toLower(); - - - if (suffix == "tar") { - _tar = new Tar(fileName); - if (!_tar->open()) { - _errorString = "Error reading tar file"; - return; - } - - QString mapFileName = fi.completeBaseName() + ".map"; - QByteArray ba = _tar->file(mapFileName); - if (ba.isNull()) { - _errorString = "Map file not found"; - return; - } - QBuffer buffer(&ba); - MapFile mf(buffer); - if (!mf.isValid()) { - _errorString = mf.errorString(); - return; - } else { - _name = mf.name(); - _map.size = mf.size(); - _map.path = mf.image(); - _projection = mf.projection(); - _transform = mf.transform(); - } - - if (!setTileInfo(_tar->files())) - return; - } else { - QFile file(fileName); - MapFile mf(file); - if (!mf.isValid()) { - _errorString = mf.errorString(); - return; - } else { - _name = mf.name(); - _map.size = mf.size(); - _map.path = mf.image(); - _projection = mf.projection(); - _transform = mf.transform(); - } - - QDir set(fi.absolutePath() + "/" + "set"); - if (set.exists()) { - if (!setTileInfo(set.entryList(), set.absolutePath())) - return; - } else { - if (!setImageInfo(fi.absolutePath())) - return; - } - } - - _valid = true; -} - -OziMap::OziMap(const QString &fileName, Tar &tar, QObject *parent) - : Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _ratio(1.0), _valid(false) -{ - QFileInfo fi(fileName); - QFileInfo map(fi.absolutePath()); - QFileInfo layer(map.absolutePath()); - QString mapFile = layer.fileName() + "/" + map.fileName() + "/" - + fi.fileName(); - - QByteArray ba = tar.file(mapFile); - if (ba.isNull()) { - _errorString = "Map file not found"; - return; - } - QBuffer buffer(&ba); - MapFile mf(buffer); - if (!mf.isValid()) { - _errorString = mf.errorString(); - return; - } - - _name = mf.name(); - _map.size = mf.size(); - _projection = mf.projection(); - _transform = mf.transform(); - _tar = new Tar(fi.absolutePath() + "/" + fi.completeBaseName() + ".tar"); - - _valid = true; -} - -OziMap::~OziMap() -{ - delete _img; - delete _tar; - delete _ozf; -} - void OziMap::load() { if (_tar && !_tar->isOpen()) { @@ -302,12 +304,12 @@ void OziMap::drawOZF(QPainter *painter, const QRectF &rect) const void OziMap::drawImage(QPainter *painter, const QRectF &rect) const { - /* Drawing directly a sub-rectangle without an image copy does not work - for big images under OpenGL. The image is most probably loaded as - whole which exceeds the texture size limit. */ QRectF sr(rect.topLeft() * _ratio, rect.size() * _ratio); - QImage img(_img->copy(sr.toRect())); - painter->drawImage(rect.topLeft(), img); + 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) diff --git a/src/map/ozimap.h b/src/map/ozimap.h index 8715fc73..badf6a4f 100644 --- a/src/map/ozimap.h +++ b/src/map/ozimap.h @@ -34,6 +34,7 @@ public: void draw(QPainter *painter, const QRectF &rect, bool block); void setDevicePixelRatio(qreal ratio) {_ratio = ratio;} + void setOpenGLEnabled(bool enabled) {_opengl = enabled;} void load(); void unload(); @@ -74,6 +75,7 @@ private: int _zoom; QPointF _scale; qreal _ratio; + bool _opengl; bool _valid; QString _errorString;