aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
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
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')
-rw-r--r--tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp59
-rw-r--r--tests/auto/qml/qquicklistmodelworkerscript/tst_qquicklistmodelworkerscript.cpp47
2 files changed, 44 insertions, 62 deletions
diff --git a/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp b/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
index e4045ebe88..4c1a472269 100644
--- a/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
+++ b/tests/auto/qml/qquicklistmodel/tst_qquicklistmodel.cpp
@@ -86,7 +86,10 @@ class tst_qquicklistmodel : public QQmlDataTest
{
Q_OBJECT
public:
- tst_qquicklistmodel() {}
+ tst_qquicklistmodel()
+ {
+ qRegisterMetaType<QVector<int> >();
+ }
private:
int roleFromName(const QQuickListModel *model, const QString &roleName);
@@ -146,7 +149,7 @@ bool tst_qquicklistmodel::compareVariantList(const QVariantList &testList, QVari
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();
@@ -155,14 +158,7 @@ bool tst_qquicklistmodel::compareVariantList(const QVariantList &testList, QVari
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;
@@ -184,12 +180,7 @@ bool tst_qquicklistmodel::compareVariantList(const QVariantList &testList, QVari
int tst_qquicklistmodel::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);
}
void tst_qquicklistmodel::static_types_data()
@@ -720,11 +711,11 @@ void tst_qquicklistmodel::set()
RUNEXPR("model.set(0, {test:true})");
QCOMPARE(RUNEXPR("model.get(0).test").toBool(), true); // triggers creation of model cache
- QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(true));
+ QCOMPARE(model.data(0, 0), qVariantFromValue(true));
RUNEXPR("model.set(0, {test:false})");
QCOMPARE(RUNEXPR("model.get(0).test").toBool(), false); // tests model cache is updated
- QCOMPARE(model.data(0, model.roles()[0]), qVariantFromValue(false));
+ QCOMPARE(model.data(0, 0), qVariantFromValue(false));
QString warning = QString::fromLatin1("<Unknown File>: Can't create role for unsupported data type");
if (isValidErrorMessage(warning, dynamicRoles))
@@ -759,7 +750,7 @@ void tst_qquicklistmodel::get()
RUNEXPR("model.append({roleC: {} })");
RUNEXPR("model.append({roleD: [ { a:1, b:2 }, { c: 3 } ] })");
- QSignalSpy spy(model, SIGNAL(itemsChanged(int, int, QList<int>)));
+ QSignalSpy spy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
QQmlExpression expr(engine.rootContext(), model, expression);
expr.evaluate();
QVERIFY(!expr.hasError());
@@ -777,9 +768,9 @@ void tst_qquicklistmodel::get()
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
- QCOMPARE(spyResult.at(2).value<QList<int> >(), (QList<int>() << 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
+ QCOMPARE(spyResult.at(2).value<QVector<int> >(), (QVector<int>() << role));
delete model;
}
@@ -887,7 +878,7 @@ void tst_qquicklistmodel::get_nested()
QString extendedExpression = QString("get(%1).%2.%3").arg(outerListIndex).arg(outerListRoleName).arg(expression);
QQmlExpression expr(engine.rootContext(), model, extendedExpression);
- QSignalSpy spy(childModel, SIGNAL(itemsChanged(int, int, QList<int>)));
+ QSignalSpy spy(childModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
expr.evaluate();
QVERIFY(!expr.hasError());
@@ -901,9 +892,9 @@ void tst_qquicklistmodel::get_nested()
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
- QCOMPARE(spyResult.at(2).value<QList<int> >(), (QList<int>() << role));
+ QCOMPARE(spyResult.at(0).value<QModelIndex>(), childModel->index(index, 0, QModelIndex()));
+ QCOMPARE(spyResult.at(1).value<QModelIndex>(), childModel->index(index, 0, QModelIndex())); // only 1 item is modified at a time
+ QCOMPARE(spyResult.at(2).value<QVector<int> >(), (QVector<int>() << role));
}
delete model;
@@ -978,7 +969,7 @@ void tst_qquicklistmodel::property_changes()
QObject *connectionsObject = component.create();
QVERIFY2(component.errorString().isEmpty(), QTest::toString(component.errorString()));
- QSignalSpy spyItemsChanged(&model, SIGNAL(itemsChanged(int, int, QList<int>)));
+ QSignalSpy spyItemsChanged(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
expr.setExpression(script_change);
expr.evaluate();
@@ -990,8 +981,8 @@ void tst_qquicklistmodel::property_changes()
// 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);
}
@@ -1111,13 +1102,13 @@ void tst_qquicklistmodel::clear()
// clearing does not remove the roles
RUNEXPR("model.append({propertyA: \"value a\", propertyB: \"value b\", propertyC: \"value c\"})");
- QList<int> roles = model.roles();
+ QHash<int, QByteArray> roleNames = model.roleNames();
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"));
+ QCOMPARE(model.roleNames(), roleNames);
+ QCOMPARE(roleNames[0], QByteArray("propertyA"));
+ QCOMPARE(roleNames[1], QByteArray("propertyB"));
+ QCOMPARE(roleNames[2], QByteArray("propertyC"));
}
void tst_qquicklistmodel::signal_handlers_data()
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);