1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Improved tile file check

This commit is contained in:
Martin Tůma 2023-12-31 13:20:04 +01:00
parent acc9d07a22
commit 0248ecb254

View File

@ -62,7 +62,7 @@ OziMap::OziMap(const QString &fileName, CalibrationType type,
if (type == Unknown) { if (type == Unknown) {
_tar = new Tar(fileName); _tar = new Tar(fileName);
if (!_tar->open()) { if (!_tar->open()) {
_errorString = "Error reading tar file: " + _tar->errorString(); _errorString = _tar->errorString();
return; return;
} }
QStringList files(_tar->files()); QStringList files(_tar->files());
@ -262,27 +262,30 @@ bool OziMap::setImageInfo(const QString &path)
bool OziMap::setTileInfo(const QStringList &tiles, const QString &path) bool OziMap::setTileInfo(const QStringList &tiles, const QString &path)
{ {
static QRegularExpression rx("_[0-9]+_[0-9]+\\.");
if (!_map.size.isValid()) { if (!_map.size.isValid()) {
_errorString = "Missing total image size (IWH)"; _errorString = "Missing total image size (IWH)";
return false; return false;
} }
QRegularExpression 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)) { const QString &tile = tiles.at(i);
_tile.path = QString(tiles.at(i)).replace(rx, "_%1_%2.");
if (tile.startsWith("set/") && tile.contains(rx)) {
_tile.path = QString(tile).replace(rx, "_%1_%2.");
if (_tar) { if (_tar) {
QByteArray ba = _tar->file(tiles.at(i)); QByteArray ba(_tar->file(tile));
QBuffer buffer(&ba); QBuffer buffer(&ba);
_tile.size = QImageReader(&buffer).size(); _tile.size = QImageReader(&buffer).size();
} else { } else {
_tile.path = path + "/" + _tile.path; _tile.path = path + "/" + _tile.path;
_tile.size = QImageReader(path + "/" + tiles.at(i)).size(); _tile.size = QImageReader(path + "/" + tile).size();
} }
if (!_tile.size.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(tile).fileName());
return false; return false;
} }
@ -393,8 +396,9 @@ void OziMap::drawOZF(QPainter *painter, const QRectF &rect) const
int y = round(tl.y() * _mapRatio + j * _ozf->tileSize().height()); int y = round(tl.y() * _mapRatio + 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())