diff options
author | Bea Lam <bea.lam@nokia.com> | 2011-04-08 04:20:17 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2011-04-12 01:07:48 (GMT) |
commit | 6ec7695eaa02c923b90d72e3918b9ab50da63e41 (patch) | |
tree | 79730f4d1e6ef69f5ccaf87b14d9bc9ee38d40cb /tests | |
parent | 051a76c1d65d698f71dc75c89f91ae9021357eae (diff) | |
download | Qt-6ec7695eaa02c923b90d72e3918b9ab50da63e41.zip Qt-6ec7695eaa02c923b90d72e3918b9ab50da63e41.tar.gz Qt-6ec7695eaa02c923b90d72e3918b9ab50da63e41.tar.bz2 |
ListModel::clear() should not clear roles
Clearing a model and then appending a new object with a subset of the
previous roles was causing a crash since ListModel cleared the roles
and VisualDataModel did not, so VisualDataModel was requesting invalid
roles. This could have been fixed by clearing the meta object and
its property cache in in VisualDataModel but this is less efficient,
and also the general use case is for model data to always have the same
roles.
Task-number: QTBUG-18587
Change-Id: Ib11d2292888ab7a41e772b1e11700cd665e94ae7
Reviewed-by: Michael Brasser
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index 45072f3..2f7513f 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -106,6 +106,7 @@ private slots: void property_changes_data(); void property_changes_worker(); void property_changes_worker_data(); + void clear(); }; int tst_qdeclarativelistmodel::roleFromName(const QDeclarativeListModel *model, const QString &roleName) { @@ -1091,6 +1092,47 @@ void tst_qdeclarativelistmodel::property_changes_worker_data() property_changes_data(); } +void tst_qdeclarativelistmodel::clear() +{ + QDeclarativeEngine engine; + QDeclarativeListModel model; + QDeclarativeEngine::setContextForObject(&model, engine.rootContext()); + engine.rootContext()->setContextObject(&model); + + QScriptEngine *seng = QDeclarativeEnginePrivate::getScriptEngine(&engine); + QScriptValue sv = seng->newObject(); + QVariant result; + + model.clear(); + QCOMPARE(model.count(), 0); + + sv.setProperty("propertyA", "value a"); + sv.setProperty("propertyB", "value b"); + model.append(sv); + QCOMPARE(model.count(), 1); + + model.clear(); + QCOMPARE(model.count(), 0); + + model.append(sv); + model.append(sv); + QCOMPARE(model.count(), 2); + + model.clear(); + QCOMPARE(model.count(), 0); + + // clearing does not remove the roles + sv.setProperty("propertyC", "value c"); + model.append(sv); + QList<int> roles = model.roles(); + model.clear(); + QCOMPARE(model.count(), 0); + QCOMPARE(model.roles(), roles); + QCOMPARE(model.toString(roles[0]), QString("propertyA")); + QCOMPARE(model.toString(roles[1]), QString("propertyB")); + QCOMPARE(model.toString(roles[2]), QString("propertyC")); +} + QTEST_MAIN(tst_qdeclarativelistmodel) #include "tst_qdeclarativelistmodel.moc" |