aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qquicklistmodelworkerscript
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-07-10 17:01:52 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-25 02:15:15 +0200
commit7daab8039abc32ab5be5706a08cb58905fe0e0b6 (patch)
tree9ceb8afdeb37ac4d9bc089545e73e31040b847e4 /tests/auto/qml/qquicklistmodelworkerscript
parentb355aacb6e5c4f9b7ebb317125409ea0959d11d6 (diff)
Remove QListModelInterface.
Implement ListModel and XmlListModel using QAbstractListModel instead. Task-number: QTBUG-15728 Change-Id: I14e03d90883d341f4b1d89c1e9fc9dc1534fde78 Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
Diffstat (limited to 'tests/auto/qml/qquicklistmodelworkerscript')
-rw-r--r--tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp47
1 files changed, 19 insertions, 28 deletions
diff --git a/tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp b/tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp
index c5d16e53f4..8227eb587b 100644
--- a/tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp
+++ b/tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp
@@ -85,7 +85,10 @@ class tst_qquicklistmodelworkerscript : public QQmlDataTest
{
Q_OBJECT
public:
- tst_qquicklistmodelworkerscript() {}
+ tst_qquicklistmodelworkerscript()
+ {
+ qRegisterMetaType<QVector<int> >();
+ }
private:
int roleFromName(const QQuickListModel *model, const QString &roleName);
@@ -133,7 +136,7 @@ bool tst_qquicklistmodelworkerscript::compareVariantList(const QVariantList &tes
return false;
const QVariantMap &map = testVariant.toMap();
- const QList<int> &roles = model->roles();
+ const QHash<int, QByteArray> roleNames = model->roleNames();
QVariantMap::const_iterator it = map.begin();
QVariantMap::const_iterator end = map.end();
@@ -142,18 +145,11 @@ bool tst_qquicklistmodelworkerscript::compareVariantList(const QVariantList &tes
const QString &testKey = it.key();
const QVariant &testData = it.value();
- int roleIndex = -1;
- for (int j=0 ; j < roles.count() ; ++j) {
- if (model->toString(roles[j]).compare(testKey) == 0) {
- roleIndex = j;
- break;
- }
- }
-
+ int roleIndex = roleNames.key(testKey.toUtf8(), -1);
if (roleIndex == -1)
return false;
- const QVariant &modelData = model->data(i, roleIndex);
+ const QVariant &modelData = model->data(model->index(i, 0, QModelIndex()), roleIndex);
if (testData.type() == QVariant::List) {
const QVariantList &subList = testData.toList();
@@ -171,12 +167,7 @@ bool tst_qquicklistmodelworkerscript::compareVariantList(const QVariantList &tes
int tst_qquicklistmodelworkerscript::roleFromName(const QQuickListModel *model, const QString &roleName)
{
- QList<int> roles = model->roles();
- for (int i=0; i<roles.count(); i++) {
- if (model->toString(roles[i]) == roleName)
- return roles[i];
- }
- return -1;
+ return model->roleNames().key(roleName.toUtf8(), -1);
}
QQuickItem *tst_qquicklistmodelworkerscript::createWorkerTest(QQmlEngine *eng, QQmlComponent *component, QQuickListModel *model)
@@ -497,7 +488,7 @@ void tst_qquicklistmodelworkerscript::get_worker()
int role = roleFromName(&model, roleName);
QVERIFY(role >= 0);
- QSignalSpy spy(&model, SIGNAL(itemsChanged(int, int, QList<int>)));
+ QSignalSpy spy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
// in the worker thread, change the model data and call sync()
QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker",
@@ -515,9 +506,9 @@ void tst_qquicklistmodelworkerscript::get_worker()
QCOMPARE(spy.count(), 1);
QList<QVariant> spyResult = spy.takeFirst();
- QCOMPARE(spyResult.at(0).toInt(), index);
- QCOMPARE(spyResult.at(1).toInt(), 1); // only 1 item is modified at a time
- QVERIFY(spyResult.at(2).value<QList<int> >().contains(role));
+ QCOMPARE(spyResult.at(0).value<QModelIndex>(), model.index(index, 0, QModelIndex()));
+ QCOMPARE(spyResult.at(1).value<QModelIndex>(), model.index(index, 0, QModelIndex())); // only 1 item is modified at a time
+ QVERIFY(spyResult.at(2).value<QVector<int> >().contains(role));
delete item;
}
@@ -621,7 +612,7 @@ void tst_qquicklistmodelworkerscript::property_changes_worker()
expr.evaluate();
QVERIFY2(!expr.hasError(), QTest::toString(expr.error().toString()));
- QSignalSpy spyItemsChanged(&model, SIGNAL(itemsChanged(int, int, QList<int>)));
+ QSignalSpy spyItemsChanged(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker",
Q_ARG(QVariant, QStringList(script_change))));
@@ -630,8 +621,8 @@ void tst_qquicklistmodelworkerscript::property_changes_worker()
// test itemsChanged() is emitted correctly
if (itemsChanged) {
QCOMPARE(spyItemsChanged.count(), 1);
- QCOMPARE(spyItemsChanged.at(0).at(0).toInt(), listIndex);
- QCOMPARE(spyItemsChanged.at(0).at(1).toInt(), 1);
+ QCOMPARE(spyItemsChanged.at(0).at(0).value<QModelIndex>(), model.index(listIndex, 0, QModelIndex()));
+ QCOMPARE(spyItemsChanged.at(0).at(1).value<QModelIndex>(), model.index(listIndex, 0, QModelIndex()));
} else {
QCOMPARE(spyItemsChanged.count(), 0);
}
@@ -674,8 +665,8 @@ void tst_qquicklistmodelworkerscript::worker_sync()
QVERIFY(childModel);
QVERIFY(childModel->count() == 1);
- QSignalSpy spyModelInserted(&model, SIGNAL(itemsInserted(int,int)));
- QSignalSpy spyChildInserted(childModel, SIGNAL(itemsInserted(int,int)));
+ QSignalSpy spyModelInserted(&model, SIGNAL(rowsInserted(QModelIndex,int,int)));
+ QSignalSpy spyChildInserted(childModel, SIGNAL(rowsInserted(QModelIndex,int,int)));
QVERIFY(QMetaObject::invokeMethod(item, "addItemViaWorker"));
waitForWorker(item);
@@ -729,7 +720,7 @@ void tst_qquicklistmodelworkerscript::worker_remove_element()
QQuickItem *item = createWorkerTest(&eng, &component, &model);
QVERIFY(item != 0);
- QSignalSpy spyModelRemoved(&model, SIGNAL(itemsRemoved(int,int)));
+ QSignalSpy spyModelRemoved(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)));
QVERIFY(model.count() == 0);
QVERIFY(spyModelRemoved.count() == 0);
@@ -792,7 +783,7 @@ void tst_qquicklistmodelworkerscript::worker_remove_list()
QQuickItem *item = createWorkerTest(&eng, &component, &model);
QVERIFY(item != 0);
- QSignalSpy spyModelRemoved(&model, SIGNAL(itemsRemoved(int,int)));
+ QSignalSpy spyModelRemoved(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)));
QVERIFY(model.count() == 0);
QVERIFY(spyModelRemoved.count() == 0);