mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-18 19:52:09 +01:00
Only create/copy the sub-images when OpenGL is used
This commit is contained in:
parent
d4b46a4bb6
commit
3176271955
@ -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)
|
||||
|
@ -142,6 +142,7 @@ private:
|
||||
#ifdef ENABLE_HIDPI
|
||||
qreal _ratio;
|
||||
#endif // ENABLE_HIDPI
|
||||
bool _opengl;
|
||||
};
|
||||
|
||||
#endif // MAPVIEW_H
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user