From ddcf9fc80e074c5a9d1ecbbf3c60ca27f250ce98 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Thu, 4 Jul 2013 12:14:44 +0200 Subject: Don't assume that the last step of the XPath is an element name In order to find the number of items in the model, the model did a second query on the document representing the result set. So, suppose the user queried for //a/b/c, the result set would contain all the 'c' elements from the input document. In order to find the number of items in the result set, it did a second query with the expression "count(/dummy:items/c)", where 'c' was extracted from the last step in the original XPath expression For simple expressions, this worked fine. However, if the last step had a predicate such as "//c/parent::b" it didn't work. The solution is to not filter *again* the last step when we query for the count, since we know that all result items are direct children of "dummy:items", and instead just execute the query "count(dummy::items/*)". This should also potentially improve performance. Task-number: QTBUG-17588 Change-Id: Ib2fdf1ec8b91022df0597e089ad34d34b04428b0 Reviewed-by: Alan Alpert --- src/imports/xmllistmodel/qqmlxmllistmodel.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/imports/xmllistmodel') diff --git a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp index 856c063cbb..7cc4e64522 100644 --- a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp +++ b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp @@ -388,8 +388,7 @@ void QQuickXmlQueryEngine::doQueryJob(XmlQueryJob *currentJob, QQuickXmlQueryRes b.open(QIODevice::ReadOnly); QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + currentJob->namespaces; - QString prefix = QLatin1String("doc($inputDocument)/dummy:items") + - currentJob->query.mid(currentJob->query.lastIndexOf(QLatin1Char('/'))); + QString prefix = QLatin1String("doc($inputDocument)/dummy:items/*"); //figure out how many items we are dealing with int count = -1; -- cgit v1.2.3