From 6b2f17191baccf7ff17ee912bdf04fb44bea6d52 Mon Sep 17 00:00:00 2001 From: xylosper Date: Thu, 31 Jan 2019 12:39:04 +0900 Subject: [qt] Support feature collection for GeoJSON source data This commit adds support of `QVector` and `QList` for data in GeoJSON source. --- platform/qt/src/qt_conversion.hpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'platform/qt') diff --git a/platform/qt/src/qt_conversion.hpp b/platform/qt/src/qt_conversion.hpp index 070a3dd375..6927f2510a 100644 --- a/platform/qt/src/qt_conversion.hpp +++ b/platform/qt/src/qt_conversion.hpp @@ -35,7 +35,9 @@ public: static bool isObject(const QVariant& value) { return value.canConvert(QVariant::Map) || value.type() == QVariant::ByteArray - || QString(value.typeName()) == QStringLiteral("QMapbox::Feature"); + || QString(value.typeName()) == QStringLiteral("QMapbox::Feature") + || value.userType() == qMetaTypeId>() + || value.userType() == qMetaTypeId>(); } static optional objectMember(const QVariant& value, const char* key) { @@ -119,6 +121,10 @@ public: static optional toGeoJSON(const QVariant& value, Error& error) { if (value.typeName() == QStringLiteral("QMapbox::Feature")) { return GeoJSON { asMapboxGLFeature(value.value()) }; + } else if (value.userType() == qMetaTypeId>()) { + return featureCollectionToGeoJSON(value.value>()); + } else if (value.userType() == qMetaTypeId>()) { + return featureCollectionToGeoJSON(value.value>()); } else if (value.type() != QVariant::ByteArray) { error = { "JSON data must be in QByteArray" }; return {}; @@ -127,6 +133,17 @@ public: QByteArray data = value.toByteArray(); return parseGeoJSON(std::string(data.constData(), data.size()), error); } + +private: + template + static GeoJSON featureCollectionToGeoJSON(const T &features) { + mapbox::feature::feature_collection collection; + collection.reserve(static_cast(features.size())); + for (const auto &feature : features) { + collection.push_back(asMapboxGLFeature(feature)); + } + return GeoJSON { std::move(collection) }; + } }; template -- cgit v1.2.1