History

incorporate code review feedback

Seth Alves committed 11 years ago

Commit bed37ef1 parent c90ca4b7 files · +69 −56Browse files

Showing the changes to libraries/shared/src/VariantMapToScriptValue.cpp (1 of 7 files). Show all

Unified · Split

libraries/shared/src/VariantMapToScriptValue.cpp+47−0
@@ -0,0 +1,47 @@
1+//
2+// VariantMapToScriptValue.cpp
3+// libraries/shared/src/
4+//
5+// Created by Brad Hefta-Gaub on 12/6/13.
6+// Copyright 2013 High Fidelity, Inc.
7+//
8+// Distributed under the Apache License, Version 2.0.
9+// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10+//
11+
12+#include <QDebug>
13+#include "VariantMapToScriptValue.h"
14+
15+QScriptValue variantMapToScriptValue(QVariantMap& variantMap, QScriptEngine& scriptEngine) {
16+ QScriptValue scriptValue = scriptEngine.newObject();
17+
18+ for (QVariantMap::const_iterator iter = variantMap.begin(); iter != variantMap.end(); ++iter) {
19+ QString key = iter.key();
20+ QVariant qValue = iter.value();
21+
22+ switch(qValue.type()) {
23+ case QVariant::Bool:
24+ scriptValue.setProperty(key, qValue.toBool());
25+ break;
26+ case QVariant::Int:
27+ scriptValue.setProperty(key, qValue.toInt());
28+ break;
29+ case QVariant::Double:
30+ scriptValue.setProperty(key, qValue.toDouble());
31+ break;
32+ case QVariant::String: {
33+ scriptValue.setProperty(key, scriptEngine.newVariant(qValue));
34+ break;
35+ }
36+ case QVariant::Map: {
37+ QVariantMap childMap = qValue.toMap();
38+ scriptValue.setProperty(key, variantMapToScriptValue(childMap, scriptEngine));
39+ break;
40+ }
41+ default:
42+ qDebug() << "unhandled QScript type" << qValue.type();
43+ }
44+ }
45+
46+ return scriptValue;
47+}