summaryrefslogtreecommitdiffstats
path: root/examples/xml
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2009-08-19 09:24:04 (GMT)
committeraxis <qt-info@nokia.com>2009-08-19 09:24:04 (GMT)
commit2d1b49bd21b788ba3e35fc5c41bf3aab42cbda65 (patch)
tree24dae3a4532870d61282841f6bb186cb008ab747 /examples/xml
parentb3a3652abbf1cb4ebba6c6257ecf47f8dc022d93 (diff)
parent20d2b7312456435e5e1a98dba7c2cc96b44fe83c (diff)
downloadQt-2d1b49bd21b788ba3e35fc5c41bf3aab42cbda65.zip
Qt-2d1b49bd21b788ba3e35fc5c41bf3aab42cbda65.tar.gz
Qt-2d1b49bd21b788ba3e35fc5c41bf3aab42cbda65.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Conflicts: tests/auto/auto.pro
Diffstat (limited to 'examples/xml')
-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..2682d91 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
+ skipCurrentElement();
}
}
//! [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();
}
}