diff options
-rw-r--r-- | src/declarative/util/qdeclarativelistmodel.cpp | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp | 26 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index 1a28176..ce7681a 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -1273,6 +1273,8 @@ void ModelNode::setObjectValue(const QScriptValue& valuemap) { value->setListValue(v); } else { value->values << v.toVariant(); + if (objectCache) + objectCache->setValue(it.name().toUtf8(), value->values.last()); } if (properties.contains(it.name())) delete properties[it.name()]; diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index 12000d0..d02f54f 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -41,6 +41,7 @@ #include <qtest.h> #include <QtDeclarative/private/qdeclarativeitem_p.h> #include <QtDeclarative/private/qdeclarativetext_p.h> +#include <QtDeclarative/private/qdeclarativeengine_p.h> #include <QtDeclarative/private/qdeclarativelistmodel_p.h> #include <QtDeclarative/private/qdeclarativeexpression_p.h> #include <QDeclarativeComponent> @@ -77,6 +78,7 @@ private slots: void convertNestedToFlat_ok_data(); void error_data(); void error(); + void set(); }; QScriptValue tst_QDeclarativeListModel::nestedListValue(QScriptEngine *eng) const @@ -550,6 +552,30 @@ void tst_QDeclarativeListModel::error() } } +void tst_QDeclarativeListModel::set() +{ + QDeclarativeEngine engine; + QDeclarativeListModel model; + QDeclarativeEngine::setContextForObject(&model,engine.rootContext()); + engine.rootContext()->setContextObject(&model); + QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(&engine); + + QScriptValue sv = seng->newObject(); + sv.setProperty("test", QScriptValue(false)); + model.append(sv); + + sv.setProperty("test", QScriptValue(true)); + model.set(0, sv); + QCOMPARE(model.get(0).property("test").toBool(), true); // triggers creation of model cache + QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(true)); + + sv.setProperty("test", QScriptValue(false)); + model.set(0, sv); + QCOMPARE(model.get(0).property("test").toBool(), false); // tests model cache is updated + QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(false)); +} + + QTEST_MAIN(tst_QDeclarativeListModel) #include "tst_qdeclarativelistmodel.moc" |