diff --git a/src/QtLocationPlugin/qgeotiledmappingmanagerengineqgc.cpp b/src/QtLocationPlugin/qgeotiledmappingmanagerengineqgc.cpp index e11e8f281a98d99f16725dbce1a24548987e8537..1422f55552068cf90a34cdf80757963acdb1b42f 100644 --- a/src/QtLocationPlugin/qgeotiledmappingmanagerengineqgc.cpp +++ b/src/QtLocationPlugin/qgeotiledmappingmanagerengineqgc.cpp @@ -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 ¶meters) +{ + + 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 diff --git a/src/QtLocationPlugin/qgeotiledmappingmanagerengineqgc.h b/src/QtLocationPlugin/qgeotiledmappingmanagerengineqgc.h index 03f0f9c2691c41ce5c32de9dd2b5791334f3004f..6bc8447d9202049be783121d93bb957e9968d05d 100644 --- a/src/QtLocationPlugin/qgeotiledmappingmanagerengineqgc.h +++ b/src/QtLocationPlugin/qgeotiledmappingmanagerengineqgc.h @@ -77,6 +77,7 @@ public: private: #if QT_VERSION >= 0x050500 QString m_customCopyright; + void _setCache(const QVariantMap ¶meters); #endif };