diff options
author | Shane Kearns <shane.kearns@sosco.com> | 2009-08-20 17:36:13 (GMT) |
---|---|---|
committer | Shane Kearns <shane.kearns@sosco.com> | 2009-08-20 17:36:13 (GMT) |
commit | 4ba5a86f530e93c179c9049d36b2f38595a5ef09 (patch) | |
tree | 6ce937f760164e2fc8822ba04625af103a49dec0 /examples | |
parent | fdda7f1dd01215e36116aa4e3428aae9f23dd711 (diff) | |
parent | ef1335b1ab76fb3ee1082b5abab66b43fa45df1d (diff) | |
download | Qt-4ba5a86f530e93c179c9049d36b2f38595a5ef09.zip Qt-4ba5a86f530e93c179c9049d36b2f38595a5ef09.tar.gz Qt-4ba5a86f530e93c179c9049d36b2f38595a5ef09.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt-s60-public
Diffstat (limited to 'examples')
-rw-r--r-- | examples/opengl/framebufferobject/bubbles.svg | 13 | ||||
-rw-r--r-- | examples/opengl/hellogl/glwidget.cpp | 52 | ||||
-rw-r--r-- | examples/opengl/pbuffers2/bubbles.svg | 13 | ||||
-rw-r--r-- | examples/opengl/samplebuffers/glwidget.cpp | 29 | ||||
-rw-r--r-- | examples/painting/svgviewer/files/bubbles.svg | 36 | ||||
-rw-r--r-- | examples/qws/dbscreen/dbscreen.cpp | 21 | ||||
-rw-r--r-- | examples/qws/dbscreen/dbscreendriverplugin.cpp | 23 | ||||
-rw-r--r-- | examples/xml/streambookmarks/mainwindow.cpp | 4 | ||||
-rw-r--r-- | examples/xml/streambookmarks/xbelreader.cpp | 67 | ||||
-rw-r--r-- | examples/xml/streambookmarks/xbelreader.h | 6 | ||||
-rw-r--r-- | examples/xml/streambookmarks/xbelwriter.cpp | 32 | ||||
-rw-r--r-- | examples/xml/streambookmarks/xbelwriter.h | 3 |
12 files changed, 179 insertions, 120 deletions
diff --git a/examples/opengl/framebufferobject/bubbles.svg b/examples/opengl/framebufferobject/bubbles.svg index 3d7971d..65867da 100644 --- a/examples/opengl/framebufferobject/bubbles.svg +++ b/examples/opengl/framebufferobject/bubbles.svg @@ -78,6 +78,10 @@ <!-- Define a shadow for each sphere. --> <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" /> <g id="bubble"> + <circle fill="black" cx="0" cy="0" r="50" /> + <circle fill="#a6ce39" cx="0" cy="0" r="33" /> + <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10 + L -11,22 L -1,12 Z" /> <circle cx="0" cy="0" r="100" /> </g> </defs> @@ -176,6 +180,15 @@ </g> </g> <g transform="translate(200,0)" > + <g transform="translate(200,490) scale(2.0,1.0) rotate(45)" > + <rect fill="#a6ce39" x="-69" y="-69" width="138" height="138" /> + <circle fill="black" cx="0" cy="0" r="50" /> + <circle fill="#a6ce39" cx="0" cy="0" r="33" /> + <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10 + L -11,22 L -1,12 Z" /> + <animateTransform attributeName="transform" type="rotate" values="0; 360" + begin="0s" dur="10s" fill="freeze" repeatCount="indefinite" /> + </g> <g transform="translate(200,375)"> <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" /> diff --git a/examples/opengl/hellogl/glwidget.cpp b/examples/opengl/hellogl/glwidget.cpp index 86d5d8c..877e1ca 100644 --- a/examples/opengl/hellogl/glwidget.cpp +++ b/examples/opengl/hellogl/glwidget.cpp @@ -183,30 +183,46 @@ GLuint GLWidget::makeObject() glBegin(GL_QUADS); + GLdouble x1 = +0.06; + GLdouble y1 = -0.14; + GLdouble x2 = +0.14; + GLdouble y2 = -0.06; + GLdouble x3 = +0.08; + GLdouble y3 = +0.00; + GLdouble x4 = +0.30; + GLdouble y4 = +0.22; + + quad(x1, y1, x2, y2, y2, x2, y1, x1); + quad(x3, y3, x4, y4, y4, x4, y3, x3); + + extrude(x1, y1, x2, y2); + extrude(x2, y2, y2, x2); + extrude(y2, x2, y1, x1); + extrude(y1, x1, x1, y1); + extrude(x3, y3, x4, y4); + extrude(x4, y4, y4, x4); + extrude(y4, x4, y3, x3); + const double Pi = 3.14159265358979323846; const int NumSectors = 200; - for (int j = 0; j < 2; ++j) { - double r = 0.1 + (j * 0.2); - - for (int i = 0; i < NumSectors; ++i) { - double angle1 = (i * 2 * Pi) / NumSectors; - GLdouble x5 = (r + 0.1) * sin(angle1); - GLdouble y5 = (r + 0.1) * cos(angle1); - GLdouble x6 = r * sin(angle1); - GLdouble y6 = r * cos(angle1); + for (int i = 0; i < NumSectors; ++i) { + double angle1 = (i * 2 * Pi) / NumSectors; + GLdouble x5 = 0.30 * sin(angle1); + GLdouble y5 = 0.30 * cos(angle1); + GLdouble x6 = 0.20 * sin(angle1); + GLdouble y6 = 0.20 * cos(angle1); - double angle2 = ((i + 1) * 2 * Pi) / NumSectors; - GLdouble x7 = r * sin(angle2); - GLdouble y7 = r * cos(angle2); - GLdouble x8 = (r + 0.1) * sin(angle2); - GLdouble y8 = (r + 0.1) * cos(angle2); + double angle2 = ((i + 1) * 2 * Pi) / NumSectors; + GLdouble x7 = 0.20 * sin(angle2); + GLdouble y7 = 0.20 * cos(angle2); + GLdouble x8 = 0.30 * sin(angle2); + GLdouble y8 = 0.30 * cos(angle2); - quad(x5, y5, x6, y6, x7, y7, x8, y8); + quad(x5, y5, x6, y6, x7, y7, x8, y8); - extrude(x6, y6, x7, y7); - extrude(x8, y8, x5, y5); - } + extrude(x6, y6, x7, y7); + extrude(x8, y8, x5, y5); } glEnd(); diff --git a/examples/opengl/pbuffers2/bubbles.svg b/examples/opengl/pbuffers2/bubbles.svg index 3d7971d..65867da 100644 --- a/examples/opengl/pbuffers2/bubbles.svg +++ b/examples/opengl/pbuffers2/bubbles.svg @@ -78,6 +78,10 @@ <!-- Define a shadow for each sphere. --> <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" /> <g id="bubble"> + <circle fill="black" cx="0" cy="0" r="50" /> + <circle fill="#a6ce39" cx="0" cy="0" r="33" /> + <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10 + L -11,22 L -1,12 Z" /> <circle cx="0" cy="0" r="100" /> </g> </defs> @@ -176,6 +180,15 @@ </g> </g> <g transform="translate(200,0)" > + <g transform="translate(200,490) scale(2.0,1.0) rotate(45)" > + <rect fill="#a6ce39" x="-69" y="-69" width="138" height="138" /> + <circle fill="black" cx="0" cy="0" r="50" /> + <circle fill="#a6ce39" cx="0" cy="0" r="33" /> + <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10 + L -11,22 L -1,12 Z" /> + <animateTransform attributeName="transform" type="rotate" values="0; 360" + begin="0s" dur="10s" fill="freeze" repeatCount="indefinite" /> + </g> <g transform="translate(200,375)"> <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" /> diff --git a/examples/opengl/samplebuffers/glwidget.cpp b/examples/opengl/samplebuffers/glwidget.cpp index 95651b3..9a41f51 100644 --- a/examples/opengl/samplebuffers/glwidget.cpp +++ b/examples/opengl/samplebuffers/glwidget.cpp @@ -109,28 +109,37 @@ void GLWidget::makeObject() QColor qtGreen(QColor::fromCmykF(0.40, 0.0, 1.0, 0.0)); const double Pi = 3.14159265358979323846; const int NumSectors = 15; + GLdouble x1 = +0.06; + GLdouble y1 = -0.14; + GLdouble x2 = +0.14; + GLdouble y2 = -0.06; + GLdouble x3 = +0.08; + GLdouble y3 = +0.00; + GLdouble x4 = +0.30; + GLdouble y4 = +0.22; list = glGenLists(1); glNewList(list, GL_COMPILE); { for (int i = 0; i < NumSectors; ++i) { double angle1 = (i * 2 * Pi) / NumSectors; - GLdouble x1 = 0.30 * sin(angle1); - GLdouble y1 = 0.30 * cos(angle1); - GLdouble x2 = 0.20 * sin(angle1); - GLdouble y2 = 0.20 * cos(angle1); + GLdouble x5 = 0.30 * sin(angle1); + GLdouble y5 = 0.30 * cos(angle1); + GLdouble x6 = 0.20 * sin(angle1); + GLdouble y6 = 0.20 * cos(angle1); double angle2 = ((i + 1) * 2 * Pi) / NumSectors; - GLdouble x3 = 0.20 * sin(angle2); - GLdouble y3 = 0.20 * cos(angle2); - GLdouble x4 = 0.30 * sin(angle2); - GLdouble y4 = 0.30 * cos(angle2); + GLdouble x7 = 0.20 * sin(angle2); + GLdouble y7 = 0.20 * cos(angle2); + GLdouble x8 = 0.30 * sin(angle2); + GLdouble y8 = 0.30 * cos(angle2); qglColor(qtGreen); - quad(GL_QUADS, x1, y1, x2, y2, x3, y3, x4, y4); + quad(GL_QUADS, x5, y5, x6, y6, x7, y7, x8, y8); qglColor(Qt::black); - quad(GL_LINE_LOOP, x1, y1, x2, y2, x3, y3, x4, y4); + quad(GL_LINE_LOOP, x5, y5, x6, y6, x7, y7, x8, y8); } + qglColor(qtGreen); quad(GL_QUADS, x1, y1, x2, y2, y2, x2, y1, x1); quad(GL_QUADS, x3, y3, x4, y4, y4, x4, y3, x3); diff --git a/examples/painting/svgviewer/files/bubbles.svg b/examples/painting/svgviewer/files/bubbles.svg index 3d7971d..b20666e 100644 --- a/examples/painting/svgviewer/files/bubbles.svg +++ b/examples/painting/svgviewer/files/bubbles.svg @@ -87,56 +87,56 @@ <g transform="translate(200,700)"> <use xlink:href="#bubble" fill="url(#blueBubble)" /> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="1s" dur="10s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(315,700)"> <g transform="scale(0.5,0.5)"> <use xlink:href="#bubble" fill="url(#redBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="3s" dur="7s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(80,700)"> <g transform="scale(0.65,0.65)"> <use xlink:href="#bubble" fill="url(#greenBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="5s" dur="9s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(255,700)"> <g transform="scale(0.3,0.3)"> <use xlink:href="#bubble" fill="url(#yellowBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="2s" dur="6s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(565,700)"> <g transform="scale(0.4,0.4)"> <use xlink:href="#bubble" fill="url(#blueBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="4s" dur="8s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(715,700)"> <g transform="scale(0.6,0.6)"> <use xlink:href="#bubble" fill="url(#redBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="1s" dur="4s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(645,700)"> <g transform="scale(0.375,0.375)"> <use xlink:href="#bubble" fill="url(#greenBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="0s" dur="11s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(555,700)"> <g transform="scale(0.9,0.9)"> <use xlink:href="#bubble" fill="url(#yellowBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="3s" dur="7.5s" fill="freeze" repeatCount="indefinite" /> </g> @@ -144,28 +144,28 @@ <g transform="scale(0.5,0.5)"> <use xlink:href="#bubble" fill="url(#blueBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="3s" dur="6s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(215,700)"> <g transform="scale(0.45,0.45)"> <use xlink:href="#bubble" fill="url(#redBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="5.5s" dur="7s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(420,700)"> <g transform="scale(0.75,0.75)"> <use xlink:href="#bubble" fill="url(#greenBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="1s" dur="9s" fill="freeze" repeatCount="indefinite" /> </g> <g transform="translate(815,700)"> <g transform="scale(0.6,0.6)"> <use xlink:href="#bubble" fill="url(#yellowBubble)" /> </g> - <animateTransform attributeName="transform" type="translate" + <animateTransform attributeName="transform" type="translate" additive="sum" values="0,0; 0,-800" begin="2s" dur="9.5s" fill="freeze" repeatCount="indefinite" /> </g> @@ -176,6 +176,18 @@ </g> </g> <g transform="translate(200,0)" > +<<<<<<< HEAD:examples/painting/svgviewer/files/bubbles.svg +======= + <g transform="translate(200,490) scale(2.0,1.0) rotate(45)" > + <rect fill="#a6ce39" x="-69" y="-69" width="138" height="138" /> + <circle fill="black" cx="0" cy="0" r="50" /> + <circle fill="#a6ce39" cx="0" cy="0" r="33" /> + <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10 + L -11,22 L -1,12 Z" /> + <animateTransform attributeName="transform" type="rotate" additive="sum" values="0; 360" + begin="0s" dur="10s" fill="freeze" repeatCount="indefinite" /> + </g> +>>>>>>> qt/master:examples/painting/svgviewer/files/bubbles.svg <g transform="translate(200,375)"> <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" /> <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" /> diff --git a/examples/qws/dbscreen/dbscreen.cpp b/examples/qws/dbscreen/dbscreen.cpp index 86c34cd..fb6897c 100644 --- a/examples/qws/dbscreen/dbscreen.cpp +++ b/examples/qws/dbscreen/dbscreen.cpp @@ -1,11 +1,11 @@ - /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Nokia Corporation (qt-info@nokia.com) - ** - ** This file is part of the examples of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions @@ -36,11 +36,8 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ +** +****************************************************************************/ #include "dbscreen.h" #include <QApplication> diff --git a/examples/qws/dbscreen/dbscreendriverplugin.cpp b/examples/qws/dbscreen/dbscreendriverplugin.cpp index 6f11198..9190753 100644 --- a/examples/qws/dbscreen/dbscreendriverplugin.cpp +++ b/examples/qws/dbscreen/dbscreendriverplugin.cpp @@ -1,11 +1,11 @@ - /**************************************************************************** - ** - ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Nokia Corporation (qt-info@nokia.com) - ** - ** This file is part of the examples of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions @@ -36,12 +36,9 @@ ** If you are unsure which license is appropriate for your use, please ** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ****************************************************************************/ - +** +****************************************************************************/ + #include <QScreenDriverPlugin> #include "dbscreen.h" diff --git a/examples/xml/streambookmarks/mainwindow.cpp b/examples/xml/streambookmarks/mainwindow.cpp index 183143d..5aef327 100644 --- a/examples/xml/streambookmarks/mainwindow.cpp +++ b/examples/xml/streambookmarks/mainwindow.cpp @@ -91,10 +91,8 @@ void MainWindow::open() XbelReader reader(treeWidget); if (!reader.read(&file)) { QMessageBox::warning(this, tr("QXmlStream Bookmarks"), - tr("Parse error in file %1 at line %2, column %3:\n%4") + tr("Parse error in file %1:\n\n%2") .arg(fileName) - .arg(reader.lineNumber()) - .arg(reader.columnNumber()) .arg(reader.errorString())); } else { statusBar()->showMessage(tr("File loaded"), 2000); diff --git a/examples/xml/streambookmarks/xbelreader.cpp b/examples/xml/streambookmarks/xbelreader.cpp index 2682d91..0770643 100644 --- a/examples/xml/streambookmarks/xbelreader.cpp +++ b/examples/xml/streambookmarks/xbelreader.cpp @@ -60,42 +60,43 @@ XbelReader::XbelReader(QTreeWidget *treeWidget) //! [1] bool XbelReader::read(QIODevice *device) { - setDevice(device); + xml.setDevice(device); - if (readNextStartElement()) { - if (name() == "xbel" && attributes().value("version") == "1.0") + if (xml.readNextStartElement()) { + if (xml.name() == "xbel" && xml.attributes().value("version") == "1.0") readXBEL(); else - raiseError(QObject::tr("The file is not an XBEL version 1.0 file.")); + xml.raiseError(QObject::tr("The file is not an XBEL version 1.0 file.")); } - return !error(); + return !xml.error(); } //! [1] //! [2] -void XbelReader::readUnknownElement() +QString XbelReader::errorString() const { - while (readNextStartElement()) { - readUnknownElement(); - } + return QObject::tr("%1\nLine %2, column %3") + .arg(xml.errorString()) + .arg(xml.lineNumber()) + .arg(xml.columnNumber()); } //! [2] //! [3] void XbelReader::readXBEL() { - Q_ASSERT(isStartElement() && name() == "xbel"); + Q_ASSERT(xml.isStartElement() && xml.name() == "xbel"); - while (readNextStartElement()) { - if (name() == "folder") + while (xml.readNextStartElement()) { + if (xml.name() == "folder") readFolder(0); - else if (name() == "bookmark") + else if (xml.name() == "bookmark") readBookmark(0); - else if (name() == "separator") + else if (xml.name() == "separator") readSeparator(0); else - skipCurrentElement(); + xml.skipCurrentElement(); } } //! [3] @@ -103,9 +104,9 @@ void XbelReader::readXBEL() //! [4] void XbelReader::readTitle(QTreeWidgetItem *item) { - Q_ASSERT(isStartElement() && name() == "title"); + Q_ASSERT(xml.isStartElement() && xml.name() == "title"); - QString title = readElementText(); + QString title = xml.readElementText(); item->setText(0, title); } //! [4] @@ -113,52 +114,52 @@ void XbelReader::readTitle(QTreeWidgetItem *item) //! [5] void XbelReader::readSeparator(QTreeWidgetItem *item) { - Q_ASSERT(isStartElement() && name() == "separator"); + Q_ASSERT(xml.isStartElement() && xml.name() == "separator"); QTreeWidgetItem *separator = createChildItem(item); separator->setFlags(item->flags() & ~Qt::ItemIsSelectable); separator->setText(0, QString(30, 0xB7)); - skipCurrentElement(); + xml.skipCurrentElement(); } //! [5] void XbelReader::readFolder(QTreeWidgetItem *item) { - Q_ASSERT(isStartElement() && name() == "folder"); + Q_ASSERT(xml.isStartElement() && xml.name() == "folder"); QTreeWidgetItem *folder = createChildItem(item); - bool folded = (attributes().value("folded") != "no"); + bool folded = (xml.attributes().value("folded") != "no"); treeWidget->setItemExpanded(folder, !folded); - while (readNextStartElement()) { - if (name() == "title") + while (xml.readNextStartElement()) { + if (xml.name() == "title") readTitle(folder); - else if (name() == "folder") + else if (xml.name() == "folder") readFolder(folder); - else if (name() == "bookmark") + else if (xml.name() == "bookmark") readBookmark(folder); - else if (name() == "separator") + else if (xml.name() == "separator") readSeparator(folder); else - skipCurrentElement(); + xml.skipCurrentElement(); } } void XbelReader::readBookmark(QTreeWidgetItem *item) { - Q_ASSERT(isStartElement() && name() == "bookmark"); + Q_ASSERT(xml.isStartElement() && xml.name() == "bookmark"); QTreeWidgetItem *bookmark = createChildItem(item); bookmark->setFlags(bookmark->flags() | Qt::ItemIsEditable); bookmark->setIcon(0, bookmarkIcon); bookmark->setText(0, QObject::tr("Unknown title")); - bookmark->setText(1, attributes().value("href").toString()); + bookmark->setText(1, xml.attributes().value("href").toString()); - while (readNextStartElement()) { - if (name() == "title") + while (xml.readNextStartElement()) { + if (xml.name() == "title") readTitle(bookmark); else - skipCurrentElement(); + xml.skipCurrentElement(); } } @@ -170,6 +171,6 @@ QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item) } else { childItem = new QTreeWidgetItem(treeWidget); } - childItem->setData(0, Qt::UserRole, name().toString()); + childItem->setData(0, Qt::UserRole, xml.name().toString()); return childItem; } diff --git a/examples/xml/streambookmarks/xbelreader.h b/examples/xml/streambookmarks/xbelreader.h index 80f0a28..00d5850 100644 --- a/examples/xml/streambookmarks/xbelreader.h +++ b/examples/xml/streambookmarks/xbelreader.h @@ -51,7 +51,7 @@ class QTreeWidgetItem; QT_END_NAMESPACE //! [0] -class XbelReader : public QXmlStreamReader +class XbelReader { public: //! [1] @@ -60,9 +60,10 @@ public: bool read(QIODevice *device); + QString errorString() const; + private: //! [2] - void readUnknownElement(); void readXBEL(); void readTitle(QTreeWidgetItem *item); void readSeparator(QTreeWidgetItem *item); @@ -71,6 +72,7 @@ private: QTreeWidgetItem *createChildItem(QTreeWidgetItem *item); + QXmlStreamReader xml; QTreeWidget *treeWidget; //! [2] diff --git a/examples/xml/streambookmarks/xbelwriter.cpp b/examples/xml/streambookmarks/xbelwriter.cpp index 3a2862a..58757f5 100644 --- a/examples/xml/streambookmarks/xbelwriter.cpp +++ b/examples/xml/streambookmarks/xbelwriter.cpp @@ -47,23 +47,23 @@ XbelWriter::XbelWriter(QTreeWidget *treeWidget) : treeWidget(treeWidget) { - setAutoFormatting(true); + xml.setAutoFormatting(true); } //! [0] //! [1] bool XbelWriter::writeFile(QIODevice *device) { - setDevice(device); + xml.setDevice(device); - writeStartDocument(); - writeDTD("<!DOCTYPE xbel>"); - writeStartElement("xbel"); - writeAttribute("version", "1.0"); + xml.writeStartDocument(); + xml.writeDTD("<!DOCTYPE xbel>"); + xml.writeStartElement("xbel"); + xml.writeAttribute("version", "1.0"); for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) writeItem(treeWidget->topLevelItem(i)); - writeEndDocument(); + xml.writeEndDocument(); return true; } //! [1] @@ -74,20 +74,20 @@ void XbelWriter::writeItem(QTreeWidgetItem *item) QString tagName = item->data(0, Qt::UserRole).toString(); if (tagName == "folder") { bool folded = !treeWidget->isItemExpanded(item); - writeStartElement(tagName); - writeAttribute("folded", folded ? "yes" : "no"); - writeTextElement("title", item->text(0)); + xml.writeStartElement(tagName); + xml.writeAttribute("folded", folded ? "yes" : "no"); + xml.writeTextElement("title", item->text(0)); for (int i = 0; i < item->childCount(); ++i) writeItem(item->child(i)); - writeEndElement(); + xml.writeEndElement(); } else if (tagName == "bookmark") { - writeStartElement(tagName); + xml.writeStartElement(tagName); if (!item->text(1).isEmpty()) - writeAttribute("href", item->text(1)); - writeTextElement("title", item->text(0)); - writeEndElement(); + xml.writeAttribute("href", item->text(1)); + xml.writeTextElement("title", item->text(0)); + xml.writeEndElement(); } else if (tagName == "separator") { - writeEmptyElement(tagName); + xml.writeEmptyElement(tagName); } } //! [2] diff --git a/examples/xml/streambookmarks/xbelwriter.h b/examples/xml/streambookmarks/xbelwriter.h index 29a8b04..b74d015 100644 --- a/examples/xml/streambookmarks/xbelwriter.h +++ b/examples/xml/streambookmarks/xbelwriter.h @@ -50,7 +50,7 @@ class QTreeWidgetItem; QT_END_NAMESPACE //! [0] -class XbelWriter : public QXmlStreamWriter +class XbelWriter { public: XbelWriter(QTreeWidget *treeWidget); @@ -58,6 +58,7 @@ public: private: void writeItem(QTreeWidgetItem *item); + QXmlStreamWriter xml; QTreeWidget *treeWidget; }; //! [0] |