diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-11-13 03:09:40 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-11-13 03:16:46 (GMT) |
commit | f21957b3bb12a16a905f79f3a791931eb77663d9 (patch) | |
tree | fa95f3708fb27f954f7fc44821449106b1f0e15f /src/declarative/util/qmlxmllistmodel.cpp | |
parent | db3ae6188c8f88f25b4f8e2645e76a7c6fffef18 (diff) | |
download | Qt-f21957b3bb12a16a905f79f3a791931eb77663d9.zip Qt-f21957b3bb12a16a905f79f3a791931eb77663d9.tar.gz Qt-f21957b3bb12a16a905f79f3a791931eb77663d9.tar.bz2 |
Enforce unique role names for XmlListModel.
Diffstat (limited to 'src/declarative/util/qmlxmllistmodel.cpp')
-rw-r--r-- | src/declarative/util/qmlxmllistmodel.cpp | 26 |
1 files changed, 9 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; |