diff options
| author | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-07 17:00:53 -0800 |
|---|---|---|
| committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-23 13:31:13 -0700 |
| commit | d7227e13a7a87cf50a4c8c1f0615fc565f5a2679 (patch) | |
| tree | eda76a2da3220f3cfeec901400369cf9c8361f58 /platform/qt | |
| parent | 1c757cce34344dfecc9a724034680225143f92b7 (diff) | |
| download | qtlocation-mapboxgl-d7227e13a7a87cf50a4c8c1f0615fc565f5a2679.tar.gz | |
[all] Replace Result<T> with optional<T> plus out Error parameter
Diffstat (limited to 'platform/qt')
| -rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 18 | ||||
| -rw-r--r-- | platform/qt/src/qt_geojson.hpp | 20 |
2 files changed, 22 insertions, 16 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index b1c0a11ee1..3d5da10c36 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -1250,9 +1250,10 @@ void QMapboxGL::addSource(const QString &id, const QVariantMap ¶ms) using namespace mbgl::style; using namespace mbgl::style::conversion; - Result<std::unique_ptr<Source>> source = convert<std::unique_ptr<Source>>(QVariant(params), id.toStdString()); + Error error; + mbgl::optional<std::unique_ptr<Source>> source = convert<std::unique_ptr<Source>>(QVariant(params), error, id.toStdString()); if (!source) { - qWarning() << "Unable to add source:" << source.error().message.c_str(); + qWarning() << "Unable to add source:" << error.message.c_str(); return; } @@ -1291,7 +1292,8 @@ void QMapboxGL::updateSource(const QString &id, const QVariantMap ¶ms) } if (params.contains("data")) { - auto result = convertGeoJSON(params["data"]); + Error error; + auto result = convertGeoJSON(params["data"], error); if (result) { sourceGeoJSON->setGeoJSON(*result); } @@ -1362,9 +1364,10 @@ void QMapboxGL::addLayer(const QVariantMap ¶ms) using namespace mbgl::style; using namespace mbgl::style::conversion; - Result<std::unique_ptr<Layer>> layer = convert<std::unique_ptr<Layer>>(QVariant(params)); + Error error; + mbgl::optional<std::unique_ptr<Layer>> layer = convert<std::unique_ptr<Layer>>(QVariant(params), error); if (!layer) { - qWarning() << "Unable to add layer:" << layer.error().message.c_str(); + qWarning() << "Unable to add layer:" << error.message.c_str(); return; } @@ -1445,9 +1448,10 @@ void QMapboxGL::setFilter(const QString& layer, const QVariant& filter) Filter filter_; - Result<Filter> converted = convert<Filter>(filter); + Error error; + mbgl::optional<Filter> converted = convert<Filter>(filter, error); if (!converted) { - qWarning() << "Error parsing filter:" << converted.error().message.c_str(); + qWarning() << "Error parsing filter:" << error.message.c_str(); return; } filter_ = std::move(*converted); diff --git a/platform/qt/src/qt_geojson.hpp b/platform/qt/src/qt_geojson.hpp index 038b051941..7c50c663dd 100644 --- a/platform/qt/src/qt_geojson.hpp +++ b/platform/qt/src/qt_geojson.hpp @@ -180,20 +180,21 @@ namespace style { namespace conversion { template <> -Result<GeoJSON> convertGeoJSON(const QMapbox::Feature& feature) { - return Result<GeoJSON> { GeoJSON { asMapboxGLFeature(feature) } }; +optional<GeoJSON> convertGeoJSON(const QMapbox::Feature& feature, Error&) { + return GeoJSON { asMapboxGLFeature(feature) }; } template <> -Result<GeoJSON> convertGeoJSON(const QVariant& value) { +optional<GeoJSON> convertGeoJSON(const QVariant& value, Error& error) { #if QT_VERSION >= 0x050000 if (value.typeName() == QStringLiteral("QMapbox::Feature")) { #else if (value.typeName() == QString("QMapbox::Feature")) { #endif - return convertGeoJSON(value.value<QMapbox::Feature>()); + return convertGeoJSON(value.value<QMapbox::Feature>(), error); } else if (value.type() != QVariant::ByteArray) { - return Error { "JSON data must be in QByteArray" }; + error = { "JSON data must be in QByteArray" }; + return {}; } auto data = value.toByteArray(); @@ -208,13 +209,14 @@ Result<GeoJSON> convertGeoJSON(const QVariant& value) { if (d.HasParseError()) { std::stringstream message; message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError()); - - return Error { message.str() }; + error = { message.str() }; + return {}; } - Result<GeoJSON> geoJSON = convertGeoJSON<JSValue>(d); + optional<GeoJSON> geoJSON = convertGeoJSON<JSValue>(d, error); if (!geoJSON) { - return Error { geoJSON.error().message }; + error = { error.message }; + return {}; } return geoJSON; |
