summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-05-27 21:07:35 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-05-29 10:33:37 +0000
commitc07087aea7e2f08d8fa5e7068c946ac83ce9f8c1 (patch)
tree08521d0fb3df58374d0700818dbe184299784582
parent2244429e7577baee4de062756d0708b076c1541f (diff)
downloadqtlocation-c07087aea7e2f08d8fa5e7068c946ac83ce9f8c1.tar.gz
Refactor: move code not depending on "this" into static methods
This patch moves the implementation of the default filenameToTileSpec and tileSpecToFileName methods into standalone public static methods so that they can be possibly reused by plugins or other components, since these implementations do not actually depend on any member of QGeoFileTileCache. Change-Id: I6e3f59615ff3a5e0924f946aa13aabebb8157e42 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/location/maps/qgeofiletilecache.cpp124
-rw-r--r--src/location/maps/qgeofiletilecache_p.h3
2 files changed, 70 insertions, 57 deletions
diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp
index ede900bd..d40ad825 100644
--- a/src/location/maps/qgeofiletilecache.cpp
+++ b/src/location/maps/qgeofiletilecache.cpp
@@ -401,6 +401,71 @@ void QGeoFileTileCache::insert(const QGeoTileSpec &spec,
* and act as a poison */
}
+QString QGeoFileTileCache::tileSpecToFilenameDefault(const QGeoTileSpec &spec, const QString &format, const QString &directory)
+{
+ QString filename = spec.plugin();
+ filename += QLatin1String("-");
+ filename += QString::number(spec.mapId());
+ filename += QLatin1String("-");
+ filename += QString::number(spec.zoom());
+ filename += QLatin1String("-");
+ filename += QString::number(spec.x());
+ filename += QLatin1String("-");
+ filename += QString::number(spec.y());
+
+ //Append version if real version number to ensure backwards compatibility and eviction of old tiles
+ if (spec.version() != -1) {
+ filename += QLatin1String("-");
+ filename += QString::number(spec.version());
+ }
+
+ filename += QLatin1String(".");
+ filename += format;
+
+ QDir dir = QDir(directory);
+
+ return dir.filePath(filename);
+}
+
+QGeoTileSpec QGeoFileTileCache::filenameToTileSpecDefault(const QString &filename)
+{
+ QGeoTileSpec emptySpec;
+
+ QStringList parts = filename.split('.');
+
+ if (parts.length() != 2)
+ return emptySpec;
+
+ QString name = parts.at(0);
+ QStringList fields = name.split('-');
+
+ int length = fields.length();
+ if (length != 5 && length != 6)
+ return emptySpec;
+
+ QList<int> numbers;
+
+ bool ok = false;
+ for (int i = 1; i < length; ++i) {
+ ok = false;
+ int value = fields.at(i).toInt(&ok);
+ if (!ok)
+ return emptySpec;
+ numbers.append(value);
+ }
+
+ //File name without version, append default
+ if (numbers.length() < 5)
+ numbers.append(-1);
+
+ return QGeoTileSpec(fields.at(0),
+ numbers.at(0),
+ numbers.at(1),
+ numbers.at(2),
+ numbers.at(3),
+ numbers.at(4));
+}
+
void QGeoFileTileCache::evictFromDiskCache(QGeoCachedTileDisk *td)
{
QFile::remove(td->filename);
@@ -526,67 +591,12 @@ bool QGeoFileTileCache::isTileBogus(const QByteArray &bytes) const
QString QGeoFileTileCache::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) const
{
- QString filename = spec.plugin();
- filename += QLatin1String("-");
- filename += QString::number(spec.mapId());
- filename += QLatin1String("-");
- filename += QString::number(spec.zoom());
- filename += QLatin1String("-");
- filename += QString::number(spec.x());
- filename += QLatin1String("-");
- filename += QString::number(spec.y());
-
- //Append version if real version number to ensure backwards compatibility and eviction of old tiles
- if (spec.version() != -1) {
- filename += QLatin1String("-");
- filename += QString::number(spec.version());
- }
-
- filename += QLatin1String(".");
- filename += format;
-
- QDir dir = QDir(directory);
-
- return dir.filePath(filename);
+ return tileSpecToFilenameDefault(spec, format, directory);
}
QGeoTileSpec QGeoFileTileCache::filenameToTileSpec(const QString &filename) const
{
- QGeoTileSpec emptySpec;
-
- QStringList parts = filename.split('.');
-
- if (parts.length() != 2)
- return emptySpec;
-
- QString name = parts.at(0);
- QStringList fields = name.split('-');
-
- int length = fields.length();
- if (length != 5 && length != 6)
- return emptySpec;
-
- QList<int> numbers;
-
- bool ok = false;
- for (int i = 1; i < length; ++i) {
- ok = false;
- int value = fields.at(i).toInt(&ok);
- if (!ok)
- return emptySpec;
- numbers.append(value);
- }
-
- //File name without version, append default
- if (numbers.length() < 5)
- numbers.append(-1);
-
- return QGeoTileSpec(fields.at(0),
- numbers.at(0),
- numbers.at(1),
- numbers.at(2),
- numbers.at(3),
- numbers.at(4));
+ return filenameToTileSpecDefault(filename);
}
QString QGeoFileTileCache::directory() const
diff --git a/src/location/maps/qgeofiletilecache_p.h b/src/location/maps/qgeofiletilecache_p.h
index 2ae40d36..e319e2a2 100644
--- a/src/location/maps/qgeofiletilecache_p.h
+++ b/src/location/maps/qgeofiletilecache_p.h
@@ -136,6 +136,9 @@ public:
const QString &format,
QAbstractGeoTileCache::CacheAreas areas = QAbstractGeoTileCache::AllCaches) Q_DECL_OVERRIDE;
+ static QString tileSpecToFilenameDefault(const QGeoTileSpec &spec, const QString &format, const QString &directory);
+ static QGeoTileSpec filenameToTileSpecDefault(const QString &filename);
+
protected:
void init() Q_DECL_OVERRIDE;
void printStats() Q_DECL_OVERRIDE;