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