1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Some more cosmetic optimizations

This commit is contained in:
Martin Tůma 2018-10-05 07:10:49 +02:00
parent ed4e201b08
commit a7e02bdc8b
8 changed files with 21 additions and 12 deletions

View File

@ -18,7 +18,7 @@
#define MAX_DIGITAL_ZOOM 2 #define MAX_DIGITAL_ZOOM 2
#define MIN_DIGITAL_ZOOM -3 #define MIN_DIGITAL_ZOOM -3
#define MARGIN 10.0 #define MARGIN 10
#define SCALE_OFFSET 7 #define SCALE_OFFSET 7
MapView::MapView(Map *map, POI *poi, QWidget *parent) MapView::MapView(Map *map, POI *poi, QWidget *parent)

View File

@ -32,6 +32,8 @@ private:
double _lat, _lon; double _lat, _lon;
}; };
Q_DECLARE_TYPEINFO(Coordinates, Q_PRIMITIVE_TYPE);
inline bool operator==(const Coordinates &c1, const Coordinates &c2) inline bool operator==(const Coordinates &c1, const Coordinates &c2)
{return (c1.lat() == c2.lat() && c1.lon() == c2.lon());} {return (c1.lat() == c2.lat() && c1.lon() == c2.lon());}
inline bool operator!=(const Coordinates &c1, const Coordinates &c2) inline bool operator!=(const Coordinates &c1, const Coordinates &c2)

View File

@ -92,13 +92,17 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QPointF tl(floor(rect.left() / tileSize()) QPointF tl(floor(rect.left() / tileSize())
* tileSize(), floor(rect.top() / tileSize()) * tileSize()); * tileSize(), floor(rect.top() / tileSize()) * tileSize());
QList<Tile> tiles;
QSizeF s(qMin(rect.right() - tl.x(), b.width()), QSizeF s(qMin(rect.right() - tl.x(), b.width()),
qMin(rect.bottom() - tl.y(), b.height())); qMin(rect.bottom() - tl.y(), b.height()));
for (int i = 0; i < ceil(s.width() / tileSize()); i++) int width = ceil(s.width() / tileSize());
for (int j = 0; j < ceil(s.height() / tileSize()); j++) int height = ceil(s.height() / tileSize());
tiles.append(Tile(QPoint(tile.x() + i,
_invertY ? (1<<_zoom) - (tile.y() + j) - 1 : tile.y() + j), _zoom)); QVector<Tile> tiles;
tiles.reserve(width * height);
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
tiles.append(Tile(QPoint(tile.x() + i, _invertY ? (1<<_zoom)
- (tile.y() + j) - 1 : tile.y() + j), _zoom));
if (flags & Map::Block) if (flags & Map::Block)
_tileLoader->loadTilesSync(tiles); _tileLoader->loadTilesSync(tiles);

View File

@ -10,6 +10,7 @@
class Tile class Tile
{ {
public: public:
Tile() {}
Tile(const QPoint &xy, const QVariant &zoom, const RectD &bbox = RectD()) Tile(const QPoint &xy, const QVariant &zoom, const RectD &bbox = RectD())
{_xy = xy; _zoom = zoom; _bbox = bbox;} {_xy = xy; _zoom = zoom; _bbox = bbox;}

View File

@ -24,7 +24,7 @@ TileLoader::TileLoader(const QString &dir, QObject *parent)
connect(_downloader, SIGNAL(finished()), this, SIGNAL(finished())); connect(_downloader, SIGNAL(finished()), this, SIGNAL(finished()));
} }
void TileLoader::loadTilesAsync(QList<Tile> &list) void TileLoader::loadTilesAsync(QVector<Tile> &list)
{ {
QList<Download> dl; QList<Download> dl;
@ -48,7 +48,7 @@ void TileLoader::loadTilesAsync(QList<Tile> &list)
_downloader->get(dl, _authorization); _downloader->get(dl, _authorization);
} }
void TileLoader::loadTilesSync(QList<Tile> &list) void TileLoader::loadTilesSync(QVector<Tile> &list)
{ {
QList<Download> dl; QList<Download> dl;

View File

@ -17,8 +17,8 @@ public:
void setAuthorization(const Authorization &authorization) void setAuthorization(const Authorization &authorization)
{_authorization = authorization;} {_authorization = authorization;}
void loadTilesAsync(QList<Tile> &list); void loadTilesAsync(QVector<Tile> &list);
void loadTilesSync(QList<Tile> &list); void loadTilesSync(QVector<Tile> &list);
void clearCache(); void clearCache();
signals: signals:

View File

@ -193,7 +193,8 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QPoint br = QPoint((int)ceil(rect.right() / tileSize()), QPoint br = QPoint((int)ceil(rect.right() / tileSize()),
(int)ceil(rect.bottom() / tileSize())); (int)ceil(rect.bottom() / tileSize()));
QList<Tile> tiles; QVector<Tile> tiles;
tiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
for (int i = tl.x(); i < br.x(); i++) { for (int i = tl.x(); i < br.x(); i++) {
for (int j = tl.y(); j < br.y(); j++) { for (int j = tl.y(); j < br.y(); j++) {
PointD ttl(_transform.img2proj(QPointF(i * TILE_SIZE, PointD ttl(_transform.img2proj(QPointF(i * TILE_SIZE,

View File

@ -173,7 +173,8 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QPoint br = QPoint((int)ceil(rect.right() / ts.width()), QPoint br = QPoint((int)ceil(rect.right() / ts.width()),
(int)ceil(rect.bottom() / ts.height())); (int)ceil(rect.bottom() / ts.height()));
QList<Tile> tiles; QVector<Tile> tiles;
tiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
for (int i = tl.x(); i < br.x(); i++) for (int i = tl.x(); i < br.x(); i++)
for (int j = tl.y(); j < br.y(); j++) for (int j = tl.y(); j < br.y(); j++)
tiles.append(Tile(QPoint(i, j), z.id())); tiles.append(Tile(QPoint(i, j), z.id()));