Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 17 files). Show all
Unified · Split
| @@ -369,3 +369,41 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra · 368 unmodified lines | |||
| 369 | vec3FromScriptValue(intersection, value.intersection); | 369 | vec3FromScriptValue(intersection, value.intersection); |
| 370 | } | 370 | } |
| 371 | } | 371 | } |
| 372 | |||
| 373 | |||
| 374 | // XXX why can't I find a call that does this? | ||
| 375 | QScriptValue variantMapToQScriptValue(QVariantMap& variantMap, QScriptEngine& scriptEngine) { | ||
| 376 | QScriptValue scriptValue = scriptEngine.newObject(); | ||
| 377 | |||
| 378 | for (QVariantMap::const_iterator iter = variantMap.begin(); iter != variantMap.end(); ++iter) { | ||
| 379 | QString key = iter.key(); | ||
| 380 | QVariant qValue = iter.value(); | ||
| 381 | |||
| 382 | qDebug() << key << "=" << qValue; | ||
| 383 | |||
| 384 | switch(qValue.type()) { | ||
| 385 | case QVariant::Bool: | ||
| 386 | scriptValue.setProperty(key, qValue.toBool()); | ||
| 387 | break; | ||
| 388 | case QVariant::Int: | ||
| 389 | scriptValue.setProperty(key, qValue.toInt()); | ||
| 390 | break; | ||
| 391 | case QVariant::Double: | ||
| 392 | scriptValue.setProperty(key, qValue.toDouble()); | ||
| 393 | break; | ||
| 394 | case QVariant::String: { | ||
| 395 | scriptValue.setProperty(key, scriptEngine.newVariant(qValue)); | ||
| 396 | break; | ||
| 397 | } | ||
| 398 | case QVariant::Map: { | ||
| 399 | QVariantMap childMap = qValue.toMap(); | ||
| 400 | scriptValue.setProperty(key, variantMapToQScriptValue(childMap, scriptEngine)); | ||
| 401 | break; | ||
| 402 | } | ||
| 403 | default: | ||
| 404 | qDebug() << "unhandled QScript type" << qValue.type(); | ||
| 405 | } | ||
| 406 | } | ||
| 407 | |||
| 408 | return scriptValue; | ||
| 409 | } | ||