mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 13:41:16 +01:00
Some more offline map code cleanup
This commit is contained in:
parent
16476dbf74
commit
de05f5e64b
@ -15,7 +15,7 @@
|
|||||||
#include "offlinemap.h"
|
#include "offlinemap.h"
|
||||||
|
|
||||||
|
|
||||||
bool OfflineMap::getImageInfo(const QString &path)
|
bool OfflineMap::setImageInfo(const QString &path)
|
||||||
{
|
{
|
||||||
QFileInfo ii(_map.path);
|
QFileInfo ii(_map.path);
|
||||||
|
|
||||||
@ -58,8 +58,13 @@ bool OfflineMap::getImageInfo(const QString &path)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OfflineMap::getTileInfo(const QStringList &tiles, const QString &path)
|
bool OfflineMap::setTileInfo(const QStringList &tiles, const QString &path)
|
||||||
{
|
{
|
||||||
|
if (!_map.size.isValid()) {
|
||||||
|
_errorString = "Missing total image size (IWH)";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
@ -79,6 +84,7 @@ bool OfflineMap::getTileInfo(const QStringList &tiles, const QString &path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_map.path = QString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,15 +93,6 @@ bool OfflineMap::getTileInfo(const QStringList &tiles, const QString &path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OfflineMap::totalSizeSet()
|
|
||||||
{
|
|
||||||
if (!_map.size.isValid()) {
|
|
||||||
_errorString = "Missing total image size (IWH)";
|
|
||||||
return false;
|
|
||||||
} else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
||||||
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _valid(false)
|
: Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _valid(false)
|
||||||
{
|
{
|
||||||
@ -158,21 +155,15 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_tar) {
|
if (_tar) {
|
||||||
if (!totalSizeSet())
|
if (!setTileInfo(_tar->files()))
|
||||||
return;
|
return;
|
||||||
if (!getTileInfo(_tar->files()))
|
|
||||||
return;
|
|
||||||
_map.path = QString();
|
|
||||||
} else {
|
} else {
|
||||||
QDir set(fi.absolutePath() + "/" + "set");
|
QDir set(fi.absolutePath() + "/" + "set");
|
||||||
if (set.exists()) {
|
if (set.exists()) {
|
||||||
if (!totalSizeSet())
|
if (!setTileInfo(set.entryList(), set.absolutePath()))
|
||||||
return;
|
return;
|
||||||
if (!getTileInfo(set.entryList(), set.absolutePath()))
|
|
||||||
return;
|
|
||||||
_map.path = QString();
|
|
||||||
} else {
|
} else {
|
||||||
if (!getImageInfo(fi.absolutePath()))
|
if (!setImageInfo(fi.absolutePath()))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,7 +221,7 @@ void OfflineMap::load()
|
|||||||
qPrintable(_tar->fileName()));
|
qPrintable(_tar->fileName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!getTileInfo(_tar->files()))
|
if (!setTileInfo(_tar->files()))
|
||||||
qWarning("%s: %s", qPrintable(_tar->fileName()),
|
qWarning("%s: %s", qPrintable(_tar->fileName()),
|
||||||
qPrintable(_errorString));
|
qPrintable(_errorString));
|
||||||
return;
|
return;
|
||||||
@ -249,7 +240,7 @@ void OfflineMap::unload()
|
|||||||
_img = 0;
|
_img = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
|
void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect) const
|
||||||
{
|
{
|
||||||
QPoint tl = QPoint((int)floor(rect.left() / (qreal)_tile.size.width())
|
QPoint tl = QPoint((int)floor(rect.left() / (qreal)_tile.size.width())
|
||||||
* _tile.size.width(), (int)floor(rect.top() / _tile.size.height())
|
* _tile.size.width(), (int)floor(rect.top() / _tile.size.height())
|
||||||
@ -287,7 +278,7 @@ void OfflineMap::drawTiled(QPainter *painter, const QRectF &rect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
|
void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect) const
|
||||||
{
|
{
|
||||||
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()
|
||||||
@ -318,7 +309,7 @@ void OfflineMap::drawOZF(QPainter *painter, const QRectF &rect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OfflineMap::drawImage(QPainter *painter, const QRectF &rect)
|
void OfflineMap::drawImage(QPainter *painter, const QRectF &rect) const
|
||||||
{
|
{
|
||||||
QRect r(rect.toRect());
|
QRect r(rect.toRect());
|
||||||
painter->drawImage(r.left(), r.top(), *_img, r.left(), r.top(),
|
painter->drawImage(r.left(), r.top(), *_img, r.left(), r.top(),
|
||||||
|
@ -59,13 +59,12 @@ private:
|
|||||||
QPointF ll2xy(const Coordinates &c) const;
|
QPointF ll2xy(const Coordinates &c) const;
|
||||||
Coordinates xy2ll(const QPointF &p) const;
|
Coordinates xy2ll(const QPointF &p) const;
|
||||||
|
|
||||||
bool getTileInfo(const QStringList &tiles, const QString &path = QString());
|
bool setTileInfo(const QStringList &tiles, const QString &path = QString());
|
||||||
bool getImageInfo(const QString &path);
|
bool setImageInfo(const QString &path);
|
||||||
bool totalSizeSet();
|
|
||||||
|
|
||||||
void drawTiled(QPainter *painter, const QRectF &rect);
|
void drawTiled(QPainter *painter, const QRectF &rect) const;
|
||||||
void drawOZF(QPainter *painter, const QRectF &rect);
|
void drawOZF(QPainter *painter, const QRectF &rect) const;
|
||||||
void drawImage(QPainter *painter, const QRectF &rect);
|
void drawImage(QPainter *painter, const QRectF &rect) const;
|
||||||
|
|
||||||
void rescale(int zoom);
|
void rescale(int zoom);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user