diff --git a/libs/map/mapview.cpp b/libs/map/mapview.cpp index 318e39a..2406ddb 100644 --- a/libs/map/mapview.cpp +++ b/libs/map/mapview.cpp @@ -92,10 +92,18 @@ void MapView::setCachePath(const QString & p) { } -void collectDownloadIndeces(OSMTileCache * cache, QQueue & indeces, OSM::TileIndex index, int target_zoom_level, bool only_new) { +void MapView::setTileObsoleteTime(int secs) { + cache->setTileObsoleteTime(secs); +} + + +void collectDownloadIndeces(OSMTileCache * cache, + QQueue & 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); } diff --git a/libs/map/mapview.h b/libs/map/mapview.h index a417102..b2c28d7 100644 --- a/libs/map/mapview.h +++ b/libs/map/mapview.h @@ -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: diff --git a/libs/map/osm_tile_cache.cpp b/libs/map/osm_tile_cache.cpp index ec9a66b..1cfa18c 100644 --- a/libs/map/osm_tile_cache.cpp +++ b/libs/map/osm_tile_cache.cpp @@ -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 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; } diff --git a/libs/map/osm_tile_cache_p.h b/libs/map/osm_tile_cache_p.h index 8b0a731..ab38841 100644 --- a/libs/map/osm_tile_cache_p.h +++ b/libs/map/osm_tile_cache_p.h @@ -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 queue; QCache tile_cache; diff --git a/libs/map/osm_types_p.h b/libs/map/osm_types_p.h index 778ece8..9783678 100644 --- a/libs/map/osm_types_p.h +++ b/libs/map/osm_types_p.h @@ -36,6 +36,7 @@ struct TileIndex { struct TilePixmap { TileIndex index; QPixmap pixmap; + bool obsolete = false; bool isEmpty() const; int pixmapBytes() const; }; diff --git a/libs/piqt/piqt.h b/libs/piqt/piqt.h index 0ac280c..6b4446c 100644 --- a/libs/piqt/piqt.h +++ b/libs/piqt/piqt.h @@ -794,4 +794,104 @@ T piqDeserialize(const QByteArray & data) { } +/// PICout with Qt + + +inline PICout operator<<(PICout s, const QVariant & v) { + s << Q2PIVariant(v); + return s; +} + +inline PICout operator<<(PICout s, const QByteArray & v) { + s << Q2PIByteArray(v); + return s; +} + +inline PICout operator<<(PICout s, const QString & v) { + s << Q2PIString(v); + return s; +} + +inline PICout operator<<(PICout s, const QStringList & v) { + s << Q2PIStringList(v); + return s; +} + +#if QT_VERSION_MAJOR == 5 +template +inline PICout operator<<(PICout s, const QVector & v) { + s << Q2PIVector(v); + return s; +} +#endif + +template +inline PICout operator<<(PICout s, const QList & v) { + s << Q2PIVector(v); + return s; +} + +template +inline PICout operator<<(PICout s, const QMap & v) { + s << Q2PIMap(v); + return s; +} + +inline PICout operator<<(PICout s, const QTime & v) { + s << Q2PITime(v); + return s; +} + +inline PICout operator<<(PICout s, const QDate & v) { + s << Q2PIDate(v); + return s; +} + +inline PICout operator<<(PICout s, const QDateTime & v) { + s << Q2PIDateTime(v); + return s; +} + +inline PICout operator<<(PICout s, const QPoint & v) { + s << Q2PIPoint(v); + return s; +} + +inline PICout operator<<(PICout s, const QPointF & v) { + s << Q2PIPoint(v); + return s; +} + +inline PICout operator<<(PICout s, const QLine & v) { + s << Q2PILine(v); + return s; +} + +inline PICout operator<<(PICout s, const QLineF & v) { + s << Q2PILine(v); + return s; +} + +inline PICout operator<<(PICout s, const QRect & v) { + s << Q2PIRect(v); + return s; +} + +inline PICout operator<<(PICout s, const QRectF & v) { + s << Q2PIRect(v); + return s; +} + +inline PICout operator<<(PICout s, const QColor & v) { + s << Q2PIColor(v); + return s; +} + +#ifdef PIQT_HAS_GEOPOSITION +inline PICout operator<<(PICout s, const QGeoCoordinate & v) { + s << Q2PIGeoPosition(v); + return s; +} +#endif + #endif // PIQT_H diff --git a/utils/mapviewer/mainwindow.cpp b/utils/mapviewer/mainwindow.cpp index 12b4983..6b5f1f9 100644 --- a/utils/mapviewer/mainwindow.cpp +++ b/utils/mapviewer/mainwindow.cpp @@ -7,6 +7,7 @@ #include "mapitempolygon.h" #include "mapitemtext.h" #include "osm_geocoding.h" +#include "piliterals_time.h" #include "piqt.h" #include "qad_locations.h" @@ -18,6 +19,7 @@ MainWindow::MainWindow(QWidget * parent): EMainWindow(parent), Ui::MainWindow() { setupUi(this); + map->setTileObsoleteTime((5_d).toSeconds()); session.setFile(QAD::userPath(QAD::ltConfig, "session_mapviewer")); session.addEntry(this); session.load();