diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-08-19 07:24:09 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-08-19 07:24:09 (GMT) |
commit | 52e14a2d02d1d664bd8b981d261db0a62592efb8 (patch) | |
tree | d315c6f53081a41bee4ccba540204eaeef66bb99 /examples | |
parent | 12bdeb146a479b008d9f65c022bb22a15989e558 (diff) | |
parent | 5fb5c01bd0ac234eaca890d97053c7b0772861a3 (diff) | |
download | Qt-52e14a2d02d1d664bd8b981d261db0a62592efb8.zip Qt-52e14a2d02d1d664bd8b981d261db0a62592efb8.tar.gz Qt-52e14a2d02d1d664bd8b981d261db0a62592efb8.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt into qtscript-jsc-backend
Diffstat (limited to 'examples')
-rw-r--r-- | examples/network/googlesuggest/googlesuggest.cpp | 7 | ||||
-rw-r--r-- | examples/xml/streambookmarks/xbelreader.cpp | 100 |
2 files changed, 38 insertions, 69 deletions
diff --git a/examples/network/googlesuggest/googlesuggest.cpp b/examples/network/googlesuggest/googlesuggest.cpp index ada0edf..4142511 100644 --- a/examples/network/googlesuggest/googlesuggest.cpp +++ b/examples/network/googlesuggest/googlesuggest.cpp @@ -134,7 +134,6 @@ bool GSuggestCompletion::eventFilter(QObject *obj, QEvent *ev) void GSuggestCompletion::showCompletion(const QStringList &choices, const QStringList &hits) { - if (choices.isEmpty() || choices.count() != hits.count()) return; @@ -204,16 +203,16 @@ void GSuggestCompletion::handleNetworkData(QNetworkReply *networkReply) QXmlStreamReader xml(response); while (!xml.atEnd()) { xml.readNext(); - if (xml.tokenType() == QXmlStreamReader::StartElement) + if (xml.isStartElement()) { if (xml.name() == "suggestion") { QStringRef str = xml.attributes().value("data"); choices << str.toString(); } - if (xml.tokenType() == QXmlStreamReader::StartElement) - if (xml.name() == "num_queries") { + else if (xml.name() == "num_queries") { QStringRef str = xml.attributes().value("int"); hits << str.toString(); } + } } showCompletion(choices, hits); diff --git a/examples/xml/streambookmarks/xbelreader.cpp b/examples/xml/streambookmarks/xbelreader.cpp index 47c8c3d..4472f8a 100644 --- a/examples/xml/streambookmarks/xbelreader.cpp +++ b/examples/xml/streambookmarks/xbelreader.cpp @@ -62,15 +62,11 @@ bool XbelReader::read(QIODevice *device) { setDevice(device); - while (!atEnd()) { - readNext(); - - if (isStartElement()) { - if (name() == "xbel" && attributes().value("version") == "1.0") - readXBEL(); - else - raiseError(QObject::tr("The file is not an XBEL version 1.0 file.")); - } + if (readNextStartElement()) { + if (name() == "xbel" && attributes().value("version") == "1.0") + readXBEL(); + else + raiseError(QObject::tr("The file is not an XBEL version 1.0 file.")); } return !error(); @@ -80,15 +76,7 @@ bool XbelReader::read(QIODevice *device) //! [2] void XbelReader::readUnknownElement() { - Q_ASSERT(isStartElement()); - - while (!atEnd()) { - readNext(); - - if (isEndElement()) - break; - - if (isStartElement()) + while (readNextStartElement()) { readUnknownElement(); } } @@ -99,22 +87,15 @@ void XbelReader::readXBEL() { Q_ASSERT(isStartElement() && name() == "xbel"); - while (!atEnd()) { - readNext(); - - if (isEndElement()) - break; - - if (isStartElement()) { - if (name() == "folder") - readFolder(0); - else if (name() == "bookmark") - readBookmark(0); - else if (name() == "separator") - readSeparator(0); - else - readUnknownElement(); - } + while (readNextStartElement()) { + if (name() == "folder") + readFolder(0); + else if (name() == "bookmark") + readBookmark(0); + else if (name() == "separator") + readSeparator(0); + else + readUnknownElement(); } } //! [3] @@ -132,10 +113,12 @@ void XbelReader::readTitle(QTreeWidgetItem *item) //! [5] void XbelReader::readSeparator(QTreeWidgetItem *item) { + Q_ASSERT(isStartElement() && name() == "separator"); + QTreeWidgetItem *separator = createChildItem(item); separator->setFlags(item->flags() & ~Qt::ItemIsSelectable); separator->setText(0, QString(30, 0xB7)); - readElementText(); + skipCurrentElement(); } //! [5] @@ -147,24 +130,17 @@ void XbelReader::readFolder(QTreeWidgetItem *item) bool folded = (attributes().value("folded") != "no"); treeWidget->setItemExpanded(folder, !folded); - while (!atEnd()) { - readNext(); - - if (isEndElement()) - break; - - if (isStartElement()) { - if (name() == "title") - readTitle(folder); - else if (name() == "folder") - readFolder(folder); - else if (name() == "bookmark") - readBookmark(folder); - else if (name() == "separator") - readSeparator(folder); - else - readUnknownElement(); - } + while (readNextStartElement()) { + if (name() == "title") + readTitle(folder); + else if (name() == "folder") + readFolder(folder); + else if (name() == "bookmark") + readBookmark(folder); + else if (name() == "separator") + readSeparator(folder); + else + skipCurrentElement(); } } @@ -177,18 +153,12 @@ void XbelReader::readBookmark(QTreeWidgetItem *item) bookmark->setIcon(0, bookmarkIcon); bookmark->setText(0, QObject::tr("Unknown title")); bookmark->setText(1, attributes().value("href").toString()); - while (!atEnd()) { - readNext(); - - if (isEndElement()) - break; - - if (isStartElement()) { - if (name() == "title") - readTitle(bookmark); - else - readUnknownElement(); - } + + while (readNextStartElement()) { + if (name() == "title") + readTitle(bookmark); + else + skipCurrentElement(); } } |