summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/util/qmlxmllistmodel.cpp26
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/data/unique.qml8
-rw-r--r--tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp15
3 files changed, 32 insertions, 17 deletions
diff --git a/src/declarative/util/qmlxmllistmodel.cpp b/src/declarative/util/qmlxmllistmodel.cpp
index 3d90b44..8407b1d 100644
--- a/src/declarative/util/qmlxmllistmodel.cpp
+++ b/src/declarative/util/qmlxmllistmodel.cpp
@@ -132,8 +132,6 @@ struct QmlXmlRoleList : public QmlConcreteList<QmlXmlListModelRole *>
QmlXmlRoleList(QmlXmlListModelPrivate *p)
: model(p) {}
virtual void append(QmlXmlListModelRole *role);
- //XXX clear, removeAt, and insert need to invalidate any cached data (in data table) as well
- // (and the model should emit the appropriate signals)
virtual void clear();
virtual void removeAt(int i);
virtual void insert(int i, QmlXmlListModelRole *role);
@@ -309,7 +307,7 @@ void QmlXmlQuery::doSubQueryJob()
b.seek(0);
}
- //XXX this method is much slower, but would work better for incremental loading
+ //this method is much slower, but works better for incremental loading
/*for (int j = 0; j < m_size; ++j) {
QList<QVariant> resultList;
for (int i = 0; i < m_roleObjects->size(); ++i) {
@@ -338,13 +336,6 @@ void QmlXmlQuery::doSubQueryJob()
}*/
}
-
-//TODO: error handling (currently quite fragile)
-// profile doQuery and doSubquery
-// support complex/nested objects?
-// how do we handle data updates (like rss feed -- usually items inserted at beginning)
-
-
class QmlXmlListModelPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QmlXmlListModel)
@@ -373,14 +364,12 @@ public:
};
-void QmlXmlRoleList::append(QmlXmlListModelRole *role) {
- QmlConcreteList<QmlXmlListModelRole *>::append(role);
- model->roles << model->highestRole;
- model->roleNames << role->name();
- ++model->highestRole;
+void QmlXmlRoleList::append(QmlXmlListModelRole *role)
+{
+ insert(size(), role);
}
-//XXX clear, removeAt, and insert need to invalidate any cached data (in data table) as well
+//### clear, removeAt, and insert need to invalidate any cached data (in data table) as well
// (and the model should emit the appropriate signals)
void QmlXmlRoleList::clear()
{
@@ -396,10 +385,13 @@ void QmlXmlRoleList::removeAt(int i)
QmlConcreteList<QmlXmlListModelRole *>::removeAt(i);
}
-//### we should enforce unique role names
void QmlXmlRoleList::insert(int i, QmlXmlListModelRole *role)
{
QmlConcreteList<QmlXmlListModelRole *>::insert(i, role);
+ if (model->roleNames.contains(role->name())) {
+ qmlInfo(role) << QObject::tr("\"%1\" duplicates a previous role name and will be disabled.").arg(role->name());
+ return;
+ }
model->roles.insert(i, model->highestRole);
model->roleNames.insert(i, role->name());
++model->highestRole;
diff --git a/tests/auto/declarative/qmlxmllistmodel/data/unique.qml b/tests/auto/declarative/qmlxmllistmodel/data/unique.qml
new file mode 100644
index 0000000..ed0f293
--- /dev/null
+++ b/tests/auto/declarative/qmlxmllistmodel/data/unique.qml
@@ -0,0 +1,8 @@
+import Qt 4.6
+
+XmlListModel {
+ source: "model.xml"
+ query: "/Pets/Pet"
+ XmlRole { name: "name"; query: "name/string()" }
+ XmlRole { name: "name"; query: "type/string()" }
+}
diff --git a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp
index 71bc4f9..a68006d 100644
--- a/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp
+++ b/tests/auto/declarative/qmlxmllistmodel/tst_qmlxmllistmodel.cpp
@@ -58,6 +58,7 @@ private slots:
void attributes();
void roles();
void roleErrors();
+ void uniqueRoleNames();
private:
QmlEngine engine;
@@ -175,6 +176,20 @@ void tst_qmlxmllistmodel::roleErrors()
delete listModel;
}
+void tst_qmlxmllistmodel::uniqueRoleNames()
+{
+ QmlComponent component(&engine, QUrl("file://" SRCDIR "/data/unique.qml"));
+ QTest::ignoreMessage(QtWarningMsg, "QML QmlXmlListModelRole (file://" SRCDIR "/data/unique.qml:7:5) \"name\" duplicates a previous role name and will be disabled.");
+ QmlXmlListModel *listModel = qobject_cast<QmlXmlListModel*>(component.create());
+ QVERIFY(listModel != 0);
+ QTRY_COMPARE(listModel->count(), 9);
+
+ QList<int> roles = listModel->roles();
+ QCOMPARE(roles.count(), 1);
+
+ delete listModel;
+}
+
QTEST_MAIN(tst_qmlxmllistmodel)
#include "tst_qmlxmllistmodel.moc"