diff --git a/src/map/IMG/gmapdata.cpp b/src/map/IMG/gmapdata.cpp index 58b141f0..1e15c1e2 100644 --- a/src/map/IMG/gmapdata.cpp +++ b/src/map/IMG/gmapdata.cpp @@ -92,7 +92,7 @@ bool GMAPData::loadTile(const QDir &dir) } } - if (!tile->init()) { + if (!tile->init(0)) { qWarning("%s: Invalid map tile", qPrintable(dir.path())); delete tile; return false; diff --git a/src/map/IMG/imgdata.cpp b/src/map/IMG/imgdata.cpp index a180b570..41ea1a4e 100644 --- a/src/map/IMG/imgdata.cpp +++ b/src/map/IMG/imgdata.cpp @@ -29,11 +29,11 @@ static SubFile::Type tileType(const char str[3]) return SubFile::Unknown; } -bool IMGData::readSubFileBlocks(QFile &file, quint64 offset, SubFile *subFile) +bool IMGData::readSubFileBlocks(QFile *file, quint64 offset, SubFile *subFile) { quint16 block; - if (!file.seek(offset + 0x20)) + if (!file->seek(offset + 0x20)) return false; for (int i = 0; i < 240; i++) { if (!readValue(file, block)) @@ -46,11 +46,11 @@ bool IMGData::readSubFileBlocks(QFile &file, quint64 offset, SubFile *subFile) return true; } -bool IMGData::readIMGHeader(QFile &file) +bool IMGData::readIMGHeader(QFile *file) { char signature[7], identifier[7]; - if (!(file.read((char*)&_key, 1) && file.seek(0x10) - && read(file, signature, sizeof(signature)) && file.seek(0x41) + if (!(file->read((char*)&_key, 1) && file->seek(0x10) + && read(file, signature, sizeof(signature)) && file->seek(0x41) && read(file, identifier, sizeof(identifier))) || memcmp(signature, "DSKIMG", sizeof(signature)) || memcmp(identifier, "GARMIN", sizeof(identifier))) { @@ -60,8 +60,8 @@ bool IMGData::readIMGHeader(QFile &file) char d1[20], d2[31]; quint8 e1, e2; - if (!(file.seek(0x49) && read(file, d1, sizeof(d1)) && file.seek(0x61) - && readValue(file, e1) && readValue(file, e2) && file.seek(0x65) + if (!(file->seek(0x49) && read(file, d1, sizeof(d1)) && file->seek(0x61) + && readValue(file, e1) && readValue(file, e2) && file->seek(0x65) && read(file, d2, sizeof(d2)))) { _errorString = "Error reading IMG header"; return false; @@ -74,7 +74,7 @@ bool IMGData::readIMGHeader(QFile &file) return true; } -bool IMGData::readFAT(QFile &file, TileMap &tileMap) +bool IMGData::readFAT(QFile *file, TileMap &tileMap) { QByteArray typFile; quint8 flag; @@ -82,7 +82,7 @@ bool IMGData::readFAT(QFile &file, TileMap &tileMap) // Skip unused FAT blocks if any while (true) { - if (!(file.seek(offset) && readValue(file, flag))) + if (!(file->seek(offset) && readValue(file, flag))) return false; if (flag) break; @@ -93,14 +93,14 @@ bool IMGData::readFAT(QFile &file, TileMap &tileMap) char name[8], type[3]; quint32 size; quint16 part; - if (!(file.seek(offset + 12) && readValue(file, size))) + if (!(file->seek(offset + 12) && readValue(file, size))) return false; offset += 512; int cnt = (size - offset) / 512; // Read FAT blocks describing the IMG sub-files for (int i = 0; i < cnt; i++) { - if (!(file.seek(offset) && readValue(file, flag) + if (!(file->seek(offset) && readValue(file, flag) && read(file, name, sizeof(name)) && read(file, type, sizeof(type)) && readValue(file, size) && readValue(file, part))) @@ -140,13 +140,13 @@ bool IMGData::readFAT(QFile &file, TileMap &tileMap) return true; } -bool IMGData::createTileTree(const TileMap &tileMap) +bool IMGData::createTileTree(QFile *file, const TileMap &tileMap) { for (TileMap::const_iterator it = tileMap.constBegin(); it != tileMap.constEnd(); ++it) { VectorTile *tile = it.value(); - if (!tile->init()) { + if (!tile->init(file)) { qWarning("%s: %s: Invalid map tile", qPrintable(_fileName), qPrintable(it.key())); delete tile; @@ -177,14 +177,14 @@ IMGData::IMGData(const QString &fileName) : MapData(fileName) return; } - if (!readIMGHeader(file)) + if (!readIMGHeader(&file)) return; - if (!readFAT(file, tileMap)) { + if (!readFAT(&file, tileMap)) { _errorString = "Error reading FAT data"; qDeleteAll(tileMap); return; } - if (!createTileTree(tileMap)) { + if (!createTileTree(&file, tileMap)) { _errorString = "No usable map tile found"; return; } @@ -194,16 +194,16 @@ IMGData::IMGData(const QString &fileName) : MapData(fileName) _valid = true; } -qint64 IMGData::read(QFile &file, char *data, qint64 maxSize) const +qint64 IMGData::read(QFile *file, char *data, qint64 maxSize) const { - qint64 ret = file.read(data, maxSize); + qint64 ret = file->read(data, maxSize); if (_key) for (int i = 0; i < ret; i++) data[i] ^= _key; return ret; } -template bool IMGData::readValue(QFile &file, T &val) const +template bool IMGData::readValue(QFile *file, T &val) const { T data; @@ -215,9 +215,9 @@ template bool IMGData::readValue(QFile &file, T &val) const return true; } -bool IMGData::readBlock(QFile &file, int blockNum, char *data) const +bool IMGData::readBlock(QFile *file, int blockNum, char *data) const { - if (!file.seek((quint64)blockNum << _blockBits)) + if (!file->seek((quint64)blockNum << _blockBits)) return false; if (read(file, data, 1ULL<<_blockBits) < (qint64)(1ULL<<_blockBits)) return false; diff --git a/src/map/IMG/imgdata.h b/src/map/IMG/imgdata.h index 5c651b6c..28826d4d 100644 --- a/src/map/IMG/imgdata.h +++ b/src/map/IMG/imgdata.h @@ -13,17 +13,17 @@ public: IMGData(const QString &fileName); unsigned blockBits() const {return _blockBits;} - bool readBlock(QFile &file, int blockNum, char *data) const; + bool readBlock(QFile *file, int blockNum, char *data) const; private: typedef QMap TileMap; - qint64 read(QFile &file, char *data, qint64 maxSize) const; - template bool readValue(QFile &file, T &val) const; - bool readSubFileBlocks(QFile &file, quint64 offset, SubFile *subFile); - bool readFAT(QFile &file, TileMap &tileMap); - bool readIMGHeader(QFile &file); - bool createTileTree(const TileMap &tileMap); + qint64 read(QFile *file, char *data, qint64 maxSize) const; + template bool readValue(QFile *file, T &val) const; + bool readSubFileBlocks(QFile *file, quint64 offset, SubFile *subFile); + bool readFAT(QFile *file, TileMap &tileMap); + bool readIMGHeader(QFile *file); + bool createTileTree(QFile *file, const TileMap &tileMap); quint8 _key; unsigned _blockBits; diff --git a/src/map/IMG/mapdata.cpp b/src/map/IMG/mapdata.cpp index 53ae01a0..68c031a5 100644 --- a/src/map/IMG/mapdata.cpp +++ b/src/map/IMG/mapdata.cpp @@ -13,7 +13,7 @@ using namespace IMG; bool MapData::polyCb(VectorTile *tile, void *context) { PolyCTX *ctx = (PolyCTX*)context; - tile->polys(ctx->rect, ctx->zoom, ctx->polygons, ctx->lines, + tile->polys(ctx->file, ctx->rect, ctx->zoom, ctx->polygons, ctx->lines, ctx->cache, ctx->lock); return true; } @@ -21,14 +21,16 @@ bool MapData::polyCb(VectorTile *tile, void *context) bool MapData::pointCb(VectorTile *tile, void *context) { PointCTX *ctx = (PointCTX*)context; - tile->points(ctx->rect, ctx->zoom, ctx->points, ctx->cache, ctx->lock); + tile->points(ctx->file, ctx->rect, ctx->zoom, ctx->points, ctx->cache, + ctx->lock); return true; } bool MapData::elevationCb(VectorTile *tile, void *context) { ElevationCTX *ctx = (ElevationCTX*)context; - tile->elevations(ctx->rect, ctx->zoom, ctx->elevations, ctx->cache, ctx->lock); + tile->elevations(ctx->file, ctx->rect, ctx->zoom, ctx->elevations, + ctx->cache, ctx->lock); return true; } @@ -50,10 +52,10 @@ MapData::~MapData() delete _style; } -void MapData::polys(const RectC &rect, int bits, QList *polygons, - QList *lines) +void MapData::polys(QFile *file, const RectC &rect, int bits, + QList *polygons, QList *lines) { - PolyCTX ctx(rect, zoom(bits), polygons, lines, &_polyCache, &_lock); + PolyCTX ctx(file, rect, zoom(bits), polygons, lines, &_polyCache, &_lock); double min[2], max[2]; min[0] = rect.left(); @@ -64,9 +66,10 @@ void MapData::polys(const RectC &rect, int bits, QList *polygons, _tileTree.Search(min, max, polyCb, &ctx); } -void MapData::points(const RectC &rect, int bits, QList *points) +void MapData::points(QFile *file, const RectC &rect, int bits, + QList *points) { - PointCTX ctx(rect, zoom(bits), points, &_pointCache, &_lock); + PointCTX ctx(file, rect, zoom(bits), points, &_pointCache, &_lock); double min[2], max[2]; min[0] = rect.left(); @@ -77,9 +80,10 @@ void MapData::points(const RectC &rect, int bits, QList *points) _tileTree.Search(min, max, pointCb, &ctx); } -void MapData::elevations(const RectC &rect, int bits, QList *elevations) +void MapData::elevations(QFile *file, const RectC &rect, int bits, + QList *elevations) { - ElevationCTX ctx(rect, zoom(bits), elevations, &_demCache, &_demLock); + ElevationCTX ctx(file, rect, zoom(bits), elevations, &_demCache, &_demLock); double min[2], max[2]; min[0] = rect.left(); @@ -95,14 +99,14 @@ void MapData::load(qreal ratio) Q_ASSERT(!_style); if (_typ) - _style = new Style(ratio, _typ); + _style = new Style(0, ratio, _typ); else { QString typFile(ProgramPaths::typFile()); if (QFileInfo::exists(typFile)) { SubFile typ(&typFile); - _style = new Style(ratio, &typ); + _style = new Style(0, ratio, &typ); } else - _style = new Style(ratio); + _style = new Style(0, ratio); } } diff --git a/src/map/IMG/mapdata.h b/src/map/IMG/mapdata.h index 4de46e76..a1cd688f 100644 --- a/src/map/IMG/mapdata.h +++ b/src/map/IMG/mapdata.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "common/rectc.h" #include "common/rtree.h" @@ -77,10 +78,11 @@ public: const RectC &bounds() const {return _bounds;} const Range &zooms() const {return _zoomLevels;} const Style *style() const {return _style;} - void polys(const RectC &rect, int bits, QList *polygons, + void polys(QFile *file, const RectC &rect, int bits, QList *polygons, QList *lines); - void points(const RectC &rect, int bits, QList *points); - void elevations(const RectC &rect, int bits, QList *elevations); + void points(QFile *file, const RectC &rect, int bits, QList *points); + void elevations(QFile *file, const RectC &rect, int bits, + QList *elevations); void load(qreal ratio); void clear(); @@ -122,12 +124,13 @@ private: struct PolyCTX { - PolyCTX(const RectC &rect, const Zoom &zoom, + PolyCTX(QFile *file, const RectC &rect, const Zoom &zoom, QList *polygons, QList *lines, PolyCache *cache, QMutex *lock) - : rect(rect), zoom(zoom), polygons(polygons), lines(lines), - cache(cache), lock(lock) {} + : file(file), rect(rect), zoom(zoom), polygons(polygons), + lines(lines), cache(cache), lock(lock) {} + QFile *file; const RectC ▭ const Zoom &zoom; QList *polygons; @@ -138,10 +141,12 @@ private: struct PointCTX { - PointCTX(const RectC &rect, const Zoom &zoom, + PointCTX(QFile *file, const RectC &rect, const Zoom &zoom, QList *points, PointCache *cache, QMutex *lock) - : rect(rect), zoom(zoom), points(points), cache(cache), lock(lock) {} + : file(file), rect(rect), zoom(zoom), points(points), cache(cache), + lock(lock) {} + QFile *file; const RectC ▭ const Zoom &zoom; QList *points; @@ -151,11 +156,12 @@ private: struct ElevationCTX { - ElevationCTX(const RectC &rect, const Zoom &zoom, + ElevationCTX(QFile *file, const RectC &rect, const Zoom &zoom, QList *elevations, ElevationCache *cache, QMutex *lock) - : rect(rect), zoom(zoom), elevations(elevations), cache(cache), - lock(lock) {} + : file(file), rect(rect), zoom(zoom), elevations(elevations), + cache(cache), lock(lock) {} + QFile *file; const RectC ▭ const Zoom &zoom; QList *elevations; diff --git a/src/map/IMG/rastertile.cpp b/src/map/IMG/rastertile.cpp index 7425cada..dd4c5b20 100644 --- a/src/map/IMG/rastertile.cpp +++ b/src/map/IMG/rastertile.cpp @@ -152,7 +152,7 @@ void RasterTile::drawPolygons(QPainter *painter, bool insert = false; SubFile::Handle *hdl = hc.object(poly.raster.lbl()); if (!hdl) { - hdl = new SubFile::Handle(poly.raster.lbl()); + hdl = new SubFile::Handle(_file, poly.raster.lbl()); insert = true; } QPixmap pm(poly.raster.lbl()->image(*hdl, poly.raster.id())); @@ -443,11 +443,16 @@ void RasterTile::fetchData(QList &polygons, { QPoint ttl(_rect.topLeft()); + if (dynamic_cast(_data)) { + _file = new QFile(_data->fileName()); + _file->open(QIODevice::ReadOnly | QIODevice::Unbuffered); + } + QRectF polyRect(ttl, QPointF(ttl.x() + _rect.width(), ttl.y() + _rect.height())); RectD polyRectD(_transform.img2proj(polyRect.topLeft()), _transform.img2proj(polyRect.bottomRight())); - _data->polys(polyRectD.toRectC(_proj, 20), _zoom, + _data->polys(_file, polyRectD.toRectC(_proj, 20), _zoom, &polygons, _vectors ? &lines : 0); if (_vectors) { @@ -456,7 +461,7 @@ void RasterTile::fetchData(QList &polygons, + TEXT_EXTENT)); RectD pointRectD(_transform.img2proj(pointRect.topLeft()), _transform.img2proj(pointRect.bottomRight())); - _data->points(pointRectD.toRectC(_proj, 20), _zoom, &points); + _data->points(_file, pointRectD.toRectC(_proj, 20), _zoom, &points); } } @@ -481,7 +486,7 @@ MatrixD RasterTile::elevation(int extend) const // Extra margin for always including the next DEM tile on the map tile // edges (the DEM tile resolution is usally 0.5-15% of the map tile) double factor = 6 - (_zoom - 24) * 1.7; - _data->elevations(rect.adjusted(0, 0, rect.width() / factor, + _data->elevations(_file, rect.adjusted(0, 0, rect.width() / factor, -rect.height() / factor), _zoom, &tiles); DEMTree tree(tiles); diff --git a/src/map/IMG/rastertile.h b/src/map/IMG/rastertile.h index 96871739..c394a841 100644 --- a/src/map/IMG/rastertile.h +++ b/src/map/IMG/rastertile.h @@ -22,7 +22,8 @@ public: bool hillShading, bool rasters, bool vectors) : _proj(proj), _transform(transform), _data(data), _zoom(zoom), _rect(rect), _ratio(ratio), _key(key), _hillShading(hillShading), - _rasters(rasters), _vectors(vectors) {} + _rasters(rasters), _vectors(vectors), _file(0) {} + ~RasterTile() {delete _file;} const QString &key() const {return _key;} QPoint xy() const {return _rect.topLeft();} @@ -88,6 +89,7 @@ private: QPixmap _pixmap; bool _hillShading; bool _rasters, _vectors; + QFile *_file; }; } diff --git a/src/map/IMG/style.cpp b/src/map/IMG/style.cpp index 372acb8a..6e56e81a 100644 --- a/src/map/IMG/style.cpp +++ b/src/map/IMG/style.cpp @@ -1268,50 +1268,50 @@ bool Style::parseDrawOrder(SubFile *file, SubFile::Handle &hdl, return true; } -bool Style::parseTYPFile(SubFile *file) +bool Style::parseTYPFile(QFile *file, SubFile *typ) { - SubFile::Handle hdl(file); + SubFile::Handle hdl(file, typ); Section points, lines, polygons, order; quint16 tmp16, codepage; - if (!(file->seek(hdl, 0x15) && file->readUInt16(hdl, codepage) - && file->readUInt32(hdl, points.offset) - && file->readUInt32(hdl, points.size) - && file->readUInt32(hdl, lines.offset) - && file->readUInt32(hdl, lines.size) - && file->readUInt32(hdl, polygons.offset) - && file->readUInt32(hdl, polygons.size))) + if (!(typ->seek(hdl, 0x15) && typ->readUInt16(hdl, codepage) + && typ->readUInt32(hdl, points.offset) + && typ->readUInt32(hdl, points.size) + && typ->readUInt32(hdl, lines.offset) + && typ->readUInt32(hdl, lines.size) + && typ->readUInt32(hdl, polygons.offset) + && typ->readUInt32(hdl, polygons.size))) return false; - if (!(file->readUInt16(hdl, tmp16) && file->readUInt16(hdl, tmp16))) + if (!(typ->readUInt16(hdl, tmp16) && typ->readUInt16(hdl, tmp16))) return false; - if (!(file->readUInt32(hdl, points.arrayOffset) - && file->readUInt16(hdl, points.arrayItemSize) - && file->readUInt32(hdl, points.arraySize) - && file->readUInt32(hdl, lines.arrayOffset) - && file->readUInt16(hdl, lines.arrayItemSize) - && file->readUInt32(hdl, lines.arraySize) - && file->readUInt32(hdl, polygons.arrayOffset) - && file->readUInt16(hdl, polygons.arrayItemSize) - && file->readUInt32(hdl, polygons.arraySize) - && file->readUInt32(hdl, order.arrayOffset) - && file->readUInt16(hdl, order.arrayItemSize) - && file->readUInt32(hdl, order.arraySize))) + if (!(typ->readUInt32(hdl, points.arrayOffset) + && typ->readUInt16(hdl, points.arrayItemSize) + && typ->readUInt32(hdl, points.arraySize) + && typ->readUInt32(hdl, lines.arrayOffset) + && typ->readUInt16(hdl, lines.arrayItemSize) + && typ->readUInt32(hdl, lines.arraySize) + && typ->readUInt32(hdl, polygons.arrayOffset) + && typ->readUInt16(hdl, polygons.arrayItemSize) + && typ->readUInt32(hdl, polygons.arraySize) + && typ->readUInt32(hdl, order.arrayOffset) + && typ->readUInt16(hdl, order.arrayItemSize) + && typ->readUInt32(hdl, order.arraySize))) return false; - if (!(parsePoints(file, hdl, points) && parseLines(file, hdl, lines) - && parsePolygons(file, hdl, polygons) - && parseDrawOrder(file, hdl, order))) { + if (!(parsePoints(typ, hdl, points) && parseLines(typ, hdl, lines) + && parsePolygons(typ, hdl, polygons) + && parseDrawOrder(typ, hdl, order))) { qWarning("%s: Invalid TYP file, using default style", - qPrintable(file->fileName())); + qPrintable(typ->fileName())); return false; } return true; } -Style::Style(qreal ratio, SubFile *typ) +Style::Style(QFile *file, qreal ratio, SubFile *typ) { _large = pixelSizeFont(16); _normal = pixelSizeFont(14); @@ -1326,7 +1326,7 @@ Style::Style(qreal ratio, SubFile *typ) defaultPointStyle(ratio); if (typ) - parseTYPFile(typ); + parseTYPFile(file, typ); } const Style::Line &Style::line(quint32 type) const diff --git a/src/map/IMG/style.h b/src/map/IMG/style.h index 9bfc47b1..1374083c 100644 --- a/src/map/IMG/style.h +++ b/src/map/IMG/style.h @@ -104,7 +104,7 @@ public: }; - Style(qreal ratio, SubFile *typ = 0); + Style(QFile *file, qreal ratio, SubFile *typ = 0); const Line &line(quint32 type) const; const Polygon &polygon(quint32 type) const; @@ -171,7 +171,7 @@ private: bool extended; }; - bool parseTYPFile(SubFile *file); + bool parseTYPFile(QFile *file, SubFile *typ); bool parsePoints(SubFile *file, SubFile::Handle &hdl, const Section §ion); bool parsePoint(SubFile *file, SubFile::Handle &hdl, diff --git a/src/map/IMG/subfile.cpp b/src/map/IMG/subfile.cpp index efdee7ab..90576774 100644 --- a/src/map/IMG/subfile.cpp +++ b/src/map/IMG/subfile.cpp @@ -27,9 +27,9 @@ bool SubFile::seek(Handle &handle, quint32 pos) const int blockNum = pos >> BLOCK_BITS; if (handle._blockNum != blockNum) { - if (!handle._file.seek((quint64)blockNum << BLOCK_BITS)) + if (!handle._file->seek((quint64)blockNum << BLOCK_BITS)) return false; - if (handle._file.read(handle._data.data(), (1<read(handle._data.data(), (1<fileName()); + _file->open(QIODevice::ReadOnly | QIODevice::Unbuffered); + _delete = true; + } _data.resize(subFile->blockSize()); - _file.setFileName(subFile->fileName()); - _file.open(QIODevice::ReadOnly | QIODevice::Unbuffered); + } + ~Handle() + { + if (_delete) + delete _file; } private: friend class SubFile; - QFile _file; + QFile *_file; QByteArray _data; int _blockNum; int _blockPos; int _pos; + bool _delete; }; SubFile(const IMGData *img) diff --git a/src/map/IMG/trefile.cpp b/src/map/IMG/trefile.cpp index 7385382b..959a6545 100644 --- a/src/map/IMG/trefile.cpp +++ b/src/map/IMG/trefile.cpp @@ -49,9 +49,9 @@ TREFile::~TREFile() clear(); } -bool TREFile::init() +bool TREFile::init(QFile *file) { - Handle hdl(this); + Handle hdl(file, this); quint8 locked, levels[64]; quint16 hdrLen; qint32 north, east, south, west; @@ -154,9 +154,9 @@ int TREFile::readExtEntry(Handle &hdl, quint32 &polygons, quint32 &lines, return rb; } -bool TREFile::load(int idx) +bool TREFile::load(QFile *file, int idx) { - Handle hdl(this); + Handle hdl(file, this); QList sl; SubDiv *s = 0; SubDivTree *tree = new SubDivTree(); @@ -282,7 +282,7 @@ void TREFile::clear() _subdivs.clear(); } -const TREFile::SubDivTree *TREFile::subdivs(const Zoom &zoom) +const TREFile::SubDivTree *TREFile::subdivs(QFile *file, const Zoom &zoom) { int idx = -1; @@ -296,7 +296,7 @@ const TREFile::SubDivTree *TREFile::subdivs(const Zoom &zoom) if (idx < 0) return 0; - if (!_subdivs.contains(_levels.at(idx).level) && !load(idx)) + if (!_subdivs.contains(_levels.at(idx).level) && !load(file, idx)) return 0; return _subdivs.value(_levels.at(idx).level); @@ -309,10 +309,10 @@ static bool cb(SubDiv *subdiv, void *context) return true; } -QList TREFile::subdivs(const RectC &rect, const Zoom &zoom) +QList TREFile::subdivs(QFile *file, const RectC &rect, const Zoom &zoom) { QList list; - const SubDivTree *tree = subdivs(zoom); + const SubDivTree *tree = subdivs(file, zoom); double min[2], max[2]; min[0] = rect.left(); diff --git a/src/map/IMG/trefile.h b/src/map/IMG/trefile.h index 0bc1cc6c..c309f365 100644 --- a/src/map/IMG/trefile.h +++ b/src/map/IMG/trefile.h @@ -24,11 +24,11 @@ public: : SubFile(gmp, offset), _flags(0), _extItemSize(0) {} ~TREFile(); - bool init(); + bool init(QFile *file); void clear(); const RectC &bounds() const {return _bounds;} - QList subdivs(const RectC &rect, const Zoom &zoom); + QList subdivs(QFile *file, const RectC &rect, const Zoom &zoom); quint32 shift(quint8 bits) const {return (bits == _levels.last().bits) ? (_flags >> 0xb) & 7 : 0;} QVector zooms() const; @@ -41,8 +41,8 @@ private: }; typedef RTree SubDivTree; - bool load(int idx); - const SubDivTree *subdivs(const Zoom &zoom); + bool load(QFile *file, int idx); + const SubDivTree *subdivs(QFile *file, const Zoom &zoom); int readExtEntry(Handle &hdl, quint32 &polygons, quint32 &lines, quint32 &points); diff --git a/src/map/IMG/vectortile.cpp b/src/map/IMG/vectortile.cpp index 19a83dd1..850a3f60 100644 --- a/src/map/IMG/vectortile.cpp +++ b/src/map/IMG/vectortile.cpp @@ -40,20 +40,20 @@ SubFile *VectorTile::file(SubFile::Type type) } } -bool VectorTile::init() +bool VectorTile::init(QFile *file) { - if (_gmp && !initGMP()) + if (_gmp && !initGMP(file)) return false; - if (!(_tre && _tre->init() && _rgn)) + if (!(_tre && _tre->init(file) && _rgn)) return false; return true; } -bool VectorTile::initGMP() +bool VectorTile::initGMP(QFile *file) { - SubFile::Handle hdl(_gmp); + SubFile::Handle hdl(file, _gmp); quint32 tre, rgn, lbl, net, nod, dem; if (!(_gmp->seek(hdl, 0x19) && _gmp->readUInt32(hdl, tre) @@ -118,7 +118,7 @@ void VectorTile::clear() _demLoaded = 0; } -void VectorTile::polys(const RectC &rect, const Zoom &zoom, +void VectorTile::polys(QFile *file, const RectC &rect, const Zoom &zoom, QList *polygons, QList *lines, MapData::PolyCache *cache, QMutex *lock) { @@ -133,10 +133,10 @@ void VectorTile::polys(const RectC &rect, const Zoom &zoom, } if (!_loaded) { - rgnHdl = new SubFile::Handle(_rgn); - lblHdl = new SubFile::Handle(_lbl); - netHdl = new SubFile::Handle(_net); - nodHdl = new SubFile::Handle(_nod); + rgnHdl = new SubFile::Handle(file, _rgn); + lblHdl = new SubFile::Handle(file, _lbl); + netHdl = new SubFile::Handle(file, _net); + nodHdl = new SubFile::Handle(file, _nod); if (!load(*rgnHdl, *lblHdl, *netHdl, *nodHdl)) { lock->unlock(); @@ -145,7 +145,7 @@ void VectorTile::polys(const RectC &rect, const Zoom &zoom, } } - QList subdivs = _tre->subdivs(rect, zoom); + QList subdivs = _tre->subdivs(file, rect, zoom); for (int i = 0; i < subdivs.size(); i++) { SubDiv *subdiv = subdivs.at(i); @@ -154,9 +154,9 @@ void VectorTile::polys(const RectC &rect, const Zoom &zoom, quint32 shift = _tre->shift(subdiv->bits()); if (!rgnHdl) { - rgnHdl = new SubFile::Handle(_rgn); - lblHdl = new SubFile::Handle(_lbl); - netHdl = new SubFile::Handle(_net); + rgnHdl = new SubFile::Handle(file, _rgn); + lblHdl = new SubFile::Handle(file, _lbl); + netHdl = new SubFile::Handle(file, _net); } if (!subdiv->initialized() && !_rgn->subdivInit(*rgnHdl, subdiv)) @@ -175,9 +175,9 @@ void VectorTile::polys(const RectC &rect, const Zoom &zoom, if (_net && _net->hasLinks()) { if (!nodHdl) - nodHdl = new SubFile::Handle(_nod); + nodHdl = new SubFile::Handle(file, _nod); if (!nodHdl2) - nodHdl2 = new SubFile::Handle(_nod); + nodHdl2 = new SubFile::Handle(file, _nod); _rgn->links(*rgnHdl, subdiv, shift, _net, *netHdl, _nod, *nodHdl, *nodHdl2, _lbl, *lblHdl, &polys->lines); } @@ -199,7 +199,7 @@ void VectorTile::polys(const RectC &rect, const Zoom &zoom, delete rgnHdl; delete lblHdl; delete netHdl; delete nodHdl; delete nodHdl2; } -void VectorTile::points(const RectC &rect, const Zoom &zoom, +void VectorTile::points(QFile *file, const RectC &rect, const Zoom &zoom, QList *points, MapData::PointCache *cache, QMutex *lock) { SubFile::Handle *rgnHdl = 0, *lblHdl = 0; @@ -212,10 +212,10 @@ void VectorTile::points(const RectC &rect, const Zoom &zoom, } if (!_loaded) { - rgnHdl = new SubFile::Handle(_rgn); - lblHdl = new SubFile::Handle(_lbl); - SubFile::Handle nodHdl(_nod); - SubFile::Handle netHdl(_net); + rgnHdl = new SubFile::Handle(file, _rgn); + lblHdl = new SubFile::Handle(file, _lbl); + SubFile::Handle nodHdl(file, _nod); + SubFile::Handle netHdl(file, _net); if (!load(*rgnHdl, *lblHdl, netHdl, nodHdl)) { lock->unlock(); @@ -224,15 +224,15 @@ void VectorTile::points(const RectC &rect, const Zoom &zoom, } } - QList subdivs = _tre->subdivs(rect, zoom); + QList subdivs = _tre->subdivs(file, rect, zoom); for (int i = 0; i < subdivs.size(); i++) { SubDiv *subdiv = subdivs.at(i); QList *pl = cache->object(subdiv); if (!pl) { if (!rgnHdl) { - rgnHdl = new SubFile::Handle(_rgn); - lblHdl = new SubFile::Handle(_lbl); + rgnHdl = new SubFile::Handle(file, _rgn); + lblHdl = new SubFile::Handle(file, _lbl); } if (!subdiv->initialized() && !_rgn->subdivInit(*rgnHdl, subdiv)) @@ -258,7 +258,7 @@ void VectorTile::points(const RectC &rect, const Zoom &zoom, delete rgnHdl; delete lblHdl; } -void VectorTile::elevations(const RectC &rect, const Zoom &zoom, +void VectorTile::elevations(QFile *file, const RectC &rect, const Zoom &zoom, QList *elevations, MapData::ElevationCache *cache, QMutex *lock) { @@ -272,7 +272,7 @@ void VectorTile::elevations(const RectC &rect, const Zoom &zoom, } if (!_demLoaded) { - hdl = new SubFile::Handle(_dem); + hdl = new SubFile::Handle(file, _dem); if (!loadDem(*hdl)) { lock->unlock(); @@ -293,7 +293,7 @@ void VectorTile::elevations(const RectC &rect, const Zoom &zoom, if (!el) { if (!hdl) - hdl = new SubFile::Handle(_dem); + hdl = new SubFile::Handle(file, _dem); el = _dem->elevations(*hdl, level, tile); if (!el->m.isNull()) diff --git a/src/map/IMG/vectortile.h b/src/map/IMG/vectortile.h index ca663460..6b9c2610 100644 --- a/src/map/IMG/vectortile.h +++ b/src/map/IMG/vectortile.h @@ -21,7 +21,7 @@ public: delete _dem; delete _gmp; } - bool init(); + bool init(QFile *file); void clear(); const RectC &bounds() const {return _tre->bounds();} @@ -30,12 +30,12 @@ public: SubFile *file(SubFile::Type type); - void polys(const RectC &rect, const Zoom &zoom, + void polys(QFile *file, const RectC &rect, const Zoom &zoom, QList *polygons, QList *lines, MapData::PolyCache *cache, QMutex *lock); - void points(const RectC &rect, const Zoom &zoom, + void points(QFile *file, const RectC &rect, const Zoom &zoom, QList *points, MapData::PointCache *cache, QMutex *lock); - void elevations(const RectC &rect, const Zoom &zoom, + void elevations(QFile *file, const RectC &rect, const Zoom &zoom, QList *elevations, MapData::ElevationCache *cache, QMutex *lock); @@ -78,7 +78,7 @@ public: } private: - bool initGMP(); + bool initGMP(QFile *file); bool load(SubFile::Handle &rgnHdl, SubFile::Handle &lblHdl, SubFile::Handle &netHdl, SubFile::Handle &nodHdl); bool loadDem(SubFile::Handle &demHdl); diff --git a/src/map/imgmap.cpp b/src/map/imgmap.cpp index d120ccf5..9410d555 100644 --- a/src/map/imgmap.cpp +++ b/src/map/imgmap.cpp @@ -276,7 +276,7 @@ double IMGMap::elevation(const Coordinates &c) if (d->hasDEM()) { QList tiles; - d->elevations(RectC(c, Coordinates(c.lon() + DELTA, c.lat() - DELTA)), + d->elevations(0, RectC(c, Coordinates(c.lon() + DELTA, c.lat() - DELTA)), d->zooms().max(), &tiles); DEMTree tree(tiles);