summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-05 16:31:03 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-08 13:48:57 -0700
commitbaaae99a03202641ae5b8024e57b691fe61a6688 (patch)
tree459045e56197696aa1312594f1e452b03931775d /platform/qt
parente34d8b5c802186008e49364668e4a7bd5668d0fd (diff)
downloadqtlocation-mapboxgl-baaae99a03202641ae5b8024e57b691fe61a6688.tar.gz
[core, android] Factor JSON string conversions
This adds a `convertJSON` template, to be used like: Error error optional<Foo> foo = convertJSON<Foo>(string, error); Internally, it parses the string with RapidJSON and then calls `convert<Foo>(parsed, error)`. While here, rationalize GeoJSON converters and fix error handling for Tileset conversion in OfflineDownload.
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/src/qmapboxgl.cpp2
-rw-r--r--platform/qt/src/qt_geojson.hpp11
2 files changed, 4 insertions, 9 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index edb8afa28a..ce7e237afb 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -1303,7 +1303,7 @@ void QMapboxGL::updateSource(const QString &id, const QVariantMap &params)
if (params.contains("data")) {
Error error;
- auto result = convertGeoJSON(params["data"], error);
+ auto result = convert<mbgl::GeoJSON>(params["data"], error);
if (result) {
sourceGeoJSON->setGeoJSON(*result);
}
diff --git a/platform/qt/src/qt_geojson.hpp b/platform/qt/src/qt_geojson.hpp
index 7d12660aec..a6958b7edc 100644
--- a/platform/qt/src/qt_geojson.hpp
+++ b/platform/qt/src/qt_geojson.hpp
@@ -178,25 +178,20 @@ namespace style {
namespace conversion {
template <>
-optional<GeoJSON> convertGeoJSON(const QMapbox::Feature& feature, Error&) {
- return GeoJSON { asMapboxGLFeature(feature) };
-}
-
-template <>
-optional<GeoJSON> convertGeoJSON(const QVariant& value, Error& error) {
+optional<GeoJSON> Converter<GeoJSON>::operator()(const QVariant& value, Error& error) const {
#if QT_VERSION >= 0x050000
if (value.typeName() == QStringLiteral("QMapbox::Feature")) {
#else
if (value.typeName() == QString("QMapbox::Feature")) {
#endif
- return convertGeoJSON(value.value<QMapbox::Feature>(), error);
+ return GeoJSON { asMapboxGLFeature(value.value<QMapbox::Feature>()) };
} else if (value.type() != QVariant::ByteArray) {
error = { "JSON data must be in QByteArray" };
return {};
}
QByteArray data = value.toByteArray();
- return convertGeoJSON(std::string(data.constData(), data.size()), error);
+ return convert<GeoJSON>(std::string(data.constData(), data.size()), error);
}
} // namespace conversion