mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Code cleanup
This commit is contained in:
parent
90c1e52fb5
commit
97fdcfdd74
@ -5,31 +5,12 @@
|
||||
#include <QBuffer>
|
||||
#include <QtConcurrent>
|
||||
#include "osm.h"
|
||||
#include "tile.h"
|
||||
#include "aqmmap.h"
|
||||
|
||||
|
||||
#define MAGIC "FLATPACK1"
|
||||
|
||||
class AQTile
|
||||
{
|
||||
public:
|
||||
AQTile(const QPoint &xy, const QByteArray &data, const QString &key)
|
||||
: _xy(xy), _data(data), _key(key) {}
|
||||
|
||||
const QPoint &xy() const {return _xy;}
|
||||
const QString &key() const {return _key;}
|
||||
const QPixmap &pixmap() const {return _pixmap;}
|
||||
|
||||
void load() {_pixmap.loadFromData(_data);}
|
||||
|
||||
private:
|
||||
QPoint _xy;
|
||||
QByteArray _data;
|
||||
QString _key;
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
||||
|
||||
static bool parseHeader(const QByteArray &data, QString &name)
|
||||
{
|
||||
QList<QByteArray> lines = data.split('\n');
|
||||
@ -380,7 +361,7 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
int height = ceil(s.height() / tileSize());
|
||||
|
||||
|
||||
QList<AQTile> tiles;
|
||||
QList<RenderTile> tiles;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
@ -395,16 +376,16 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
* tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
} else {
|
||||
tiles.append(AQTile(t, tileData(t), key));
|
||||
tiles.append(RenderTile(t, tileData(t), key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &AQTile::load);
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
const AQTile &mt = tiles.at(i);
|
||||
const RenderTile &mt = tiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
@ -108,11 +108,11 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
int width = _zoom ? qCeil(s.width() / tileSize()) : 1;
|
||||
int height = _zoom ? qCeil(s.height() / tileSize()) : 1;
|
||||
|
||||
QVector<Tile> tiles;
|
||||
QVector<FetchTile> 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)
|
||||
tiles.append(FetchTile(QPoint(tile.x() + i, _invertY ? (1<<_zoom)
|
||||
- (tile.y() + j) - 1 : tile.y() + j), _zoom));
|
||||
|
||||
if (flags & Map::Block)
|
||||
@ -121,7 +121,7 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
_tileLoader->loadTilesAsync(tiles);
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
Tile &t = tiles[i];
|
||||
FetchTile &t = tiles[i];
|
||||
QPointF tp = _zoom ? QPointF(tl.x() + (t.xy().x() - tile.x())
|
||||
* tileSize(), tl.y() + ((_invertY ? (1<<_zoom) - t.xy().y() - 1 :
|
||||
t.xy().y()) - tile.y()) * tileSize())
|
||||
|
@ -7,31 +7,12 @@
|
||||
#include <QBuffer>
|
||||
#include <QtConcurrent>
|
||||
#include "osm.h"
|
||||
#include "tile.h"
|
||||
#include "osmdroidmap.h"
|
||||
|
||||
|
||||
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
||||
|
||||
class OsmdroidTile
|
||||
{
|
||||
public:
|
||||
OsmdroidTile(const QPoint &xy, const QByteArray &data, const QString &key)
|
||||
: _xy(xy), _data(data), _key(key) {}
|
||||
|
||||
const QPoint &xy() const {return _xy;}
|
||||
const QString &key() const {return _key;}
|
||||
const QPixmap &pixmap() const {return _pixmap;}
|
||||
|
||||
void load() {_pixmap.loadFromData(_data);}
|
||||
|
||||
private:
|
||||
QPoint _xy;
|
||||
QByteArray _data;
|
||||
QString _key;
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
||||
|
||||
OsmdroidMap::OsmdroidMap(const QString &fileName, QObject *parent)
|
||||
: Map(fileName, parent), _mapRatio(1.0), _valid(false)
|
||||
{
|
||||
@ -268,7 +249,7 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
int height = ceil(s.height() / tileSize());
|
||||
|
||||
|
||||
QList<OsmdroidTile> tiles;
|
||||
QList<RenderTile> tiles;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
@ -283,16 +264,16 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
* tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
} else {
|
||||
tiles.append(OsmdroidTile(t, tileData(_zoom, t), key));
|
||||
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &OsmdroidTile::load);
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
const OsmdroidTile &mt = tiles.at(i);
|
||||
const RenderTile &mt = tiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
@ -7,31 +7,12 @@
|
||||
#include <QBuffer>
|
||||
#include <QtConcurrent>
|
||||
#include "osm.h"
|
||||
#include "tile.h"
|
||||
#include "sqlitemap.h"
|
||||
|
||||
|
||||
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
||||
|
||||
class SqliteTile
|
||||
{
|
||||
public:
|
||||
SqliteTile(const QPoint &xy, const QByteArray &data, const QString &key)
|
||||
: _xy(xy), _data(data), _key(key) {}
|
||||
|
||||
const QPoint &xy() const {return _xy;}
|
||||
const QString &key() const {return _key;}
|
||||
const QPixmap &pixmap() const {return _pixmap;}
|
||||
|
||||
void load() {_pixmap.loadFromData(_data);}
|
||||
|
||||
private:
|
||||
QPoint _xy;
|
||||
QByteArray _data;
|
||||
QString _key;
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
||||
|
||||
SqliteMap::SqliteMap(const QString &fileName, QObject *parent)
|
||||
: Map(fileName, parent), _mapRatio(1.0), _valid(false)
|
||||
{
|
||||
@ -215,7 +196,7 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
int height = ceil(s.height() / tileSize());
|
||||
|
||||
|
||||
QList<SqliteTile> tiles;
|
||||
QList<RenderTile> tiles;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
@ -230,16 +211,16 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
* tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
} else {
|
||||
tiles.append(SqliteTile(t, tileData(_zoom, t), key));
|
||||
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &SqliteTile::load);
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
const SqliteTile &mt = tiles.at(i);
|
||||
const RenderTile &mt = tiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
@ -7,11 +7,11 @@
|
||||
#include <QDebug>
|
||||
#include "rectd.h"
|
||||
|
||||
class Tile
|
||||
class FetchTile
|
||||
{
|
||||
public:
|
||||
Tile() {}
|
||||
Tile(const QPoint &xy, const QVariant &zoom, const RectD &bbox = RectD())
|
||||
FetchTile() {}
|
||||
FetchTile(const QPoint &xy, const QVariant &zoom, const RectD &bbox = RectD())
|
||||
: _xy(xy), _zoom(zoom), _bbox(bbox) {}
|
||||
|
||||
const QVariant &zoom() const {return _zoom;}
|
||||
@ -26,8 +26,27 @@ private:
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
||||
class RenderTile
|
||||
{
|
||||
public:
|
||||
RenderTile(const QPoint &xy, const QByteArray &data, const QString &key)
|
||||
: _xy(xy), _data(data), _key(key) {}
|
||||
|
||||
const QPoint &xy() const {return _xy;}
|
||||
const QString &key() const {return _key;}
|
||||
const QPixmap &pixmap() const {return _pixmap;}
|
||||
|
||||
void load() {_pixmap.loadFromData(_data);}
|
||||
|
||||
private:
|
||||
QPoint _xy;
|
||||
QByteArray _data;
|
||||
QString _key;
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
inline QDebug operator<<(QDebug dbg, const Tile &tile)
|
||||
inline QDebug operator<<(QDebug dbg, const FetchTile &tile)
|
||||
{
|
||||
dbg.nospace() << "Tile(" << tile.zoom() << ", " << tile.xy() << ", "
|
||||
<< tile.bbox() << ")";
|
||||
|
@ -11,30 +11,27 @@ class TileImage
|
||||
{
|
||||
public:
|
||||
TileImage() : _tile(0), _scaledSize(0) {}
|
||||
TileImage(const QString &file, Tile *tile, int scaledSize)
|
||||
TileImage(const QString &file, FetchTile *tile, int scaledSize)
|
||||
: _file(file), _tile(tile), _scaledSize(scaledSize) {}
|
||||
|
||||
void createPixmap()
|
||||
{
|
||||
_tile->pixmap().convertFromImage(_image);
|
||||
}
|
||||
void load()
|
||||
{
|
||||
QImage img;
|
||||
QByteArray z(_tile->zoom().toString().toLatin1());
|
||||
QImageReader reader(_file, z);
|
||||
if (_scaledSize)
|
||||
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
|
||||
reader.read(&_image);
|
||||
reader.read(&img);
|
||||
_tile->pixmap().convertFromImage(img);
|
||||
}
|
||||
|
||||
const QString &file() const {return _file;}
|
||||
Tile *tile() {return _tile;}
|
||||
FetchTile *tile() {return _tile;}
|
||||
|
||||
private:
|
||||
QString _file;
|
||||
Tile *_tile;
|
||||
FetchTile *_tile;
|
||||
int _scaledSize;
|
||||
QImage _image;
|
||||
};
|
||||
|
||||
static QString quadKey(const QPoint &xy, int zoom)
|
||||
@ -64,13 +61,13 @@ TileLoader::TileLoader(const QString &dir, QObject *parent)
|
||||
connect(_downloader, &Downloader::finished, this, &TileLoader::finished);
|
||||
}
|
||||
|
||||
void TileLoader::loadTilesAsync(QVector<Tile> &list)
|
||||
void TileLoader::loadTilesAsync(QVector<FetchTile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
QList<TileImage> imgs;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
FetchTile &t = list[i];
|
||||
QString file(tileFile(t));
|
||||
|
||||
if (QPixmapCache::find(file, &t.pixmap()))
|
||||
@ -97,19 +94,18 @@ void TileLoader::loadTilesAsync(QVector<Tile> &list)
|
||||
|
||||
for (int i = 0; i < imgs.size(); i++) {
|
||||
TileImage &ti = imgs[i];
|
||||
ti.createPixmap();
|
||||
QPixmapCache::insert(ti.file(), ti.tile()->pixmap());
|
||||
}
|
||||
}
|
||||
|
||||
void TileLoader::loadTilesSync(QVector<Tile> &list)
|
||||
void TileLoader::loadTilesSync(QVector<FetchTile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
QList<Tile *> tl;
|
||||
QList<FetchTile *> tl;
|
||||
QList<TileImage> imgs;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Tile &t = list[i];
|
||||
FetchTile &t = list[i];
|
||||
QString file(tileFile(t));
|
||||
|
||||
if (QPixmapCache::find(file, &t.pixmap()))
|
||||
@ -137,7 +133,7 @@ void TileLoader::loadTilesSync(QVector<Tile> &list)
|
||||
wait.exec();
|
||||
|
||||
for (int i = 0; i < tl.size(); i++) {
|
||||
Tile *t = tl[i];
|
||||
FetchTile *t = tl[i];
|
||||
QString file = tileFile(*t);
|
||||
if (QFileInfo(file).exists())
|
||||
imgs.append(TileImage(file, t, _scaledSize));
|
||||
@ -146,9 +142,6 @@ void TileLoader::loadTilesSync(QVector<Tile> &list)
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(imgs, &TileImage::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < imgs.size(); i++)
|
||||
imgs[i].createPixmap();
|
||||
}
|
||||
|
||||
void TileLoader::clearCache()
|
||||
@ -173,7 +166,7 @@ void TileLoader::setScaledSize(int size)
|
||||
QPixmapCache::clear();
|
||||
}
|
||||
|
||||
QUrl TileLoader::tileUrl(const Tile &tile) const
|
||||
QUrl TileLoader::tileUrl(const FetchTile &tile) const
|
||||
{
|
||||
QString url(_url);
|
||||
|
||||
@ -195,7 +188,7 @@ QUrl TileLoader::tileUrl(const Tile &tile) const
|
||||
return QUrl(url);
|
||||
}
|
||||
|
||||
QString TileLoader::tileFile(const Tile &tile) const
|
||||
QString TileLoader::tileFile(const FetchTile &tile) const
|
||||
{
|
||||
return _dir + QLatin1Char('/') + tile.zoom().toString() + QLatin1Char('-')
|
||||
+ QString::number(tile.xy().x()) + QLatin1Char('-')
|
||||
|
@ -19,16 +19,16 @@ public:
|
||||
void setScaledSize(int size);
|
||||
void setQuadTiles(bool quadTiles) {_quadTiles = quadTiles;}
|
||||
|
||||
void loadTilesAsync(QVector<Tile> &list);
|
||||
void loadTilesSync(QVector<Tile> &list);
|
||||
void loadTilesAsync(QVector<FetchTile> &list);
|
||||
void loadTilesSync(QVector<FetchTile> &list);
|
||||
void clearCache();
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
private:
|
||||
QUrl tileUrl(const Tile &tile) const;
|
||||
QString tileFile(const Tile &tile) const;
|
||||
QUrl tileUrl(const FetchTile &tile) const;
|
||||
QString tileFile(const FetchTile &tile) const;
|
||||
|
||||
Downloader *_downloader;
|
||||
QString _url;
|
||||
|
@ -174,7 +174,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
QPoint br = QPoint(qCeil(rect.right() / tileSize()),
|
||||
qCeil(rect.bottom() / tileSize()));
|
||||
|
||||
QVector<Tile> tiles;
|
||||
QVector<FetchTile> tiles;
|
||||
tiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
||||
for (int i = tl.x(); i < br.x(); i++) {
|
||||
for (int j = tl.y(); j < br.y(); j++) {
|
||||
@ -186,7 +186,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
? RectD(PointD(tbr.y(), tbr.x()), PointD(ttl.y(), ttl.x()))
|
||||
: RectD(ttl, tbr);
|
||||
|
||||
tiles.append(Tile(QPoint(i, j), _zoom, bbox));
|
||||
tiles.append(FetchTile(QPoint(i, j), _zoom, bbox));
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
_tileLoader->loadTilesAsync(tiles);
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
Tile &t = tiles[i];
|
||||
FetchTile &t = tiles[i];
|
||||
QPointF tp(t.xy().x() * tileSize(), t.xy().y() * tileSize());
|
||||
if (!t.pixmap().isNull()) {
|
||||
t.pixmap().setDevicePixelRatio(_mapRatio);
|
||||
|
@ -180,11 +180,11 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
QPoint br = QPoint(qCeil(rect.right() / ts.width()),
|
||||
qCeil(rect.bottom() / ts.height()));
|
||||
|
||||
QVector<Tile> tiles;
|
||||
QVector<FetchTile> tiles;
|
||||
tiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
||||
for (int i = tl.x(); i < br.x(); i++)
|
||||
for (int j = tl.y(); j < br.y(); j++)
|
||||
tiles.append(Tile(QPoint(i, j), z.id()));
|
||||
tiles.append(FetchTile(QPoint(i, j), z.id()));
|
||||
|
||||
if (flags & Map::Block)
|
||||
_tileLoader->loadTilesSync(tiles);
|
||||
@ -192,7 +192,7 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
_tileLoader->loadTilesAsync(tiles);
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
Tile &t = tiles[i];
|
||||
FetchTile &t = tiles[i];
|
||||
QPointF tp(t.xy().x() * ts.width(), t.xy().y() * ts.height());
|
||||
if (!t.pixmap().isNull()) {
|
||||
t.pixmap().setDevicePixelRatio(imageRatio());
|
||||
|
Loading…
Reference in New Issue
Block a user