mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Code cleanup/optimization
This commit is contained in:
parent
8bc575aef2
commit
33cb944e36
@ -30,17 +30,17 @@ static bool yCmp(const OfflineMap *m1, const OfflineMap *m2)
|
||||
return TL(m1).y() > TL(m2).y();
|
||||
}
|
||||
|
||||
bool Atlas::isAtlas(const QFileInfoList &files)
|
||||
bool Atlas::isAtlas(Tar &tar, const QFileInfoList &files)
|
||||
{
|
||||
for (int i = 0; i < files.count(); i++) {
|
||||
const QString &fileName = files.at(i).fileName();
|
||||
if (fileName.endsWith(".tar")) {
|
||||
if (!_tar.load(files.at(i).absoluteFilePath())) {
|
||||
if (!tar.load(files.at(i).absoluteFilePath())) {
|
||||
qWarning("%s: %s: error loading tar file", qPrintable(_name),
|
||||
qPrintable(fileName));
|
||||
return false;
|
||||
}
|
||||
QStringList tarFiles = _tar.files();
|
||||
QStringList tarFiles = tar.files();
|
||||
for (int j = 0; j < tarFiles.size(); j++)
|
||||
if (tarFiles.at(j).endsWith(".tba"))
|
||||
return true;
|
||||
@ -102,6 +102,8 @@ void Atlas::computeBounds()
|
||||
|
||||
Atlas::Atlas(const QString &path, QObject *parent) : Map(parent)
|
||||
{
|
||||
Tar tar;
|
||||
|
||||
_valid = false;
|
||||
_zoom = 0;
|
||||
|
||||
@ -110,7 +112,7 @@ Atlas::Atlas(const QString &path, QObject *parent) : Map(parent)
|
||||
|
||||
QDir dir(path);
|
||||
QFileInfoList files = dir.entryInfoList(QDir::Files);
|
||||
if (!isAtlas(files))
|
||||
if (!isAtlas(tar, files))
|
||||
return;
|
||||
|
||||
QFileInfoList layers = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
@ -120,8 +122,8 @@ Atlas::Atlas(const QString &path, QObject *parent) : Map(parent)
|
||||
| QDir::NoDotAndDotDot);
|
||||
for (int i = 0; i < maps.count(); i++) {
|
||||
OfflineMap *map;
|
||||
if (_tar.isOpen())
|
||||
map = new OfflineMap(_tar, maps.at(i).absoluteFilePath(), this);
|
||||
if (tar.isOpen())
|
||||
map = new OfflineMap(tar, maps.at(i).absoluteFilePath(), this);
|
||||
else
|
||||
map = new OfflineMap(maps.at(i).absoluteFilePath(), this);
|
||||
if (map->isValid())
|
||||
|
@ -33,14 +33,13 @@ public:
|
||||
|
||||
private:
|
||||
void draw(QPainter *painter, const QRectF &rect, int mapIndex);
|
||||
bool isAtlas(const QFileInfoList &files);
|
||||
bool isAtlas(Tar &tar, const QFileInfoList &files);
|
||||
void computeZooms();
|
||||
void computeBounds();
|
||||
|
||||
QString _name;
|
||||
bool _valid;
|
||||
|
||||
Tar _tar;
|
||||
QList<OfflineMap*> _maps;
|
||||
QVector<QPair<int, int> > _zooms;
|
||||
QVector<QPair<QRectF, QRectF> > _bounds;
|
||||
|
@ -226,6 +226,7 @@ bool OfflineMap::computeTransformation(const QList<ReferencePoint> &points)
|
||||
|
||||
_transform = QTransform(M.m(0,3), M.m(0,4), M.m(1,3), M.m(1,4), M.m(2,3),
|
||||
M.m(2,4));
|
||||
_inverted = _transform.inverted();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -571,28 +572,3 @@ void OfflineMap::draw(QPainter *painter, const QRectF &rect)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QPointF OfflineMap::ll2xy(const Coordinates &c) const
|
||||
{
|
||||
return _transform.map(_projection->ll2xy(c));
|
||||
}
|
||||
|
||||
Coordinates OfflineMap::xy2ll(const QPointF &p) const
|
||||
{
|
||||
return _projection->xy2ll(_transform.inverted().map(p));
|
||||
}
|
||||
|
||||
QPointF OfflineMap::ll2pp(const Coordinates &c) const
|
||||
{
|
||||
return _projection->ll2xy(c);
|
||||
}
|
||||
|
||||
QPointF OfflineMap::xy2pp(const QPointF &p) const
|
||||
{
|
||||
return _transform.inverted().map(p);
|
||||
}
|
||||
|
||||
QPointF OfflineMap::pp2xy(const QPointF &p) const
|
||||
{
|
||||
return _transform.map(p);
|
||||
}
|
||||
|
@ -5,10 +5,11 @@
|
||||
#include "map.h"
|
||||
#include "tar.h"
|
||||
#include "coordinates.h"
|
||||
#include "projection.h"
|
||||
|
||||
|
||||
class QIODevice;
|
||||
class QImage;
|
||||
class Projection;
|
||||
|
||||
class OfflineMap : public Map
|
||||
{
|
||||
@ -29,8 +30,10 @@ public:
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const;
|
||||
Coordinates xy2ll(const QPointF &p) const;
|
||||
QPointF ll2xy(const Coordinates &c) const
|
||||
{return _transform.map(_projection->ll2xy(c));}
|
||||
Coordinates xy2ll(const QPointF &p) const
|
||||
{return _projection->xy2ll(_inverted.map(p));}
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
||||
@ -39,9 +42,12 @@ public:
|
||||
|
||||
bool isValid() {return _valid;}
|
||||
|
||||
QPointF ll2pp(const Coordinates &c) const;
|
||||
QPointF xy2pp(const QPointF &p) const;
|
||||
QPointF pp2xy(const QPointF &p) const;
|
||||
QPointF ll2pp(const Coordinates &c) const
|
||||
{return _projection->ll2xy(c);}
|
||||
QPointF xy2pp(const QPointF &p) const
|
||||
{return _inverted.map(p);}
|
||||
QPointF pp2xy(const QPointF &p) const
|
||||
{return _transform.map(p);}
|
||||
|
||||
private:
|
||||
typedef struct {
|
||||
@ -75,7 +81,7 @@ private:
|
||||
QString _name;
|
||||
QSize _size;
|
||||
Projection *_projection;
|
||||
QTransform _transform;
|
||||
QTransform _transform, _inverted;
|
||||
qreal _resolution;
|
||||
|
||||
Tar _tar;
|
||||
|
Loading…
Reference in New Issue
Block a user