Commit a4cc3ca8 authored by dogmaphobic's avatar dogmaphobic

Fixing map cache for Qt 5.5.1

Map cacheing for < 5.5.0 was broken and we were using whatever default was provided by QtLocation. Now we're properly creating and configuring a cache manager.
parent d35b1789
......@@ -58,6 +58,7 @@
#include "qgeotilefetcherqgc.h"
#include "OpenPilotMaps.h"
#if QT_VERSION >= 0x050500
QGeoTiledMapQGC::QGeoTiledMapQGC(QGeoTiledMappingManagerEngine *engine, QObject *parent)
: QGeoTiledMap(engine, parent)
......@@ -82,7 +83,7 @@ QGeoTiledMappingManagerEngineQGC::QGeoTiledMappingManagerEngineQGC(const QVarian
mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Google Satellite Map"),tr("Google satellite map"), false, false, OpenPilot::GoogleSatellite);
mapTypes << QGeoMapType(QGeoMapType::TerrainMap, tr("Google Terrain Map"), tr("Google terrain map"), false, false, OpenPilot::GoogleTerrain);
// TODO:
// Proper hybrid maps requires collecting two separate bimaps and overlaying them.
// Proper google hybrid maps requires collecting two separate bimaps and overlaying them.
//mapTypes << QGeoMapType(QGeoMapType::HybridMap, tr("Google Hybrid Map"), tr("Google hybrid map"), false, false, OpenPilot::GoogleHybrid);
// Bing
mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Bing Street Map"), tr("Bing street map"), false, false, OpenPilot::BingMap);
......@@ -99,13 +100,62 @@ QGeoTiledMappingManagerEngineQGC::QGeoTiledMappingManagerEngineQGC(const QVarian
// QGC Default
tileFetcher->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7");
#if QT_VERSION >= 0x050500
_setCache(parameters);
#endif
setTileFetcher(tileFetcher);
QString cacheDir;
*error = QGeoServiceProvider::NoError;
errorString->clear();
#if QT_VERSION >= 0x050500
if (parameters.contains(QStringLiteral("mapping.copyright")))
m_customCopyright = parameters.value(QStringLiteral("mapping.copyright")).toString().toLatin1();
#endif
}
QGeoTiledMappingManagerEngineQGC::~QGeoTiledMappingManagerEngineQGC()
{
}
#if QT_VERSION < 0x050500
QGeoMapData *QGeoTiledMappingManagerEngineQGC::createMapData()
{
return new QGeoTiledMapData(this, 0);
}
#else
QGeoMap *QGeoTiledMappingManagerEngineQGC::createMap()
{
return new QGeoTiledMapQGC(this);
}
QString QGeoTiledMappingManagerEngineQGC::customCopyright() const
{
return m_customCopyright;
}
#endif
#if QT_VERSION >= 0x050500
void QGeoTiledMappingManagerEngineQGC::_setCache(const QVariantMap &parameters)
{
QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/QGCMapCache");
//-- Clear old cache
QDir baseDir(cacheDir);
if (baseDir.exists()) {
const QStringList oldCacheFiles = baseDir.entryList(QDir::Files);
foreach (const QString& file, oldCacheFiles)
baseDir.remove(file);
}
if (parameters.contains(QStringLiteral("mapping.cache.directory")))
cacheDir = parameters.value(QStringLiteral("mapping.cache.directory")).toString();
else {
cacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/QGCMapCache");
cacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/QGCMapCache55");
if(!QDir::root().mkpath(cacheDir)) {
qWarning() << "Could not create mapping disk cache directory: " << cacheDir;
cacheDir = QDir::homePath() + QLatin1String("/.qgcmapscache/");
......@@ -117,11 +167,10 @@ QGeoTiledMappingManagerEngineQGC::QGeoTiledMappingManagerEngineQGC(const QVarian
qWarning() << "Could not create mapping disk cache directory: " << cacheDir;
cacheDir.clear();
}
//else {
// qDebug() << "Mapping cache directory:" << cacheDir;
//}
QGeoTileCache* pTileCache = tileCache();
else {
qDebug() << "Mapping cache directory:" << cacheDir;
}
QGeoTileCache* pTileCache = createTileCacheWithDir(cacheDir);
if(pTileCache)
{
int cacheLimit = 0;
......@@ -159,37 +208,5 @@ QGeoTiledMappingManagerEngineQGC::QGeoTiledMappingManagerEngineQGC(const QVarian
}
pTileCache->setMaxMemoryUsage(cacheLimit);
}
*error = QGeoServiceProvider::NoError;
errorString->clear();
#if QT_VERSION >= 0x050500
if (parameters.contains(QStringLiteral("mapping.copyright")))
m_customCopyright = parameters.value(QStringLiteral("mapping.copyright")).toString().toLatin1();
#endif
}
QGeoTiledMappingManagerEngineQGC::~QGeoTiledMappingManagerEngineQGC()
{
}
#if QT_VERSION < 0x050500
QGeoMapData *QGeoTiledMappingManagerEngineQGC::createMapData()
{
return new QGeoTiledMapData(this, 0);
}
#else
QGeoMap *QGeoTiledMappingManagerEngineQGC::createMap()
{
return new QGeoTiledMapQGC(this);
}
QString QGeoTiledMappingManagerEngineQGC::customCopyright() const
{
return m_customCopyright;
}
#endif
......@@ -77,6 +77,7 @@ public:
private:
#if QT_VERSION >= 0x050500
QString m_customCopyright;
void _setCache(const QVariantMap &parameters);
#endif
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment