summaryrefslogtreecommitdiffstats
path: root/examples/xml/streambookmarks
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-08-19 07:10:24 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-08-19 07:10:24 (GMT)
commit5fb5c01bd0ac234eaca890d97053c7b0772861a3 (patch)
tree2cfb189131d9f9c296b04101af45088c67bfa4c6 /examples/xml/streambookmarks
parent0325e1af2b53f62db6da27ae43ea62837e36c5ae (diff)
parentaf98f27a847688e53ab1d34b4a9c04bdc63fe3e1 (diff)
downloadQt-5fb5c01bd0ac234eaca890d97053c7b0772861a3.zip
Qt-5fb5c01bd0ac234eaca890d97053c7b0772861a3.tar.gz
Qt-5fb5c01bd0ac234eaca890d97053c7b0772861a3.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'examples/xml/streambookmarks')
-rw-r--r--examples/xml/streambookmarks/xbelreader.cpp100
1 files changed, 35 insertions, 65 deletions
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();
}
}