[Qt] Allow strings as data source in the QML Item

Data values starting with ':' will be assumed to be a resource.
This commit is contained in:
Thiago Marcos P. Santos
2016-12-08 18:45:30 -02:00
committed by Thiago Marcos P. Santos
parent 97df99c134
commit d6b8866975
2 changed files with 18 additions and 3 deletions

View File

@@ -323,6 +323,16 @@ ApplicationWindow {
source.data = ":source2.geojson"
}
}
RadioButton {
text: "Route 3"
exclusiveGroup: sourceGroup
onClicked: {
source.data = '{ "type": "FeatureCollection", "features": \
[{ "type": "Feature", "properties": {}, "geometry": { \
"type": "LineString", "coordinates": [[ 24.934938848018646, \
60.16830257086771 ], [ 24.943315386772156, 60.16227776476442 ]]}}]}'
}
}
}
}

View File

@@ -290,9 +290,14 @@ bool QQuickMapboxGL::parseStyleSource(QQuickMapboxGLMapParameter *param)
source["url"] = param->property("url");
m_sourceChanges << source;
} else if (sourceType == "geojson") {
QFile geojson(param->property("data").toString());
geojson.open(QIODevice::ReadOnly);
source["data"] = geojson.readAll();
auto data = param->property("data").toString();
if (data.startsWith(':')) {
QFile geojson(data);
geojson.open(QIODevice::ReadOnly);
source["data"] = geojson.readAll();
} else {
source["data"] = data.toUtf8();
}
m_sourceChanges << source;
} else {
m_error = QGeoServiceProvider::UnknownParameterError;