From 992fd2c5cdab172618529cc79dd4f78cfd4a58bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 21 Mar 2018 19:09:37 +0100 Subject: [PATCH] Code cleanup --- src/map/mapfile.cpp | 14 ++++++-------- src/map/mapfile.h | 4 +++- src/map/offlinemap.cpp | 20 +++++++++----------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/map/mapfile.cpp b/src/map/mapfile.cpp index 8fc07bd6..f17ff0f3 100644 --- a/src/map/mapfile.cpp +++ b/src/map/mapfile.cpp @@ -128,7 +128,7 @@ int MapFile::parse(QIODevice &device, QList &points, ln++; } - return (ln == 1) ? 1 : 0; + return (ln < 9) ? ln : 0; } bool MapFile::parseMapFile(QIODevice &device, QList &points, @@ -249,7 +249,7 @@ bool MapFile::computeTransformation(QList &points) return true; } -bool MapFile::load(QIODevice &file) +MapFile::MapFile(QIODevice &file) { QList points; QString ct, datum; @@ -257,13 +257,11 @@ bool MapFile::load(QIODevice &file) const GCS *gcs; if (!parseMapFile(file, points, ct, setup, datum)) - return false; + return; if (!(gcs = createGCS(datum))) - return false; + return; if (!createProjection(gcs, ct, setup, points)) - return false; + return; if (!computeTransformation(points)) - return false; - - return true; + _image = QString(); } diff --git a/src/map/mapfile.h b/src/map/mapfile.h index 8daeae68..1e69d751 100644 --- a/src/map/mapfile.h +++ b/src/map/mapfile.h @@ -11,7 +11,9 @@ class QIODevice; class MapFile { public: - bool load(QIODevice &file); + MapFile(QIODevice &file); + + bool isValid() const {return !_image.isNull() && _projection.isValid();} const QString &errorString() const {return _errorString;} const Projection &projection() const {return _projection;} diff --git a/src/map/offlinemap.cpp b/src/map/offlinemap.cpp index 322344ca..68eea6b2 100644 --- a/src/map/offlinemap.cpp +++ b/src/map/offlinemap.cpp @@ -113,9 +113,9 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent) _errorString = "Map file not found"; return; } - QBuffer mapFile(&ba); - MapFile mf; - if (!mf.load(mapFile)) { + QBuffer buffer(&ba); + MapFile mf(buffer); + if (!mf.isValid()) { _errorString = mf.errorString(); return; } else { @@ -126,9 +126,9 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent) _transform = mf.transform(); } } else if (suffix == "map") { - MapFile mf; - QFile mapFile(fileName); - if (!mf.load(mapFile)) { + QFile file(fileName); + MapFile mf(file); + if (!mf.isValid()) { _errorString = mf.errorString(); return; } else { @@ -177,21 +177,19 @@ OfflineMap::OfflineMap(const QString &fileName, Tar &tar, QObject *parent) : Map(parent), _img(0), _tar(0), _ozf(0), _zoom(0), _valid(false) { QFileInfo fi(fileName); - MapFile mf; - - QFileInfo map(fi.absolutePath()); QFileInfo layer(map.absolutePath()); QString mapFile = layer.fileName() + "/" + map.fileName() + "/" + fi.fileName(); + QByteArray ba = tar.file(mapFile); if (ba.isNull()) { _errorString = "Map file not found"; return; } QBuffer buffer(&ba); - - if (!mf.load(buffer)) { + MapFile mf(buffer); + if (!mf.isValid()) { _errorString = mf.errorString(); return; }