PIQt now provide PICout << operators for Qt types
MapView::setTileObsoleteTime() method. You can set maximum lifetime for tile, after that it will be redownloaded
This commit is contained in:
@@ -92,10 +92,18 @@ void MapView::setCachePath(const QString & p) {
|
||||
}
|
||||
|
||||
|
||||
void collectDownloadIndeces(OSMTileCache * cache, QQueue<OSM::TileIndex> & indeces, OSM::TileIndex index, int target_zoom_level, bool only_new) {
|
||||
void MapView::setTileObsoleteTime(int secs) {
|
||||
cache->setTileObsoleteTime(secs);
|
||||
}
|
||||
|
||||
|
||||
void collectDownloadIndeces(OSMTileCache * cache,
|
||||
QQueue<OSM::TileIndex> & indeces,
|
||||
OSM::TileIndex index,
|
||||
int target_zoom_level,
|
||||
bool only_new) {
|
||||
if (only_new) {
|
||||
if (!cache->isTileFileExists(index))
|
||||
indeces << index;
|
||||
if (!cache->isTileFileExists(index)) indeces << index;
|
||||
} else
|
||||
indeces << index;
|
||||
if (index.z >= target_zoom_level) return;
|
||||
@@ -205,7 +213,7 @@ void MapView::mouseMoveEvent(QMouseEvent * e) {
|
||||
}
|
||||
}
|
||||
if (e->buttons() == Qt::RightButton) {
|
||||
auto dp = e->pos() - press_point;
|
||||
auto dp = e->pos() - press_point;
|
||||
press_point = e->pos();
|
||||
zoom(1. - dp.y() / 50., zoom_anchor);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@ public:
|
||||
QString cachePath() const;
|
||||
void setCachePath(const QString & p);
|
||||
|
||||
void setTileObsoleteTime(int secs);
|
||||
|
||||
void downloadCurrentView(int target_zoom_level = 17, bool only_new = true);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -31,8 +31,10 @@ void OSMTileCache::tileDownloaded(OSM::TileIndex index, const QPixmap & pixmap)
|
||||
|
||||
OSM::TilePixmap OSMTileCache::getTile(OSM::TileIndex index, QRectF & rect_src) {
|
||||
OSM::TilePixmap ret = getTileFromCache(index);
|
||||
if (ret.isEmpty()) {
|
||||
if (ret.isEmpty() || ret.obsolete) {
|
||||
parent->downloader->queueTile(index);
|
||||
}
|
||||
if (ret.isEmpty()) {
|
||||
QVector<QPointF> offsets;
|
||||
while (index.z >= 0) {
|
||||
index.z--;
|
||||
@@ -81,10 +83,15 @@ OSM::TilePixmap OSMTileCache::getTileFromCache(OSM::TileIndex index) {
|
||||
if (cache_dir.exists(hashdir)) {
|
||||
QString hashname = hashdir + "/" + index.hashName();
|
||||
if (cache_dir.exists(hashname)) {
|
||||
ret.pixmap.load(cache_dir.absoluteFilePath(hashname), "png");
|
||||
QString fname = cache_dir.absoluteFilePath(hashname);
|
||||
ret.pixmap.load(fname, "png");
|
||||
tile = new OSM::TilePixmap();
|
||||
tile->index = index;
|
||||
tile->pixmap = ret.pixmap;
|
||||
if (secs_obsolete > 0) {
|
||||
int secs_old = QFileInfo(fname).lastModified().secsTo(QDateTime::currentDateTime());
|
||||
ret.obsolete = secs_old >= secs_obsolete;
|
||||
}
|
||||
tile_cache.insert(tile->index.hash(), tile, tile->pixmapBytes());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
add_size_b = mb * 1024 * 1024;
|
||||
updateCacheSize();
|
||||
}
|
||||
void setTileObsoleteTime(int secs) { secs_obsolete = secs; }
|
||||
|
||||
void tileDownloaded(OSM::TileIndex index, const QPixmap & pixmap);
|
||||
OSM::TilePixmap getTile(OSM::TileIndex index, QRectF & rect_src);
|
||||
@@ -67,6 +68,7 @@ private:
|
||||
QDir cache_dir;
|
||||
QWaitCondition cond;
|
||||
QMutex cond_mutex;
|
||||
int secs_obsolete = -1;
|
||||
int fixed_size_b = 0, add_size_b = 0;
|
||||
QQueue<OSM::TilePixmap> queue;
|
||||
QCache<quint64, OSM::TilePixmap> tile_cache;
|
||||
|
||||
@@ -36,6 +36,7 @@ struct TileIndex {
|
||||
struct TilePixmap {
|
||||
TileIndex index;
|
||||
QPixmap pixmap;
|
||||
bool obsolete = false;
|
||||
bool isEmpty() const;
|
||||
int pixmapBytes() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user