improve support for arrays and objects passed in to setData

svn path=/trunk/KDE/kdebase/runtime/; revision=1175910
This commit is contained in:
Aaron J. Seigo 2010-09-16 05:36:28 +00:00
parent 0eb578462c
commit 7db67d1164

View File

@ -120,9 +120,10 @@ QScriptValue JavaScriptDataEngine::jsSetData(QScriptContext *context, QScriptEng
} }
const QString source = context->argument(0).toString(); const QString source = context->argument(0).toString();
if (context->argument(1).isArray()) { if (context->argument(1).isArray() || context->argument(1).isObject()) {
QScriptValueIterator it(context->argument(1)); QScriptValueIterator it(context->argument(1));
DataEngine::Data data; DataEngine::Data data;
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
data.insert(it.name(), it.value().toVariant()); data.insert(it.name(), it.value().toVariant());
@ -132,9 +133,19 @@ QScriptValue JavaScriptDataEngine::jsSetData(QScriptContext *context, QScriptEng
} else { } else {
QString value = context->argument(1).toString(); QString value = context->argument(1).toString();
if (context->argumentCount() > 2) { if (context->argumentCount() > 2) {
const QString key = value; if (context->argument(2).isArray() || context->argument(2).isObject()) {
value = context->argument(2).toString(); QScriptValueIterator it(context->argument(2));
iFace->setData(source, key, value); DataEngine::Data data;
while (it.hasNext()) {
it.next();
data.insert(it.name(), it.value().toVariant());
}
iFace->setData(source, value, data);
} else {
iFace->setData(source, value, context->argument(2).toString());
}
} else { } else {
iFace->setData(source, value); iFace->setData(source, value);
} }