summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-08-27 04:57:02 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-08-27 04:57:02 (GMT)
commitc43cf8ad4f1ba7d6d9e2403520a7e54ceadee60c (patch)
treeca764dc2ccab18073debb909acd6f094a6f8b881 /tests
parent94d7ec29f177665e8e2a218a161df517f3ae51d5 (diff)
downloadQt-c43cf8ad4f1ba7d6d9e2403520a7e54ceadee60c.zip
Qt-c43cf8ad4f1ba7d6d9e2403520a7e54ceadee60c.tar.gz
Qt-c43cf8ad4f1ba7d6d9e2403520a7e54ceadee60c.tar.bz2
Fix VisualDataModel model update handling when rootIndex is specified.
Task-number: QTBUG-13038
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativevisualdatamodel/data/datalist.qml16
-rw-r--r--tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp61
2 files changed, 71 insertions, 6 deletions
diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/data/datalist.qml b/tests/auto/declarative/qdeclarativevisualdatamodel/data/datalist.qml
index a798f77..c5e945a 100644
--- a/tests/auto/declarative/qdeclarativevisualdatamodel/data/datalist.qml
+++ b/tests/auto/declarative/qdeclarativevisualdatamodel/data/datalist.qml
@@ -4,12 +4,16 @@ ListView {
width: 100
height: 100
anchors.fill: parent
- model: myModel
- delegate: Component {
- Rectangle {
- height: 25
- width: 100
- Text { objectName: "display"; text: display }
+ model: VisualDataModel {
+ id: visualModel
+ objectName: "visualModel"
+ model: myModel
+ delegate: Component {
+ Rectangle {
+ height: 25
+ width: 100
+ Text { objectName: "display"; text: display }
+ }
}
}
}
diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
index 3cd786f..95ef4fc 100644
--- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
+++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
@@ -84,6 +84,7 @@ public:
private slots:
void rootIndex();
void updateLayout();
+ void childChanged();
void objectListModel();
private:
@@ -174,22 +175,82 @@ void tst_qdeclarativevisualdatamodel::updateLayout()
QVERIFY(contentItem != 0);
QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "display", 0);
+ QVERIFY(name);
QCOMPARE(name->text(), QString("Row 1 Item"));
name = findItem<QDeclarativeText>(contentItem, "display", 1);
+ QVERIFY(name);
QCOMPARE(name->text(), QString("Row 2 Item"));
name = findItem<QDeclarativeText>(contentItem, "display", 2);
+ QVERIFY(name);
QCOMPARE(name->text(), QString("Row 3 Item"));
model.invisibleRootItem()->sortChildren(0, Qt::DescendingOrder);
name = findItem<QDeclarativeText>(contentItem, "display", 0);
+ QVERIFY(name);
QCOMPARE(name->text(), QString("Row 3 Item"));
name = findItem<QDeclarativeText>(contentItem, "display", 1);
+ QVERIFY(name);
QCOMPARE(name->text(), QString("Row 2 Item"));
name = findItem<QDeclarativeText>(contentItem, "display", 2);
+ QVERIFY(name);
QCOMPARE(name->text(), QString("Row 1 Item"));
}
+void tst_qdeclarativevisualdatamodel::childChanged()
+{
+ QDeclarativeView view;
+
+ QStandardItemModel model;
+ initStandardTreeModel(&model);
+
+ view.rootContext()->setContextProperty("myModel", &model);
+
+ view.setSource(QUrl::fromLocalFile(SRCDIR "/data/datalist.qml"));
+
+ QDeclarativeListView *listview = qobject_cast<QDeclarativeListView*>(view.rootObject());
+ QVERIFY(listview != 0);
+
+ QDeclarativeItem *contentItem = listview->contentItem();
+ QVERIFY(contentItem != 0);
+
+ QDeclarativeVisualDataModel *vdm = listview->findChild<QDeclarativeVisualDataModel*>("visualModel");
+ vdm->setRootIndex(QVariant::fromValue(model.indexFromItem(model.item(1,0))));
+
+ QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "display", 0);
+ QVERIFY(name);
+ QCOMPARE(name->text(), QString("Row 2 Child Item"));
+
+ model.item(1,0)->child(0,0)->setText("Row 2 updated child");
+
+ name = findItem<QDeclarativeText>(contentItem, "display", 0);
+ QVERIFY(name);
+ QCOMPARE(name->text(), QString("Row 2 updated child"));
+
+ model.item(1,0)->appendRow(new QStandardItem(QLatin1String("Row 2 Child Item 2")));
+ QTest::qWait(300);
+
+ name = findItem<QDeclarativeText>(contentItem, "display", 1);
+ QVERIFY(name != 0);
+ QCOMPARE(name->text(), QString("Row 2 Child Item 2"));
+
+ model.item(1,0)->takeRow(1);
+ name = findItem<QDeclarativeText>(contentItem, "display", 1);
+ QVERIFY(name == 0);
+
+ vdm->setRootIndex(QVariant::fromValue(QModelIndex()));
+ QTest::qWait(300);
+ name = findItem<QDeclarativeText>(contentItem, "display", 0);
+ QVERIFY(name);
+ QCOMPARE(name->text(), QString("Row 1 Item"));
+ name = findItem<QDeclarativeText>(contentItem, "display", 1);
+ QVERIFY(name);
+ QCOMPARE(name->text(), QString("Row 2 Item"));
+ name = findItem<QDeclarativeText>(contentItem, "display", 2);
+ QVERIFY(name);
+ QCOMPARE(name->text(), QString("Row 3 Item"));
+}
+
void tst_qdeclarativevisualdatamodel::objectListModel()
{
QDeclarativeView view;