mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Offline map code cleanup/refactoring
This commit is contained in:
parent
a21464d98d
commit
16476dbf74
@ -84,16 +84,16 @@ Atlas::Atlas(const QString &fileName, QObject *parent) : Map(parent)
|
|||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
QString suffix = fi.suffix().toLower();
|
QString suffix = fi.suffix().toLower();
|
||||||
Tar tar;
|
Tar tar(fileName);
|
||||||
|
|
||||||
|
|
||||||
_valid = false;
|
_valid = false;
|
||||||
_zoom = 0;
|
_zoom = 0;
|
||||||
_name = fi.dir().dirName();
|
_name = fi.dir().dirName();
|
||||||
_ci = -1; _cz = -1;
|
_ci = -1; _cz = -1;
|
||||||
|
|
||||||
|
|
||||||
if (suffix == "tar") {
|
if (suffix == "tar") {
|
||||||
if (!tar.load(fileName)) {
|
if (!tar.open()) {
|
||||||
_errorString = "Error reading tar file";
|
_errorString = "Error reading tar file";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -113,7 +113,6 @@ Atlas::Atlas(const QString &fileName, QObject *parent) : Map(parent)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QDir dir(fi.absolutePath());
|
QDir dir(fi.absolutePath());
|
||||||
QFileInfoList layers = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
QFileInfoList layers = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
for (int n = 0; n < layers.count(); n++) {
|
for (int n = 0; n < layers.count(); n++) {
|
||||||
@ -150,12 +149,6 @@ Atlas::Atlas(const QString &fileName, QObject *parent) : Map(parent)
|
|||||||
_valid = true;
|
_valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas::~Atlas()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _maps.size(); i++)
|
|
||||||
delete _maps.at(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF Atlas::bounds() const
|
QRectF Atlas::bounds() const
|
||||||
{
|
{
|
||||||
QSizeF s(0, 0);
|
QSizeF s(0, 0);
|
||||||
@ -308,10 +301,10 @@ bool Atlas::isAtlas(const QString &path)
|
|||||||
{
|
{
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
QString suffix = fi.suffix().toLower();
|
QString suffix = fi.suffix().toLower();
|
||||||
Tar tar;
|
Tar tar(path);
|
||||||
|
|
||||||
if (suffix == "tar") {
|
if (suffix == "tar") {
|
||||||
if (!tar.load(path))
|
if (!tar.open())
|
||||||
return false;
|
return false;
|
||||||
QString tbaFileName = fi.completeBaseName() + ".tba";
|
QString tbaFileName = fi.completeBaseName() + ".tba";
|
||||||
return tar.contains(tbaFileName);
|
return tar.contains(tbaFileName);
|
||||||
|
@ -11,7 +11,6 @@ class Atlas : public Map
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Atlas(const QString &fileName, QObject *parent = 0);
|
Atlas(const QString &fileName, QObject *parent = 0);
|
||||||
~Atlas();
|
|
||||||
|
|
||||||
const QString &name() const {return _name;}
|
const QString &name() const {return _name;}
|
||||||
|
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
class Matrix {
|
class Matrix
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
Matrix() {_h = 0; _w = 0; _m = 0;}
|
Matrix() {_h = 0; _w = 0; _m = 0;}
|
||||||
Matrix(size_t h, size_t w);
|
Matrix(size_t h, size_t w);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#include <QtGlobal>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
@ -9,6 +8,8 @@
|
|||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include "common/coordinates.h"
|
#include "common/coordinates.h"
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
|
#include "tar.h"
|
||||||
|
#include "ozf.h"
|
||||||
#include "mapfile.h"
|
#include "mapfile.h"
|
||||||
#include "geotiff.h"
|
#include "geotiff.h"
|
||||||
#include "offlinemap.h"
|
#include "offlinemap.h"
|
||||||
@ -16,38 +17,40 @@
|
|||||||
|
|
||||||
bool OfflineMap::getImageInfo(const QString &path)
|
bool OfflineMap::getImageInfo(const QString &path)
|
||||||
{
|
{
|
||||||
QFileInfo ii(_imgPath);
|
QFileInfo ii(_map.path);
|
||||||
|
|
||||||
if (ii.isRelative())
|
if (ii.isRelative())
|
||||||
ii.setFile(path + "/" + _imgPath);
|
ii.setFile(path + "/" + _map.path);
|
||||||
|
|
||||||
if (!ii.exists()) {
|
if (!ii.exists()) {
|
||||||
int last = _imgPath.lastIndexOf('\\');
|
int last = _map.path.lastIndexOf('\\');
|
||||||
if (last >= 0 && last < _imgPath.length() - 1) {
|
if (last >= 0 && last < _map.path.length() - 1) {
|
||||||
QStringRef fn(&_imgPath, last + 1, _imgPath.length() - last - 1);
|
QStringRef fn(&_map.path, last + 1, _map.path.length() - last - 1);
|
||||||
ii.setFile(path + "/" + fn.toString());
|
ii.setFile(path + "/" + fn.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ii.exists())
|
if (ii.exists())
|
||||||
_imgPath = ii.absoluteFilePath();
|
_map.path = ii.absoluteFilePath();
|
||||||
else {
|
else {
|
||||||
_errorString = QString("%1: No such image file").arg(_imgPath);
|
_errorString = QString("%1: No such image file").arg(_map.path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OZF::isOZF(_imgPath)) {
|
if (OZF::isOZF(_map.path)) {
|
||||||
if (!_ozf.load(_imgPath)) {
|
_ozf = new OZF(_map.path);
|
||||||
|
if (!_ozf->open()) {
|
||||||
_errorString = QString("%1: Error loading OZF file")
|
_errorString = QString("%1: Error loading OZF file")
|
||||||
.arg(QFileInfo(_imgPath).fileName());
|
.arg(_ozf->fileName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
_scale = _ozf->scale(_zoom);
|
||||||
} else {
|
} else {
|
||||||
QImageReader img(_imgPath);
|
QImageReader img(_map.path);
|
||||||
_size = img.size();
|
_map.size = img.size();
|
||||||
if (!_size.isValid()) {
|
if (!_map.size.isValid()) {
|
||||||
_errorString = QString("%1: Error reading map image")
|
_errorString = QString("%1: Error reading map image")
|
||||||
.arg(QFileInfo(_imgPath).fileName());
|
.arg(QFileInfo(_map.path).fileName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,17 +63,17 @@ bool OfflineMap::getTileInfo(const QStringList &tiles, const QString &path)
|
|||||||
QRegExp rx("_[0-9]+_[0-9]+\\.");
|
QRegExp rx("_[0-9]+_[0-9]+\\.");
|
||||||
for (int i = 0; i < tiles.size(); i++) {
|
for (int i = 0; i < tiles.size(); i++) {
|
||||||
if (tiles.at(i).contains(rx)) {
|
if (tiles.at(i).contains(rx)) {
|
||||||
_tileName = QString(tiles.at(i)).replace(rx, "_%1_%2.");
|
_tile.path = QString(tiles.at(i)).replace(rx, "_%1_%2.");
|
||||||
|
|
||||||
if (path.isNull()) {
|
if (_tar) {
|
||||||
QByteArray ba = _tar.file(tiles.at(i));
|
QByteArray ba = _tar->file(tiles.at(i));
|
||||||
QBuffer buffer(&ba);
|
QBuffer buffer(&ba);
|
||||||
_tileSize = QImageReader(&buffer).size();
|
_tile.size = QImageReader(&buffer).size();
|
||||||
} else {
|
} else {
|
||||||
_tileName = path + "/" + _tileName;
|
_tile.path = path + "/" + _tile.path;
|
||||||
_tileSize = QImageReader(path + "/" + tiles.at(i)).size();
|
_tile.size = QImageReader(path + "/" + tiles.at(i)).size();
|
||||||
}
|
}
|
||||||
if (!_tileSize.isValid()) {
|
if (!_tile.size.isValid()) {
|
||||||
_errorString = QString("Error retrieving tile size: "
|
_errorString = QString("Error retrieving tile size: "
|
||||||
"%1: Invalid image").arg(QFileInfo(tiles.at(i)).fileName());
|
"%1: Invalid image").arg(QFileInfo(tiles.at(i)).fileName());
|
||||||
return false;
|
return false;
|
||||||
@ -86,7 +89,7 @@ bool OfflineMap::getTileInfo(const QStringList &tiles, const QString &path)
|
|||||||
|
|
||||||
bool OfflineMap::totalSizeSet()
|
bool OfflineMap::totalSizeSet()
|
||||||
{
|
{
|
||||||
if (!_size.isValid()) {
|
if (!_map.size.isValid()) {
|
||||||
_errorString = "Missing total image size (IWH)";
|
_errorString = "Missing total image size (IWH)";
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
@ -94,24 +97,21 @@ bool OfflineMap::totalSizeSet()
|
|||||||
}
|
}
|
||||||
|
|
||||||
OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
||||||
: Map(parent)
|
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _valid(false)
|
||||||
{
|
{
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
QString suffix = fi.suffix().toLower();
|
QString suffix = fi.suffix().toLower();
|
||||||
|
|
||||||
_valid = false;
|
|
||||||
_img = 0;
|
|
||||||
_zoom = 0;
|
|
||||||
_scale = QPointF(1.0, 1.0);
|
|
||||||
|
|
||||||
if (suffix == "tar") {
|
if (suffix == "tar") {
|
||||||
if (!_tar.load(fileName)) {
|
_tar = new Tar(fileName);
|
||||||
|
if (!_tar->open()) {
|
||||||
_errorString = "Error reading tar file";
|
_errorString = "Error reading tar file";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString mapFileName = fi.completeBaseName() + ".map";
|
QString mapFileName = fi.completeBaseName() + ".map";
|
||||||
QByteArray ba = _tar.file(mapFileName);
|
QByteArray ba = _tar->file(mapFileName);
|
||||||
if (ba.isNull()) {
|
if (ba.isNull()) {
|
||||||
_errorString = "Map file not found";
|
_errorString = "Map file not found";
|
||||||
return;
|
return;
|
||||||
@ -123,8 +123,8 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
_name = mf.name();
|
_name = mf.name();
|
||||||
_size = mf.size();
|
_map.size = mf.size();
|
||||||
_imgPath = mf.image();
|
_map.path = mf.image();
|
||||||
_projection = mf.projection();
|
_projection = mf.projection();
|
||||||
_transform = mf.transform();
|
_transform = mf.transform();
|
||||||
}
|
}
|
||||||
@ -136,8 +136,8 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
_name = mf.name();
|
_name = mf.name();
|
||||||
_size = mf.size();
|
_map.size = mf.size();
|
||||||
_imgPath = mf.image();
|
_map.path = mf.image();
|
||||||
_projection = mf.projection();
|
_projection = mf.projection();
|
||||||
_transform = mf.transform();
|
_transform = mf.transform();
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
_name = fi.fileName();
|
_name = fi.fileName();
|
||||||
_imgPath = fileName;
|
_map.path = fileName;
|
||||||
_projection = gt.projection();
|
_projection = gt.projection();
|
||||||
_transform = gt.transform();
|
_transform = gt.transform();
|
||||||
}
|
}
|
||||||
@ -157,12 +157,12 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_tar.isOpen()) {
|
if (_tar) {
|
||||||
if (!totalSizeSet())
|
if (!totalSizeSet())
|
||||||
return;
|
return;
|
||||||
if (!getTileInfo(_tar.files()))
|
if (!getTileInfo(_tar->files()))
|
||||||
return;
|
return;
|
||||||
_imgPath = QString();
|
_map.path = QString();
|
||||||
} else {
|
} else {
|
||||||
QDir set(fi.absolutePath() + "/" + "set");
|
QDir set(fi.absolutePath() + "/" + "set");
|
||||||
if (set.exists()) {
|
if (set.exists()) {
|
||||||
@ -170,7 +170,7 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
|||||||
return;
|
return;
|
||||||
if (!getTileInfo(set.entryList(), set.absolutePath()))
|
if (!getTileInfo(set.entryList(), set.absolutePath()))
|
||||||
return;
|
return;
|
||||||
_imgPath = QString();
|
_map.path = QString();
|
||||||
} else {
|
} else {
|
||||||
if (!getImageInfo(fi.absolutePath()))
|
if (!getImageInfo(fi.absolutePath()))
|
||||||
return;
|
return;
|
||||||
@ -183,15 +183,11 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
OfflineMap::OfflineMap(const QString &fileName, Tar &tar, QObject *parent)
|
OfflineMap::OfflineMap(const QString &fileName, Tar &tar, QObject *parent)
|
||||||
: Map(parent)
|
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _valid(false)
|
||||||
{
|
{
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
MapFile mf;
|
MapFile mf;
|
||||||
|
|
||||||
_valid = false;
|
|
||||||
_img = 0;
|
|
||||||
_zoom = 0;
|
|
||||||
_scale = QPointF(1.0, 1.0);
|
|
||||||
|
|
||||||
QFileInfo map(fi.absolutePath());
|
QFileInfo map(fi.absolutePath());
|
||||||
QFileInfo layer(map.absolutePath());
|
QFileInfo layer(map.absolutePath());
|
||||||
@ -210,36 +206,40 @@ OfflineMap::OfflineMap(const QString &fileName, Tar &tar, QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_name = mf.name();
|
_name = mf.name();
|
||||||
_size = mf.size();
|
_map.size = mf.size();
|
||||||
_projection = mf.projection();
|
_projection = mf.projection();
|
||||||
_transform = mf.transform();
|
_transform = mf.transform();
|
||||||
_inverted = _transform.inverted();
|
_inverted = _transform.inverted();
|
||||||
|
_tar = new Tar(fi.absolutePath() + "/" + fi.completeBaseName() + ".tar");
|
||||||
|
|
||||||
_tarPath = fi.absolutePath() + "/" + fi.completeBaseName() + ".tar";
|
|
||||||
_valid = true;
|
_valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflineMap::~OfflineMap()
|
OfflineMap::~OfflineMap()
|
||||||
{
|
{
|
||||||
delete _img;
|
delete _img;
|
||||||
|
delete _tar;
|
||||||
|
delete _ozf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OfflineMap::load()
|
void OfflineMap::load()
|
||||||
{
|
{
|
||||||
if (!_tarPath.isNull() && !_tileSize.isValid()) {
|
if (_tar && !_tar->isOpen()) {
|
||||||
if (!_tar.load(_tarPath)) {
|
if (!_tar->open()) {
|
||||||
qWarning("%s: error loading tar file", qPrintable(_tarPath));
|
qWarning("%s: error loading tar file",
|
||||||
|
qPrintable(_tar->fileName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!getTileInfo(_tar.files()))
|
if (!getTileInfo(_tar->files()))
|
||||||
qWarning("%s: %s", qPrintable(_tarPath), qPrintable(_errorString));
|
qWarning("%s: %s", qPrintable(_tar->fileName()),
|
||||||
|
qPrintable(_errorString));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_img && !_imgPath.isNull() && !_ozf.isOpen()) {
|
if (!_ozf && !_img && _map.isValid()) {
|
||||||
_img = new QImage(_imgPath);
|
_img = new QImage(_map.path);
|
||||||
if (_img->isNull())
|
if (_img->isNull())
|
||||||
qWarning("%s: error loading map image", qPrintable(_imgPath));
|
qWarning("%s: error loading map image", qPrintable(_map.path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,24 +251,24 @@ void OfflineMap::unload()
|
|||||||
|
|
||||||
void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
|
void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
|
||||||
{
|
{
|
||||||
QPoint tl = QPoint((int)floor(rect.left() / (qreal)_tileSize.width())
|
QPoint tl = QPoint((int)floor(rect.left() / (qreal)_tile.size.width())
|
||||||
* _tileSize.width(), (int)floor(rect.top() / _tileSize.height())
|
* _tile.size.width(), (int)floor(rect.top() / _tile.size.height())
|
||||||
* _tileSize.height());
|
* _tile.size.height());
|
||||||
|
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||||
for (int i = 0; i < ceil(s.width() / _tileSize.width()); i++) {
|
for (int i = 0; i < ceil(s.width() / _tile.size.width()); i++) {
|
||||||
for (int j = 0; j < ceil(s.height() / _tileSize.height()); j++) {
|
for (int j = 0; j < ceil(s.height() / _tile.size.height()); j++) {
|
||||||
int x = tl.x() + i * _tileSize.width();
|
int x = tl.x() + i * _tile.size.width();
|
||||||
int y = tl.y() + j * _tileSize.height();
|
int y = tl.y() + j * _tile.size.height();
|
||||||
|
|
||||||
QString tileName(_tileName.arg(QString::number(x),
|
QString tileName(_tile.path.arg(QString::number(x),
|
||||||
QString::number(y)));
|
QString::number(y)));
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
|
|
||||||
if (_tar.isOpen()) {
|
if (_tar) {
|
||||||
QString key = _tar.fileName() + "/" + tileName;
|
QString key = _tar->fileName() + "/" + tileName;
|
||||||
if (!QPixmapCache::find(key, &pixmap)) {
|
if (!QPixmapCache::find(key, &pixmap)) {
|
||||||
QByteArray ba = _tar.file(tileName);
|
QByteArray ba = _tar->file(tileName);
|
||||||
pixmap = QPixmap::fromImage(QImage::fromData(ba));
|
pixmap = QPixmap::fromImage(QImage::fromData(ba));
|
||||||
if (!pixmap.isNull())
|
if (!pixmap.isNull())
|
||||||
QPixmapCache::insert(key, pixmap);
|
QPixmapCache::insert(key, pixmap);
|
||||||
@ -278,8 +278,8 @@ void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
|
|||||||
|
|
||||||
if (pixmap.isNull()) {
|
if (pixmap.isNull()) {
|
||||||
qWarning("%s: error loading tile image", qPrintable(
|
qWarning("%s: error loading tile image", qPrintable(
|
||||||
_tileName.arg(QString::number(x), QString::number(y))));
|
_tile.path.arg(QString::number(x), QString::number(y))));
|
||||||
painter->fillRect(QRectF(QPoint(x, y), _tileSize),
|
painter->fillRect(QRectF(QPoint(x, y), _tile.size),
|
||||||
_backgroundColor);
|
_backgroundColor);
|
||||||
} else
|
} else
|
||||||
painter->drawPixmap(QPoint(x, y), pixmap);
|
painter->drawPixmap(QPoint(x, y), pixmap);
|
||||||
@ -289,28 +289,28 @@ void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
|
|||||||
|
|
||||||
void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
|
void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
|
||||||
{
|
{
|
||||||
QPoint tl = QPoint((int)floor(rect.left() / _ozf.tileSize().width())
|
QPoint tl = QPoint((int)floor(rect.left() / _ozf->tileSize().width())
|
||||||
* _ozf.tileSize().width(), (int)floor(rect.top()
|
* _ozf->tileSize().width(), (int)floor(rect.top()
|
||||||
/ _ozf.tileSize().height()) * _ozf.tileSize().height());
|
/ _ozf->tileSize().height()) * _ozf->tileSize().height());
|
||||||
|
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||||
for (int i = 0; i < ceil(s.width() / _ozf.tileSize().width()); i++) {
|
for (int i = 0; i < ceil(s.width() / _ozf->tileSize().width()); i++) {
|
||||||
for (int j = 0; j < ceil(s.height() / _ozf.tileSize().height()); j++) {
|
for (int j = 0; j < ceil(s.height() / _ozf->tileSize().height()); j++) {
|
||||||
int x = tl.x() + i * _ozf.tileSize().width();
|
int x = tl.x() + i * _ozf->tileSize().width();
|
||||||
int y = tl.y() + j * _ozf.tileSize().height();
|
int y = tl.y() + j * _ozf->tileSize().height();
|
||||||
|
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
QString key = _ozf.fileName() + "/" + QString::number(_zoom) + "_"
|
QString key = _ozf->fileName() + "/" + QString::number(_zoom) + "_"
|
||||||
+ QString::number(x) + "_" + QString::number(y);
|
+ QString::number(x) + "_" + QString::number(y);
|
||||||
if (!QPixmapCache::find(key, &pixmap)) {
|
if (!QPixmapCache::find(key, &pixmap)) {
|
||||||
pixmap = _ozf.tile(_zoom, x, y);
|
pixmap = _ozf->tile(_zoom, x, y);
|
||||||
if (!pixmap.isNull())
|
if (!pixmap.isNull())
|
||||||
QPixmapCache::insert(key, pixmap);
|
QPixmapCache::insert(key, pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pixmap.isNull()) {
|
if (pixmap.isNull()) {
|
||||||
qWarning("%s: error loading tile image", qPrintable(key));
|
qWarning("%s: error loading tile image", qPrintable(key));
|
||||||
painter->fillRect(QRectF(QPoint(x, y), _ozf.tileSize()),
|
painter->fillRect(QRectF(QPoint(x, y), _ozf->tileSize()),
|
||||||
_backgroundColor);
|
_backgroundColor);
|
||||||
} else
|
} else
|
||||||
painter->drawPixmap(QPoint(x, y), pixmap);
|
painter->drawPixmap(QPoint(x, y), pixmap);
|
||||||
@ -327,9 +327,9 @@ void OfflineMap::drawImage(QPainter *painter, const QRectF &rect)
|
|||||||
|
|
||||||
void OfflineMap::draw(QPainter *painter, const QRectF &rect)
|
void OfflineMap::draw(QPainter *painter, const QRectF &rect)
|
||||||
{
|
{
|
||||||
if (_ozf.isOpen())
|
if (_ozf)
|
||||||
drawOZF(painter, rect);
|
drawOZF(painter, rect);
|
||||||
else if (_tileSize.isValid())
|
else if (_tile.isValid())
|
||||||
drawTiled(painter, rect);
|
drawTiled(painter, rect);
|
||||||
else if (_img && !_img->isNull())
|
else if (_img && !_img->isNull())
|
||||||
drawImage(painter, rect);
|
drawImage(painter, rect);
|
||||||
@ -339,7 +339,7 @@ void OfflineMap::draw(QPainter *painter, const QRectF &rect)
|
|||||||
|
|
||||||
QPointF OfflineMap::ll2xy(const Coordinates &c) const
|
QPointF OfflineMap::ll2xy(const Coordinates &c) const
|
||||||
{
|
{
|
||||||
if (_ozf.isOpen()) {
|
if (_ozf) {
|
||||||
QPointF p(_transform.map(_projection.ll2xy(c)));
|
QPointF p(_transform.map(_projection.ll2xy(c)));
|
||||||
return QPointF(p.x() * _scale.x(), p.y() * _scale.y());
|
return QPointF(p.x() * _scale.x(), p.y() * _scale.y());
|
||||||
} else
|
} else
|
||||||
@ -348,7 +348,7 @@ QPointF OfflineMap::ll2xy(const Coordinates &c) const
|
|||||||
|
|
||||||
Coordinates OfflineMap::xy2ll(const QPointF &p) const
|
Coordinates OfflineMap::xy2ll(const QPointF &p) const
|
||||||
{
|
{
|
||||||
if (_ozf.isOpen()) {
|
if (_ozf) {
|
||||||
return _projection.xy2ll(_inverted.map(QPointF(p.x() / _scale.x(),
|
return _projection.xy2ll(_inverted.map(QPointF(p.x() / _scale.x(),
|
||||||
p.y() / _scale.y())));
|
p.y() / _scale.y())));
|
||||||
} else
|
} else
|
||||||
@ -357,10 +357,10 @@ Coordinates OfflineMap::xy2ll(const QPointF &p) const
|
|||||||
|
|
||||||
QRectF OfflineMap::bounds() const
|
QRectF OfflineMap::bounds() const
|
||||||
{
|
{
|
||||||
if (_ozf.isOpen())
|
if (_ozf)
|
||||||
return QRectF(QPointF(0, 0), _ozf.size(_zoom));
|
return QRectF(QPointF(0, 0), _ozf->size(_zoom));
|
||||||
else
|
else
|
||||||
return QRectF(QPointF(0, 0), _size);
|
return QRectF(QPointF(0, 0), _map.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal OfflineMap::resolution(const QRectF &rect) const
|
qreal OfflineMap::resolution(const QRectF &rect) const
|
||||||
@ -376,7 +376,7 @@ qreal OfflineMap::resolution(const QRectF &rect) const
|
|||||||
|
|
||||||
int OfflineMap::zoomFit(const QSize &size, const RectC &br)
|
int OfflineMap::zoomFit(const QSize &size, const RectC &br)
|
||||||
{
|
{
|
||||||
if (_ozf.isOpen()) {
|
if (_ozf) {
|
||||||
if (!br.isValid())
|
if (!br.isValid())
|
||||||
rescale(0);
|
rescale(0);
|
||||||
else {
|
else {
|
||||||
@ -384,7 +384,7 @@ int OfflineMap::zoomFit(const QSize &size, const RectC &br)
|
|||||||
_transform.map(_projection.ll2xy(br.bottomRight())))
|
_transform.map(_projection.ll2xy(br.bottomRight())))
|
||||||
.toRect().normalized());
|
.toRect().normalized());
|
||||||
|
|
||||||
for (int i = 0; i < _ozf.zooms(); i++) {
|
for (int i = 0; i < _ozf->zooms(); i++) {
|
||||||
rescale(i);
|
rescale(i);
|
||||||
if (sbr.size().width() * _scale.x() <= size.width()
|
if (sbr.size().width() * _scale.x() <= size.width()
|
||||||
&& sbr.size().height() * _scale.y() <= size.height())
|
&& sbr.size().height() * _scale.y() <= size.height())
|
||||||
@ -398,7 +398,7 @@ int OfflineMap::zoomFit(const QSize &size, const RectC &br)
|
|||||||
|
|
||||||
int OfflineMap::zoomIn()
|
int OfflineMap::zoomIn()
|
||||||
{
|
{
|
||||||
if (_ozf.isOpen())
|
if (_ozf)
|
||||||
rescale(qMax(_zoom - 1, 0));
|
rescale(qMax(_zoom - 1, 0));
|
||||||
|
|
||||||
return _zoom;
|
return _zoom;
|
||||||
@ -406,8 +406,8 @@ int OfflineMap::zoomIn()
|
|||||||
|
|
||||||
int OfflineMap::zoomOut()
|
int OfflineMap::zoomOut()
|
||||||
{
|
{
|
||||||
if (_ozf.isOpen())
|
if (_ozf)
|
||||||
rescale(qMin(_zoom + 1, _ozf.zooms() - 1));
|
rescale(qMin(_zoom + 1, _ozf->zooms() - 1));
|
||||||
|
|
||||||
return _zoom;
|
return _zoom;
|
||||||
}
|
}
|
||||||
@ -415,7 +415,5 @@ int OfflineMap::zoomOut()
|
|||||||
void OfflineMap::rescale(int zoom)
|
void OfflineMap::rescale(int zoom)
|
||||||
{
|
{
|
||||||
_zoom = zoom;
|
_zoom = zoom;
|
||||||
_scale = QPointF(
|
_scale = _ozf->scale(zoom);
|
||||||
(qreal)_ozf.size(_zoom).width() / (qreal)_ozf.size(0).width(),
|
|
||||||
(qreal)_ozf.size(_zoom).height() / (qreal)_ozf.size(0).height());
|
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
#include "projection.h"
|
#include "projection.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "tar.h"
|
|
||||||
#include "ozf.h"
|
|
||||||
|
|
||||||
|
class Tar;
|
||||||
|
class OZF;
|
||||||
class QImage;
|
class QImage;
|
||||||
|
|
||||||
class OfflineMap : public Map
|
class OfflineMap : public Map
|
||||||
@ -49,6 +49,13 @@ public:
|
|||||||
{return _transform.map(p);}
|
{return _transform.map(p);}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct ImageInfo {
|
||||||
|
QSize size;
|
||||||
|
QString path;
|
||||||
|
|
||||||
|
bool isValid() const {return size.isValid() && !path.isEmpty();}
|
||||||
|
};
|
||||||
|
|
||||||
QPointF ll2xy(const Coordinates &c) const;
|
QPointF ll2xy(const Coordinates &c) const;
|
||||||
Coordinates xy2ll(const QPointF &p) const;
|
Coordinates xy2ll(const QPointF &p) const;
|
||||||
|
|
||||||
@ -67,14 +74,10 @@ private:
|
|||||||
Projection _projection;
|
Projection _projection;
|
||||||
QTransform _transform, _inverted;
|
QTransform _transform, _inverted;
|
||||||
|
|
||||||
OZF _ozf;
|
|
||||||
Tar _tar;
|
|
||||||
QString _tarPath;
|
|
||||||
QImage *_img;
|
QImage *_img;
|
||||||
QString _imgPath;
|
Tar *_tar;
|
||||||
QSize _tileSize;
|
OZF *_ozf;
|
||||||
QString _tileName;
|
ImageInfo _map, _tile;
|
||||||
QSize _size;
|
|
||||||
|
|
||||||
int _zoom;
|
int _zoom;
|
||||||
QPointF _scale;
|
QPointF _scale;
|
||||||
|
@ -185,12 +185,8 @@ bool OZF::readTileTable()
|
|||||||
return _zooms.isEmpty() ? false : true;
|
return _zooms.isEmpty() ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OZF::load(const QString &path)
|
bool OZF::open()
|
||||||
{
|
{
|
||||||
if (_file.isOpen())
|
|
||||||
_file.close();
|
|
||||||
|
|
||||||
_file.setFileName(path);
|
|
||||||
if (!_file.open(QIODevice::ReadOnly))
|
if (!_file.open(QIODevice::ReadOnly))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -250,6 +246,12 @@ QSize OZF::size(int zoom) const
|
|||||||
return _zooms.at(zoom).size;
|
return _zooms.at(zoom).size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointF OZF::scale(int zoom) const
|
||||||
|
{
|
||||||
|
return QPointF((qreal)size(zoom).width() / (qreal)size(0).width(),
|
||||||
|
(qreal)size(zoom).height() / (qreal)size(0).height());
|
||||||
|
}
|
||||||
|
|
||||||
bool OZF::isOZF(const QString &path)
|
bool OZF::isOZF(const QString &path)
|
||||||
{
|
{
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
|
@ -12,15 +12,17 @@
|
|||||||
class OZF
|
class OZF
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OZF() : _tileSize(0), _decrypt(false), _key(0) {}
|
OZF(const QString &name) : _tileSize(0), _decrypt(false), _key(0),
|
||||||
|
_file(name) {}
|
||||||
|
|
||||||
bool load(const QString &path);
|
bool open();
|
||||||
|
|
||||||
QString fileName() const {return _file.fileName();}
|
QString fileName() const {return _file.fileName();}
|
||||||
bool isOpen() const {return _file.isOpen();}
|
bool isOpen() const {return _file.isOpen();}
|
||||||
|
|
||||||
int zooms() const {return _zooms.size();}
|
int zooms() const {return _zooms.size();}
|
||||||
QSize size(int zoom) const;
|
QSize size(int zoom) const;
|
||||||
|
QPointF scale(int zoom) const;
|
||||||
QSize tileSize() const {return QSize(_tileSize, _tileSize);}
|
QSize tileSize() const {return QSize(_tileSize, _tileSize);}
|
||||||
QPixmap tile(int zoom, int x, int y);
|
QPixmap tile(int zoom, int x, int y);
|
||||||
|
|
||||||
|
@ -44,17 +44,12 @@ static quint64 number(const char* data, size_t size, int base = 8)
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tar::load(const QString &path)
|
bool Tar::open()
|
||||||
{
|
{
|
||||||
if (_file.isOpen())
|
|
||||||
_file.close();
|
|
||||||
_index.clear();
|
|
||||||
|
|
||||||
_file.setFileName(path);
|
|
||||||
if (!_file.open(QIODevice::ReadOnly))
|
if (!_file.open(QIODevice::ReadOnly))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(_file.fileName());
|
||||||
QString tmiPath = fi.path() + "/" + fi.completeBaseName() + ".tmi";
|
QString tmiPath = fi.path() + "/" + fi.completeBaseName() + ".tmi";
|
||||||
|
|
||||||
if (loadTmi(tmiPath))
|
if (loadTmi(tmiPath))
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
class Tar
|
class Tar
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool load(const QString &path);
|
Tar(const QString &name) : _file(name) {}
|
||||||
|
|
||||||
|
bool open();
|
||||||
|
|
||||||
QStringList files() const {return _index.keys();}
|
QStringList files() const {return _index.keys();}
|
||||||
QByteArray file(const QString &name);
|
QByteArray file(const QString &name);
|
||||||
|
Loading…
Reference in New Issue
Block a user