-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QtLocationPlugin: Minor Miscellaneous Improvements
- Loading branch information
Showing
14 changed files
with
204 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
* @author Gus Grubba <[email protected]> | ||
* | ||
*/ | ||
|
||
#include "QGCMapEngine.h" | ||
#include "QGCCachedTileSet.h" | ||
#include "QGCTileCacheWorker.h" | ||
|
@@ -23,31 +24,21 @@ | |
#include "QGCTileSet.h" | ||
#include "QGCTile.h" | ||
#include "QGCCacheTile.h" | ||
#include "QGCApplication.h" | ||
#include <QGCLoggingCategory.h> | ||
|
||
#include <QtCore/qapplicationstatic.h> | ||
#include <QtCore/QStandardPaths> | ||
#include <QtCore/QDir> | ||
|
||
#define CACHE_PATH_VERSION "300" | ||
|
||
QGC_LOGGING_CATEGORY(QGCMapEngineLog, "qgc.qtlocationplugin.qgcmapengine") | ||
|
||
Q_DECLARE_METATYPE(QList<QGCTile*>) | ||
|
||
Q_APPLICATION_STATIC(QGCMapEngine, s_mapEngine); | ||
Q_APPLICATION_STATIC(QGCMapEngine, _mapEngine); | ||
|
||
QGCMapEngine* getQGCMapEngine() | ||
QGCMapEngine *getQGCMapEngine() | ||
{ | ||
return QGCMapEngine::instance(); | ||
} | ||
|
||
QGCMapEngine* QGCMapEngine::instance() | ||
{ | ||
return s_mapEngine(); | ||
} | ||
|
||
QGCMapEngine::QGCMapEngine(QObject *parent) | ||
: QObject(parent) | ||
, m_worker(new QGCCacheWorker(this)) | ||
|
@@ -72,93 +63,24 @@ QGCMapEngine::~QGCMapEngine() | |
// qCDebug(QGCMapEngineLog) << Q_FUNC_INFO << this; | ||
} | ||
|
||
void QGCMapEngine::init() | ||
QGCMapEngine *QGCMapEngine::instance() | ||
{ | ||
_wipeOldCaches(); | ||
|
||
// QString cacheDir = QAbstractGeoTileCache::baseCacheDirectory() | ||
#ifdef __mobile__ | ||
QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); | ||
#else | ||
QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); | ||
#endif | ||
cacheDir += QStringLiteral("/QGCMapCache" CACHE_PATH_VERSION); | ||
if (!QDir::root().mkpath(cacheDir)) { | ||
qCWarning(QGCMapEngineLog) << "Could not create mapping disk cache directory:" << cacheDir; | ||
|
||
cacheDir = QDir::homePath() + QStringLiteral("/.qgcmapscache/"); | ||
if (!QDir::root().mkpath(cacheDir)) { | ||
qCWarning(QGCMapEngineLog) << "Could not create mapping disk cache directory:" << cacheDir; | ||
cacheDir.clear(); | ||
} | ||
} | ||
|
||
m_cachePath = cacheDir; | ||
if (!m_cachePath.isEmpty()) { | ||
const QString databaseFilePath(m_cachePath + "/" + QGeoFileTileCacheQGC::getCacheFilename()); | ||
m_worker->setDatabaseFile(databaseFilePath); | ||
return _mapEngine(); | ||
} | ||
|
||
qCDebug(QGCMapEngineLog) << "Map Cache in:" << databaseFilePath; | ||
} else { | ||
qCCritical(QGCMapEngineLog) << "Could not find suitable map cache directory."; | ||
} | ||
void QGCMapEngine::init() | ||
{ | ||
m_worker->setDatabaseFile(QGeoFileTileCacheQGC::getDatabaseFilePath()); | ||
|
||
QGCMapTask* const task = new QGCMapTask(QGCMapTask::taskInit); | ||
(void) addTask(task); | ||
|
||
if (m_cacheWasReset) { | ||
qgcApp()->showAppMessage(tr( | ||
"The Offline Map Cache database has been upgraded. " | ||
"Your old map cache sets have been reset.")); | ||
} | ||
} | ||
|
||
bool QGCMapEngine::addTask(QGCMapTask *task) | ||
{ | ||
return m_worker->enqueueTask(task); | ||
} | ||
|
||
bool QGCMapEngine::_wipeDirectory(const QString &dirPath) | ||
{ | ||
bool result = true; | ||
|
||
const QDir dir(dirPath); | ||
if (dir.exists(dirPath)) { | ||
m_cacheWasReset = true; | ||
|
||
const QFileInfoList fileList = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst); | ||
for (const QFileInfo &info : fileList) { | ||
if (info.isDir()) { | ||
result = _wipeDirectory(info.absoluteFilePath()); | ||
} else { | ||
result = QFile::remove(info.absoluteFilePath()); | ||
} | ||
|
||
if (!result) { | ||
return result; | ||
} | ||
} | ||
result = dir.rmdir(dirPath); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
void QGCMapEngine::_wipeOldCaches() | ||
{ | ||
const QStringList oldCaches = {"/QGCMapCache55", "/QGCMapCache100"}; | ||
for (const QString &cache : oldCaches) { | ||
QString oldCacheDir; | ||
#ifdef __mobile__ | ||
oldCacheDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); | ||
#else | ||
oldCacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); | ||
#endif | ||
oldCacheDir += cache; | ||
_wipeDirectory(oldCacheDir); | ||
} | ||
} | ||
|
||
void QGCMapEngine::_updateTotals(quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize) | ||
{ | ||
emit updateTotals(totaltiles, totalsize, defaulttiles, defaultsize); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.