From f67eaa8decd47fc04ebb168b66a19d56acd858fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 12 Aug 2019 22:20:12 +0200 Subject: [PATCH] Various code cleanup --- src/map/IMG/img.cpp | 2 +- src/map/IMG/lblfile.cpp | 16 ++++++++++------ src/map/IMG/lblfile.h | 7 ++++--- src/map/IMG/netfile.cpp | 11 +++++------ src/map/IMG/netfile.h | 5 ++--- src/map/IMG/subfile.cpp | 4 ++-- src/map/IMG/subfile.h | 2 ++ src/map/IMG/vectortile.h | 6 ------ 8 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/map/IMG/img.cpp b/src/map/IMG/img.cpp index f6292343..a2aa18ba 100644 --- a/src/map/IMG/img.cpp +++ b/src/map/IMG/img.cpp @@ -91,7 +91,7 @@ IMG::IMG(const QString &fileName) } QString fn(QByteArray(name, sizeof(name))); - if (VectorTile::isTileFile(tt)) { + if (SubFile::isTileFile(tt)) { VectorTile *tile; QMap::iterator it = tileMap.find(fn); if (it == tileMap.end()) { diff --git a/src/map/IMG/lblfile.cpp b/src/map/IMG/lblfile.cpp index aa96a9aa..bf15b6fc 100644 --- a/src/map/IMG/lblfile.cpp +++ b/src/map/IMG/lblfile.cpp @@ -54,15 +54,18 @@ bool LBLFile::init() { Handle hdl; quint16 codepage; + quint8 multiplier, poiMultiplier; if (!(seek(hdl, 0x15) && readUInt32(hdl, _offset) - && readUInt32(hdl, _size) && readByte(hdl, _multiplier) + && readUInt32(hdl, _size) && readByte(hdl, multiplier) && readByte(hdl, _encoding) && seek(hdl, 0x57) && readUInt32(hdl, _poiOffset) && readUInt32(hdl, _poiSize) - && seek(hdl, 0xAA) && readUInt16(hdl, codepage))) + && readByte(hdl, poiMultiplier) && seek(hdl, 0xAA) + && readUInt16(hdl, codepage))) return false; - _multiplier = 1<<_multiplier; + _multiplier = 1<= offset * _poiMultiplier + && seek(hdl, _poiOffset + offset * _poiMultiplier) + && readUInt24(hdl, poiOffset) && (poiOffset & 0x3FFFFF))) return QString(); labelOffset = _offset + (poiOffset & 0x3FFFFF) * _multiplier; } else diff --git a/src/map/IMG/lblfile.h b/src/map/IMG/lblfile.h index 3ae3fd68..2dfbb334 100644 --- a/src/map/IMG/lblfile.h +++ b/src/map/IMG/lblfile.h @@ -10,8 +10,8 @@ class LBLFile : public SubFile { public: LBLFile(IMG *img, quint32 size) - : SubFile(img, size), _offset(0), _size(0), _poiOffset(0), _poiSize(0), - _multiplier(0), _encoding(0), _codec(0) {} + : SubFile(img, size), _codec(0), _offset(0), _size(0), _poiOffset(0), + _poiSize(0), _poiMultiplier(0), _multiplier(0), _encoding(0) {} Label label(Handle &hdl, quint32 offset, bool poi = false); @@ -21,13 +21,14 @@ private: Label label6b(Handle &hdl, quint32 offset) const; Label label8b(Handle &hdl, quint32 offset) const; + QTextCodec *_codec; quint32 _offset; quint32 _size; quint32 _poiOffset; quint32 _poiSize; + quint8 _poiMultiplier; quint8 _multiplier; quint8 _encoding; - QTextCodec *_codec; }; #endif // LBLFILE_H diff --git a/src/map/IMG/netfile.cpp b/src/map/IMG/netfile.cpp index 52d4e551..f9023fb3 100644 --- a/src/map/IMG/netfile.cpp +++ b/src/map/IMG/netfile.cpp @@ -3,22 +3,21 @@ bool NETFile::init() { Handle hdl; + quint8 multiplier; if (!(seek(hdl, 0x15) && readUInt32(hdl, _offset) - && readUInt32(hdl, _size) && readByte(hdl, _multiplier))) + && readUInt32(hdl, _size) && readByte(hdl, multiplier))) return false; - _multiplier = 1<<_multiplier; + _multiplier = 1<size(); + return _file ? (quint32)_file->size() : _size; } QString SubFile::fileName() const { - return _img ? _img->fileName() : _file->fileName(); + return _file ? _file->fileName() : _img->fileName(); } #ifndef QT_NO_DEBUG diff --git a/src/map/IMG/subfile.h b/src/map/IMG/subfile.h index c8c7fb8f..5d061f2f 100644 --- a/src/map/IMG/subfile.h +++ b/src/map/IMG/subfile.h @@ -84,6 +84,8 @@ public: QString fileName() const; static Type type(const char str[3]); + static bool isTileFile(Type type) + {return (type == TRE || type == LBL || type == RGN || type == NET);} friend QDebug operator<<(QDebug dbg, const SubFile &file); diff --git a/src/map/IMG/vectortile.h b/src/map/IMG/vectortile.h index 782d137a..e2ce6172 100644 --- a/src/map/IMG/vectortile.h +++ b/src/map/IMG/vectortile.h @@ -26,12 +26,6 @@ public: friend QDebug operator<<(QDebug dbg, const VectorTile &tile); - static bool isTileFile(SubFile::Type type) - { - return (type == SubFile::TRE || type == SubFile::LBL - || type == SubFile::RGN || type == SubFile::NET); - } - private: TREFile *_tre; RGNFile *_rgn;