summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp6
-rw-r--r--tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp43
2 files changed, 47 insertions, 2 deletions
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index e148469..3e08854 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -532,7 +532,7 @@ QHash<int,QVariant> QDeclarativeXmlListModel::data(int index, const QList<int> &
for (int i = 0; i < roles.size(); ++i) {
int role = roles.at(i);
int roleIndex = d->roles.indexOf(role);
- rv.insert(role, roleIndex == -1 ? QVariant() : d->data.at(roleIndex).at(index));
+ rv.insert(role, roleIndex == -1 ? QVariant() : d->data.value(roleIndex).value(index));
}
return rv;
}
@@ -541,7 +541,7 @@ QVariant QDeclarativeXmlListModel::data(int index, int role) const
{
Q_D(const QDeclarativeXmlListModel);
int roleIndex = d->roles.indexOf(role);
- return (roleIndex == -1) ? QVariant() : d->data.at(roleIndex).at(index);
+ return (roleIndex == -1) ? QVariant() : d->data.value(roleIndex).value(index);
}
/*!
@@ -728,6 +728,8 @@ void QDeclarativeXmlListModel::componentComplete()
Otherwise, items are only added if the model does not already
contain items with matching key role values.
+
+ \sa XmlRole::isKey
*/
void QDeclarativeXmlListModel::reload()
{
diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
index 81cc922..e3aa5cc 100644
--- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp
@@ -69,6 +69,8 @@ private slots:
void roles();
void roleErrors();
void uniqueRoleNames();
+ void status();
+ void data();
void reload();
void useKeys();
void useKeys_data();
@@ -247,6 +249,47 @@ void tst_qdeclarativexmllistmodel::uniqueRoleNames()
delete model;
}
+void tst_qdeclarativexmllistmodel::status()
+{
+ QDeclarativeXmlListModel *model;
+ model = new QDeclarativeXmlListModel;
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Null);
+
+ model->setXml("<data></data>");
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Ready);
+ delete model;
+
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Loading);
+
+ QTRY_COMPARE(model->count(), 9);
+ QCOMPARE(model->status(), QDeclarativeXmlListModel::Ready);
+
+ delete model;
+}
+
+void tst_qdeclarativexmllistmodel::data()
+{
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/model.qml"));
+ QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create());
+ QVERIFY(model != 0);
+
+ QHash<int,QVariant> blank;
+ for (int i=0; i<model->roles().count(); i++)
+ blank.insert(model->roles()[i], QVariant());
+ for (int i=0; i<9; i++) {
+ QCOMPARE(model->data(i, model->roles()), blank);
+ for (int j=0; j<model->roles().count(); j++) {
+ QCOMPARE(model->data(i, j), QVariant());
+ }
+ }
+ QTRY_COMPARE(model->count(), 9);
+
+ delete model;
+}
+
void tst_qdeclarativexmllistmodel::reload()
{
// If no keys are used, the model should be rebuilt from scratch when