diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-06-12 05:17:09 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-06-12 05:17:09 (GMT) |
commit | 815df4da786a778517b1fac8435cc052d791ce92 (patch) | |
tree | c156a5c9272339ab13331fb668871abddde24168 /src/declarative/extra | |
parent | d3f42ead5e9de12dd1f733461ccb1a1298f6966f (diff) | |
download | Qt-815df4da786a778517b1fac8435cc052d791ce92.zip Qt-815df4da786a778517b1fac8435cc052d791ce92.tar.gz Qt-815df4da786a778517b1fac8435cc052d791ce92.tar.bz2 |
Speed up XmlListModel.
Diffstat (limited to 'src/declarative/extra')
-rw-r--r-- | src/declarative/extra/qmlxmllistmodel.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp index 62ede80..b10f5fd 100644 --- a/src/declarative/extra/qmlxmllistmodel.cpp +++ b/src/declarative/extra/qmlxmllistmodel.cpp @@ -202,11 +202,10 @@ void QmlXmlQuery::doQueryJob() QXmlItem item(result.next()); if (item.isAtomicValue()) count = item.toAtomicValue().toInt(); - prefix += QLatin1String("[%1]/"); } //qDebug() << count; - m_prefix = namespaces + prefix; + m_prefix = namespaces + prefix + QLatin1String("/"); m_data = xml; if (count > 0) m_size = count; @@ -222,8 +221,24 @@ void QmlXmlQuery::doSubQueryJob() QXmlQuery subquery; subquery.bindVariable(QLatin1String("inputDocument"), &b); - //XXX should we use an array of objects or something else rather than a table? - for (int j = 0; j < m_size; ++j) { + //### we might be able to condense even further (query for everything in one go) + for (int i = 0; i < m_roleObjects->size(); ++i) { + XmlListModelRole *role = m_roleObjects->at(i); + subquery.setQuery(m_prefix + QLatin1String("(let $v := ") + role->query() + QLatin1String(" return if ($v) then ") + role->query() + QLatin1String(" else \"\")")); + QXmlResultItems output3; + subquery.evaluateTo(&output3); + QXmlItem item(output3.next()); + QList<QVariant> resultList; + while (!item.isNull()) { + resultList << item.toAtomicValue(); + item = output3.next(); + } + m_modelData << resultList; + b.seek(0); + } + + //XXX this method is much slower, but would work better for incremental loading + /*for (int j = 0; j < m_size; ++j) { QList<QVariant> resultList; for (int i = 0; i < m_roleObjects->size(); ++i) { XmlListModelRole *role = m_roleObjects->at(i); @@ -248,7 +263,7 @@ void QmlXmlQuery::doSubQueryJob() b.seek(0); } m_modelData << resultList; - } + }*/ } @@ -362,7 +377,7 @@ QHash<int,QVariant> QmlXmlListModel::data(int index, const QList<int> &roles) co for (int i = 0; i < roles.size(); ++i) { int role = roles.at(i); int roleIndex = d->roles.indexOf(role); - rv.insert(role, d->data.at(index).at(roleIndex)); + rv.insert(role, d->data.at(roleIndex).at(index)); } return rv; } @@ -462,8 +477,8 @@ void QmlXmlListModel::reload() d->queryId = -1; //clear existing data + int count = d->size; d->size = 0; - int count = d->data.count(); d->data.clear(); if (count > 0) emit itemsRemoved(0, count); |