diff options
-rw-r--r-- | platform/qt/src/qt_conversion.hpp | 19 |
1 files changed, 18 insertions, 1 deletions
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<QVector<QMapbox::Feature>>() + || value.userType() == qMetaTypeId<QList<QMapbox::Feature>>(); } static optional<QVariant> objectMember(const QVariant& value, const char* key) { @@ -119,6 +121,10 @@ public: static optional<GeoJSON> toGeoJSON(const QVariant& value, Error& error) { if (value.typeName() == QStringLiteral("QMapbox::Feature")) { return GeoJSON { asMapboxGLFeature(value.value<QMapbox::Feature>()) }; + } else if (value.userType() == qMetaTypeId<QVector<QMapbox::Feature>>()) { + return featureCollectionToGeoJSON(value.value<QVector<QMapbox::Feature>>()); + } else if (value.userType() == qMetaTypeId<QList<QMapbox::Feature>>()) { + return featureCollectionToGeoJSON(value.value<QList<QMapbox::Feature>>()); } 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<typename T> + static GeoJSON featureCollectionToGeoJSON(const T &features) { + mapbox::feature::feature_collection<double> collection; + collection.reserve(static_cast<std::size_t>(features.size())); + for (const auto &feature : features) { + collection.push_back(asMapboxGLFeature(feature)); + } + return GeoJSON { std::move(collection) }; + } }; template <class T, class...Args> |