mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-18 19:52:09 +01:00
Code cleanup/optimizations
This commit is contained in:
parent
b1748c848b
commit
a56ad8a933
@ -20,12 +20,12 @@ static bool resCmp(const OfflineMap *m1, const OfflineMap *m2)
|
|||||||
return r1 > r2;
|
return r1 > r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool lonCmp(const OfflineMap *m1, const OfflineMap *m2)
|
static bool xCmp(const OfflineMap *m1, const OfflineMap *m2)
|
||||||
{
|
{
|
||||||
return TL(m1).x() < TL(m2).x();
|
return TL(m1).x() < TL(m2).x();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool latCmp(const OfflineMap *m1, const OfflineMap *m2)
|
static bool yCmp(const OfflineMap *m1, const OfflineMap *m2)
|
||||||
{
|
{
|
||||||
return TL(m1).y() > TL(m2).y();
|
return TL(m1).y() > TL(m2).y();
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ void Atlas::computeBounds()
|
|||||||
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++)
|
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++)
|
||||||
m.append(_maps.at(i));
|
m.append(_maps.at(i));
|
||||||
|
|
||||||
qSort(m.begin(), m.end(), lonCmp);
|
qSort(m.begin(), m.end(), xCmp);
|
||||||
offsets[_maps.indexOf(m.first())].setX(w);
|
offsets[_maps.indexOf(m.first())].setX(w);
|
||||||
for (int i = 1; i < m.size(); i++) {
|
for (int i = 1; i < m.size(); i++) {
|
||||||
if (TL(m.at(i)).x() > TL(m.at(i-1)).x()) {
|
if (TL(m.at(i)).x() > TL(m.at(i-1)).x()) {
|
||||||
@ -89,7 +89,7 @@ void Atlas::computeBounds()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qSort(m.begin(), m.end(), latCmp);
|
qSort(m.begin(), m.end(), yCmp);
|
||||||
offsets[_maps.indexOf(m.first())].setY(h);
|
offsets[_maps.indexOf(m.first())].setY(h);
|
||||||
for (int i = 1; i < m.size(); i++) {
|
for (int i = 1; i < m.size(); i++) {
|
||||||
if (TL(m.at(i)).y() < TL(m.at(i-1)).y()) {
|
if (TL(m.at(i)).y() < TL(m.at(i-1)).y()) {
|
||||||
@ -182,8 +182,7 @@ qreal Atlas::zoomFit(const QSize &size, const QRectF &br)
|
|||||||
|
|
||||||
for (int z = 0; z < _zooms.count(); z++) {
|
for (int z = 0; z < _zooms.count(); z++) {
|
||||||
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++) {
|
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++) {
|
||||||
if (_bounds.at(i).first.contains(_maps.at(i)->xy2pp(
|
if (_bounds.at(i).first.contains(_maps.at(i)->ll2pp(br.center())))
|
||||||
_maps.at(i)->ll2xy(br.center()))))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QRect sbr = QRectF(_maps.at(i)->ll2xy(br.topLeft()),
|
QRect sbr = QRectF(_maps.at(i)->ll2xy(br.topLeft()),
|
||||||
@ -218,8 +217,7 @@ QPointF Atlas::ll2xy(const Coordinates &c) const
|
|||||||
int idx = _zooms.at(_zoom).first;
|
int idx = _zooms.at(_zoom).first;
|
||||||
|
|
||||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||||
if (_bounds.at(i).first.contains(_maps.at(i)->xy2pp(
|
if (_bounds.at(i).first.contains(_maps.at(i)->ll2pp(c))) {
|
||||||
_maps.at(i)->ll2xy(c)))) {
|
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -246,14 +244,29 @@ Coordinates Atlas::xy2ll(const QPointF &p) const
|
|||||||
|
|
||||||
void Atlas::draw(QPainter *painter, const QRectF &rect)
|
void Atlas::draw(QPainter *painter, const QRectF &rect)
|
||||||
{
|
{
|
||||||
painter->fillRect(rect, Qt::white);
|
// All in one map
|
||||||
|
|
||||||
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||||
if (rect.intersects(_bounds.at(i).second)) {
|
|
||||||
OfflineMap *map = _maps.at(i);
|
|
||||||
QRectF ir = rect.intersected(_bounds.at(i).second);
|
QRectF ir = rect.intersected(_bounds.at(i).second);
|
||||||
const QPointF offset = _bounds.at(i).second.topLeft();
|
if (ir == rect) {
|
||||||
QRectF pr = QRectF(ir.topLeft() - offset, ir.size());
|
draw(painter, rect, i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiple maps
|
||||||
|
painter->fillRect(rect, Qt::white);
|
||||||
|
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
|
||||||
|
QRectF ir = rect.intersected(_bounds.at(i).second);
|
||||||
|
if (!ir.isNull())
|
||||||
|
draw(painter, ir, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Atlas::draw(QPainter *painter, const QRectF &rect, int mapIndex)
|
||||||
|
{
|
||||||
|
OfflineMap *map = _maps.at(mapIndex);
|
||||||
|
const QPointF offset = _bounds.at(mapIndex).second.topLeft();
|
||||||
|
QRectF pr = QRectF(rect.topLeft() - offset, rect.size());
|
||||||
|
|
||||||
map->load();
|
map->load();
|
||||||
|
|
||||||
@ -261,5 +274,3 @@ void Atlas::draw(QPainter *painter, const QRectF &rect)
|
|||||||
map->draw(painter, pr);
|
map->draw(painter, pr);
|
||||||
painter->translate(-offset);
|
painter->translate(-offset);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -31,6 +31,7 @@ public:
|
|||||||
bool isValid() {return _valid;}
|
bool isValid() {return _valid;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void draw(QPainter *painter, const QRectF &rect, int mapIndex);
|
||||||
bool isAtlas(const QFileInfoList &files);
|
bool isAtlas(const QFileInfoList &files);
|
||||||
void computeZooms();
|
void computeZooms();
|
||||||
void computeBounds();
|
void computeBounds();
|
||||||
|
@ -515,6 +515,11 @@ Coordinates OfflineMap::xy2ll(const QPointF &p) const
|
|||||||
return _projection->xy2ll(_transform.inverted().map(p));
|
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
|
QPointF OfflineMap::xy2pp(const QPointF &p) const
|
||||||
{
|
{
|
||||||
return _transform.inverted().map(p);
|
return _transform.inverted().map(p);
|
||||||
|
@ -38,6 +38,8 @@ public:
|
|||||||
void unload();
|
void unload();
|
||||||
|
|
||||||
bool isValid() {return _valid;}
|
bool isValid() {return _valid;}
|
||||||
|
|
||||||
|
QPointF ll2pp(const Coordinates &c) const;
|
||||||
QPointF xy2pp(const QPointF &p) const;
|
QPointF xy2pp(const QPointF &p) const;
|
||||||
QPointF pp2xy(const QPointF &p) const;
|
QPointF pp2xy(const QPointF &p) const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user