mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 19:55:53 +01:00
Code cleanup
This commit is contained in:
parent
3c3fb43993
commit
90dcda217e
@ -2,6 +2,7 @@
|
|||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QRegExp>
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "common/wgs84.h"
|
#include "common/wgs84.h"
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
@ -13,7 +14,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#define MAGIC "CompeGPSRasterImage"
|
#define MAGIC "CompeGPSRasterImage"
|
||||||
#define strsize(str) (sizeof(str) - 1)
|
#define CHECK(condition) \
|
||||||
|
if (!(condition)) { \
|
||||||
|
_errorString = "Invalid/corrupted RMap file"; \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
class CalibrationPoint {
|
class CalibrationPoint {
|
||||||
public:
|
public:
|
||||||
@ -92,6 +97,7 @@ bool RMap::parseIMP(const QByteArray &data)
|
|||||||
QList<CalibrationPoint> cp;
|
QList<CalibrationPoint> cp;
|
||||||
const GCS *gcs = 0;
|
const GCS *gcs = 0;
|
||||||
QString projection, datum;
|
QString projection, datum;
|
||||||
|
QRegExp re("^P[0-9]+=");
|
||||||
|
|
||||||
for (int i = 0; i < lines.count(); i++) {
|
for (int i = 0; i < lines.count(); i++) {
|
||||||
const QString &line = lines.at(i);
|
const QString &line = lines.at(i);
|
||||||
@ -100,8 +106,7 @@ bool RMap::parseIMP(const QByteArray &data)
|
|||||||
projection = line.split("=").at(1);
|
projection = line.split("=").at(1);
|
||||||
else if (line.startsWith("Datum="))
|
else if (line.startsWith("Datum="))
|
||||||
datum = line.split("=").at(1);
|
datum = line.split("=").at(1);
|
||||||
else if (line.startsWith("P0=") || line.startsWith("P1=")
|
else if (line.contains(re)) {
|
||||||
|| line.startsWith("P2=") || line.startsWith("P3=")) {
|
|
||||||
QString point(line.split("=").at(1));
|
QString point(line.split("=").at(1));
|
||||||
cp.append(parseCalibrationPoint(point));
|
cp.append(parseCalibrationPoint(point));
|
||||||
}
|
}
|
||||||
@ -130,26 +135,6 @@ bool RMap::parseIMP(const QByteArray &data)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RMap::ok(const QDataStream &stream)
|
|
||||||
{
|
|
||||||
if (stream.status() != QDataStream::Ok) {
|
|
||||||
_errorString = "Invalid/corrupted RMap file";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RMap::seek(QFile &file, quint64 offset)
|
|
||||||
{
|
|
||||||
if (!file.seek(offset)) {
|
|
||||||
_errorString = "Invalid/corrupted RMap file";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
RMap::RMap(const QString &fileName, QObject *parent)
|
RMap::RMap(const QString &fileName, QObject *parent)
|
||||||
: Map(parent), _mapRatio(1.0), _fileName(fileName), _zoom(0), _valid(false)
|
: Map(parent), _mapRatio(1.0), _fileName(fileName), _zoom(0), _valid(false)
|
||||||
{
|
{
|
||||||
@ -162,7 +147,7 @@ RMap::RMap(const QString &fileName, QObject *parent)
|
|||||||
QDataStream stream(&file);
|
QDataStream stream(&file);
|
||||||
stream.setByteOrder(QDataStream::LittleEndian);
|
stream.setByteOrder(QDataStream::LittleEndian);
|
||||||
|
|
||||||
char magic[strsize(MAGIC)];
|
char magic[sizeof(MAGIC) - 1];
|
||||||
if (stream.readRawData(magic, sizeof(magic)) != sizeof(magic)
|
if (stream.readRawData(magic, sizeof(magic)) != sizeof(magic)
|
||||||
|| memcmp(MAGIC, magic, sizeof(magic))) {
|
|| memcmp(MAGIC, magic, sizeof(magic))) {
|
||||||
_errorString = "Not a raster RMap file";
|
_errorString = "Not a raster RMap file";
|
||||||
@ -181,21 +166,18 @@ RMap::RMap(const QString &fileName, QObject *parent)
|
|||||||
stream >> tmp;
|
stream >> tmp;
|
||||||
qint32 zoomCount;
|
qint32 zoomCount;
|
||||||
stream >> zoomCount;
|
stream >> zoomCount;
|
||||||
if (!ok(stream))
|
CHECK(stream.status() == QDataStream::Ok);
|
||||||
return;
|
|
||||||
|
|
||||||
QVector<quint64> zoomOffsets(zoomCount);
|
QVector<quint64> zoomOffsets(zoomCount);
|
||||||
for (int i = 0; i < zoomCount; i++)
|
for (int i = 0; i < zoomCount; i++)
|
||||||
stream >> zoomOffsets[i];
|
stream >> zoomOffsets[i];
|
||||||
if (!ok(stream))
|
CHECK(stream.status() == QDataStream::Ok);
|
||||||
return;
|
|
||||||
|
|
||||||
for (int i = 0; i < zoomOffsets.size(); i++) {
|
for (int i = 0; i < zoomOffsets.size(); i++) {
|
||||||
_zooms.append(Zoom());
|
_zooms.append(Zoom());
|
||||||
Zoom &zoom = _zooms.last();
|
Zoom &zoom = _zooms.last();
|
||||||
|
|
||||||
if (!seek(file, zoomOffsets.at(i)))
|
CHECK(file.seek(zoomOffsets.at(i)));
|
||||||
return;
|
|
||||||
|
|
||||||
quint32 width, height;
|
quint32 width, height;
|
||||||
stream >> width >> height;
|
stream >> width >> height;
|
||||||
@ -204,22 +186,18 @@ RMap::RMap(const QString &fileName, QObject *parent)
|
|||||||
zoom.dim = QSize(width, height);
|
zoom.dim = QSize(width, height);
|
||||||
zoom.scale = QPointF((qreal)zoom.size.width() / (qreal)imageSize.width(),
|
zoom.scale = QPointF((qreal)zoom.size.width() / (qreal)imageSize.width(),
|
||||||
(qreal)zoom.size.height() / (qreal)imageSize.height());
|
(qreal)zoom.size.height() / (qreal)imageSize.height());
|
||||||
if (!ok(stream))
|
CHECK(stream.status() == QDataStream::Ok);
|
||||||
return;
|
|
||||||
|
|
||||||
zoom.tiles.resize(zoom.dim.width() * zoom.dim.height());
|
zoom.tiles.resize(zoom.dim.width() * zoom.dim.height());
|
||||||
for (int j = 0; j < zoom.tiles.size(); j++)
|
for (int j = 0; j < zoom.tiles.size(); j++)
|
||||||
stream >> zoom.tiles[j];
|
stream >> zoom.tiles[j];
|
||||||
if (!ok(stream))
|
CHECK(stream.status() == QDataStream::Ok);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!seek(file, IMPOffset))
|
CHECK(file.seek(IMPOffset));
|
||||||
return;
|
|
||||||
quint32 IMPSize;
|
quint32 IMPSize;
|
||||||
stream >> tmp >> IMPSize;
|
stream >> tmp >> IMPSize;
|
||||||
if (!ok(stream))
|
CHECK(stream.status() == QDataStream::Ok);
|
||||||
return;
|
|
||||||
|
|
||||||
QByteArray IMP(IMPSize + 1, 0);
|
QByteArray IMP(IMPSize + 1, 0);
|
||||||
stream.readRawData(IMP.data(), IMP.size());
|
stream.readRawData(IMP.data(), IMP.size());
|
||||||
|
@ -43,8 +43,6 @@ private:
|
|||||||
QVector<quint64> tiles;
|
QVector<quint64> tiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ok(const QDataStream &stream);
|
|
||||||
bool seek(QFile &file, quint64 offset);
|
|
||||||
bool parseIMP(const QByteArray &data);
|
bool parseIMP(const QByteArray &data);
|
||||||
QPixmap tile(int x, int y);
|
QPixmap tile(int x, int y);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user