summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorxylosper <darklin20@gmail.com>2019-01-31 12:39:04 +0900
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-02-01 16:34:35 +0200
commit6b2f17191baccf7ff17ee912bdf04fb44bea6d52 (patch)
tree5e2c54b870cdb23ce770322db08cedab46cf2796 /platform/qt
parent43dc191f54504ef0d93ae7627e1aa01e2e3f117a (diff)
downloadqtlocation-mapboxgl-6b2f17191baccf7ff17ee912bdf04fb44bea6d52.tar.gz
[qt] Support feature collection for GeoJSON source data
This commit adds support of `QVector<QMapbox::Feature>` and `QList<QMapbox::Feature>` for data in GeoJSON source.
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/src/qt_conversion.hpp19
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>