summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-08-19 03:39:36 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-08-19 03:39:36 (GMT)
commit2ca4d08efc444de985a9a7749e771dfcaa0e7683 (patch)
treede821643167f835cea5a4cb133d32775d4d77784 /examples
parent84b76c452833f52891593f317a64bc78c7486bbf (diff)
parente19fa69859c1abe8da0623c502d012cff214e1c4 (diff)
downloadQt-2ca4d08efc444de985a9a7749e771dfcaa0e7683.zip
Qt-2ca4d08efc444de985a9a7749e771dfcaa0e7683.tar.gz
Qt-2ca4d08efc444de985a9a7749e771dfcaa0e7683.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/border-image/example.qml31
-rw-r--r--examples/declarative/flowview/flowview.qml4
-rw-r--r--examples/declarative/layouts/Button.qml20
-rw-r--r--examples/declarative/layouts/add.pngbin0 -> 1577 bytes
-rw-r--r--examples/declarative/layouts/del.pngbin0 -> 1661 bytes
-rw-r--r--examples/declarative/layouts/layouts.qml25
-rw-r--r--examples/declarative/layouts/positioners.qml51
-rw-r--r--examples/declarative/listview/sections.qml2
-rw-r--r--examples/declarative/loader/Browser.qml4
-rw-r--r--examples/declarative/tutorials/contacts/1_Drawing_and_Animation/3/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4a/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/1_Drawing_and_Animation/5/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/2_Reuse/1/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/2_Reuse/1a/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/2_Reuse/1b/lib/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/2_Reuse/2/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/2_Reuse/3/FieldText.qml2
-rw-r--r--examples/declarative/tutorials/contacts/2_Reuse/3/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/2_Reuse/4/FieldText.qml2
-rw-r--r--examples/declarative/tutorials/contacts/2_Reuse/4/RemoveButton.qml2
-rw-r--r--examples/declarative/tutorials/contacts/3_Collections/lib/FieldText.qml2
-rw-r--r--examples/declarative/tutorials/contacts/3_Collections/lib/RemoveButton.qml2
-rw-r--r--examples/network/googlesuggest/googlesuggest.cpp7
-rw-r--r--examples/xml/streambookmarks/xbelreader.cpp100
25 files changed, 184 insertions, 88 deletions
diff --git a/examples/declarative/border-image/example.qml b/examples/declarative/border-image/example.qml
new file mode 100644
index 0000000..10daf47
--- /dev/null
+++ b/examples/declarative/border-image/example.qml
@@ -0,0 +1,31 @@
+import Qt 4.6
+
+Rect {
+ id: Page
+ color: "white"
+ width: 520; height: 280
+
+ HorizontalPositioner {
+ anchors.centerIn: parent
+ spacing: 50
+//! [0]
+ BorderImage {
+ width: 180; height: 180
+ border.left: 30; border.top: 30
+ border.right: 30; border.bottom: 30
+ horizontalTileMode: "Stretch"
+ verticalTileMode: "Stretch"
+ source: "colors.png"
+ }
+
+ BorderImage {
+ width: 180; height: 180
+ border.left: 30; border.top: 30
+ border.right: 30; border.bottom: 30
+ horizontalTileMode: "Round"
+ verticalTileMode: "Round"
+ source: "colors.png"
+ }
+//! [0]
+ }
+}
diff --git a/examples/declarative/flowview/flowview.qml b/examples/declarative/flowview/flowview.qml
index a3d0ac5..8d1bdf6 100644
--- a/examples/declarative/flowview/flowview.qml
+++ b/examples/declarative/flowview/flowview.qml
@@ -25,8 +25,8 @@ Rect {
fromState: "" ; toState: "rotated"
reversible: true
SequentialAnimation {
- NumberAnimation { filter: [TopBar, BottomBar]; properties: "x,y"; easing: "easeInOutQuad" }
- NumberAnimation { filter: [LeftBar, RightBar]; properties: "x,y"; easing: "easeInOutQuad"}
+ NumberAnimation { targets: [TopBar, BottomBar]; properties: "x,y"; easing: "easeInOutQuad" }
+ NumberAnimation { targets: [LeftBar, RightBar]; properties: "x,y"; easing: "easeInOutQuad"}
}
}
diff --git a/examples/declarative/layouts/Button.qml b/examples/declarative/layouts/Button.qml
new file mode 100644
index 0000000..de11dc9
--- /dev/null
+++ b/examples/declarative/layouts/Button.qml
@@ -0,0 +1,20 @@
+import Qt 4.6
+Rect { border.color: "black"; color: "steelblue"; radius: 5; width: pix.width + text.width + 13; height: pix.height + 10; id: page
+ property string text
+ property string icon
+ signal clicked
+ Image { id: pix; x: 5; y:5; source: parent.icon}
+ Text { id: text; text: page.text; color: "white"; x:pix.width+pix.x+3; anchors.verticalCenter: pix.verticalCenter;}
+ MouseRegion{ id:mr; anchors.fill: parent; onClicked: {parent.focus = true; page.clicked()}}
+
+ states:
+ State{ name:"pressed"; when:mr.pressed
+ SetProperties {target:text; x: 5}
+ SetProperties {target:pix; x:text.x+text.width + 3}
+ }
+
+ transitions:
+ Transition{
+ NumberAnimation{ properties:"x,left"; easing:"easeInOutQuad"; duration:200 }
+ }
+}
diff --git a/examples/declarative/layouts/add.png b/examples/declarative/layouts/add.png
new file mode 100644
index 0000000..f29d84b
--- /dev/null
+++ b/examples/declarative/layouts/add.png
Binary files differ
diff --git a/examples/declarative/layouts/del.png b/examples/declarative/layouts/del.png
new file mode 100644
index 0000000..1d753a3
--- /dev/null
+++ b/examples/declarative/layouts/del.png
Binary files differ
diff --git a/examples/declarative/layouts/layouts.qml b/examples/declarative/layouts/layouts.qml
new file mode 100644
index 0000000..1f6b956
--- /dev/null
+++ b/examples/declarative/layouts/layouts.qml
@@ -0,0 +1,25 @@
+import Qt 4.6
+
+Item { id: resizable
+ width:400; height:400;
+ GraphicsObjectContainer{
+ anchors.fill:parent
+ QGraphicsWidget{
+ geometry:{ "0,0," + parent.width.toString() + "x" + parent.height.toString(); }
+ layout: QGraphicsLinearLayout{
+ LayoutItem{
+ minimumSize: "100x100"
+ maximumSize: "300x300"
+ preferredSize: "100x100"
+ Rect { color: "yellow"; anchors.fill: parent }
+ }
+ LayoutItem{
+ minimumSize: "100x100"
+ maximumSize: "400x400"
+ preferredSize: "200x200"
+ Rect { color: "green"; anchors.fill: parent }
+ }
+ }
+ }
+ }
+}
diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml
new file mode 100644
index 0000000..44f9509
--- /dev/null
+++ b/examples/declarative/layouts/positioners.qml
@@ -0,0 +1,51 @@
+import Qt 4.6
+Rect { width: 420; height: 420; id:page; color:"white"
+ VerticalPositioner { id: layout1; y:0; //width: 100; height:250;
+ move: Transition{ NumberAnimation {properties: "y"; easing: "easeOutBounce" }}
+ add: Transition{ NumberAnimation { properties: "y"; from: 500; duration:500; easing: "easeOutQuad"}}
+ remove: Transition { NumberAnimation { properties:"y"; to: 500; duration:500; easing: "easeInQuad"}}
+ Rect { color: "red"; width: 100; height: 50; border.color: "black"; radius: 15 }
+ Rect { id: blueV1; color: "lightsteelblue"; width: 100; height: 50; border.color: "black"; radius: 15
+ //opacity: Behavior{ NumberAnimation {}}
+ }
+ Rect { color: "green"; width: 100; height: 50; border.color: "black"; radius: 15 }
+ Rect { id: blueV2; color: "lightsteelblue"; width: 100; height: 50; border.color: "black"; radius: 15
+ //opacity: Behavior{ NumberAnimation {}}
+ }
+ Rect { color: "orange"; width: 100; height: 50; border.color: "black"; radius: 15 }
+ }
+ HorizontalPositioner { id: layout2; y:300;
+ move: Transition{ NumberAnimation {properties: "x"; easing: "easeOutBounce" }}
+ add: Transition{ NumberAnimation { properties: "x"; from: 500; duration:500; easing: "easeOutQuad"}
+ NumberAnimation { properties: "opacity"; from: 0; duration: 500;}}
+ remove: Transition { NumberAnimation { properties: "x"; to: 500; duration:500; easing: "easeInQuad"}
+ NumberAnimation { properties: "opacity"; from: 1; duration: 500}}
+ Rect { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { id: blueH1; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { color: "green"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { id: blueH2; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { color: "orange"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ }
+ Button { text: "Remove"; icon: "del.png"; x: 135; y:90;
+ onClicked: {blueH2.opacity=0; blueH1.opacity=0; blueV1.opacity=0; blueV2.opacity=0; blueG1.opacity=0; blueG2.opacity=0; blueG3.opacity=0;}
+ }
+ Button { text: "Add"; icon: "add.png"; x: 145; y:140;
+ onClicked: {blueH2.opacity=1; blueH1.opacity=1; blueV1.opacity=1; blueV2.opacity=1; blueG1.opacity=1; blueG2.opacity=1; blueG3.opacity=1;}
+ }
+ GridPositioner { x:260; y:0; columns:3
+ remove: Transition { NumberAnimation{ properties: "opacity"; from: 1; to: 0; duration: 500}
+ NumberAnimation{properties: "x,y"; easing: "easeOutBounce"} }
+ move: Transition { NumberAnimation{ properties: "x,y"; easing: "easeOutBounce" }}
+ add: Transition { NumberAnimation{ properties: "opacity"; from: 0; to: 1; duration: 500}
+ NumberAnimation{properties: "x,y"; easing: "easeOutBounce"} }
+ Rect { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { id: blueG1; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { color: "green"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { id: blueG2; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { color: "orange"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { id: blueG3; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { color: "green"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rect { color: "orange"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ }
+}
diff --git a/examples/declarative/listview/sections.qml b/examples/declarative/listview/sections.qml
index ab9fbdf..41cc2e6 100644
--- a/examples/declarative/listview/sections.qml
+++ b/examples/declarative/listview/sections.qml
@@ -28,7 +28,7 @@ Rect {
opacity: Wrapper.ListView.prevSection != Wrapper.ListView.section ? 1 : 0
Text {
text: Wrapper.ListView.section; font.bold: true
- x: 2; height: parent.height; vAlign: 'AlignVCenter'
+ x: 2; height: parent.height; verticalAlignment: 'AlignVCenter'
}
}
Item {
diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml
index d5887d7..78b26dc 100644
--- a/examples/declarative/loader/Browser.qml
+++ b/examples/declarative/loader/Browser.qml
@@ -41,7 +41,7 @@ Rect {
}
Text {
id: NameText
- anchors.fill: parent; vAlign: "AlignVCenter"
+ anchors.fill: parent; verticalAlignment: "AlignVCenter"
text: fileName; anchors.leftMargin: 32
font.pointSize: 10
color: activePalette.windowText
@@ -107,7 +107,7 @@ Rect {
anchors.left: UpButton.right; anchors.right: parent.right; height: parent.height
anchors.leftMargin: 4; anchors.rightMargin: 4
text: folders.folder; color: activePalette.buttonText
- elide: "ElideLeft"; hAlign: "AlignRight"; vAlign: "AlignVCenter"
+ elide: "ElideLeft"; horizontalAlignment: "AlignRight"; verticalAlignment: "AlignVCenter"
}
}
}
diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/3/RemoveButton.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/3/RemoveButton.qml
index 6426457..f1b72ab 100644
--- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/3/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/3/RemoveButton.qml
@@ -34,7 +34,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
}
}
diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4/RemoveButton.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4/RemoveButton.qml
index c97426c..dfb79a6 100644
--- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4/RemoveButton.qml
@@ -73,7 +73,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4a/RemoveButton.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4a/RemoveButton.qml
index 712471f..d4f30eb 100644
--- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4a/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4a/RemoveButton.qml
@@ -80,7 +80,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/5/RemoveButton.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/5/RemoveButton.qml
index acc9896..292eb45 100644
--- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/5/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/5/RemoveButton.qml
@@ -69,7 +69,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/1/RemoveButton.qml
index 5392154..f74ff99 100644
--- a/examples/declarative/tutorials/contacts/2_Reuse/1/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/2_Reuse/1/RemoveButton.qml
@@ -69,7 +69,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1a/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/1a/RemoveButton.qml
index 5392154..f74ff99 100644
--- a/examples/declarative/tutorials/contacts/2_Reuse/1a/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/2_Reuse/1a/RemoveButton.qml
@@ -69,7 +69,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1b/lib/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/1b/lib/RemoveButton.qml
index e47aff2..d21b297 100644
--- a/examples/declarative/tutorials/contacts/2_Reuse/1b/lib/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/2_Reuse/1b/lib/RemoveButton.qml
@@ -71,7 +71,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
diff --git a/examples/declarative/tutorials/contacts/2_Reuse/2/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/2/RemoveButton.qml
index 32e8ce0..9a7e0d7 100644
--- a/examples/declarative/tutorials/contacts/2_Reuse/2/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/2_Reuse/2/RemoveButton.qml
@@ -75,7 +75,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
diff --git a/examples/declarative/tutorials/contacts/2_Reuse/3/FieldText.qml b/examples/declarative/tutorials/contacts/2_Reuse/3/FieldText.qml
index e0651c8..3130bbe 100644
--- a/examples/declarative/tutorials/contacts/2_Reuse/3/FieldText.qml
+++ b/examples/declarative/tutorials/contacts/2_Reuse/3/FieldText.qml
@@ -67,7 +67,7 @@ Rect {
x: 5
width: parent.width-10
anchors.verticalCenter: parent.verticalCenter
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
color: "#505050"
font.italic: true
text: fieldText.label
diff --git a/examples/declarative/tutorials/contacts/2_Reuse/3/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/3/RemoveButton.qml
index 6280877..b99ab84 100644
--- a/examples/declarative/tutorials/contacts/2_Reuse/3/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/2_Reuse/3/RemoveButton.qml
@@ -72,7 +72,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
diff --git a/examples/declarative/tutorials/contacts/2_Reuse/4/FieldText.qml b/examples/declarative/tutorials/contacts/2_Reuse/4/FieldText.qml
index 21e3bf2..369d34d 100644
--- a/examples/declarative/tutorials/contacts/2_Reuse/4/FieldText.qml
+++ b/examples/declarative/tutorials/contacts/2_Reuse/4/FieldText.qml
@@ -69,7 +69,7 @@ Rect {
x: 5
width: parent.width-10
anchors.verticalCenter: parent.verticalCenter
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
color: "#505050"
font.italic: true
text: fieldText.label
diff --git a/examples/declarative/tutorials/contacts/2_Reuse/4/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/4/RemoveButton.qml
index 03b50eec..f4a55e1 100644
--- a/examples/declarative/tutorials/contacts/2_Reuse/4/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/2_Reuse/4/RemoveButton.qml
@@ -77,7 +77,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
diff --git a/examples/declarative/tutorials/contacts/3_Collections/lib/FieldText.qml b/examples/declarative/tutorials/contacts/3_Collections/lib/FieldText.qml
index 4506ec9..93ac0f8 100644
--- a/examples/declarative/tutorials/contacts/3_Collections/lib/FieldText.qml
+++ b/examples/declarative/tutorials/contacts/3_Collections/lib/FieldText.qml
@@ -69,7 +69,7 @@ Rect {
x: 5
width: parent.width-10
anchors.verticalCenter: parent.verticalCenter
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
color: "#505050"
font.italic: true
text: fieldText.label
diff --git a/examples/declarative/tutorials/contacts/3_Collections/lib/RemoveButton.qml b/examples/declarative/tutorials/contacts/3_Collections/lib/RemoveButton.qml
index 866a23f..d96a932 100644
--- a/examples/declarative/tutorials/contacts/3_Collections/lib/RemoveButton.qml
+++ b/examples/declarative/tutorials/contacts/3_Collections/lib/RemoveButton.qml
@@ -75,7 +75,7 @@ Rect {
anchors.rightMargin: 4
font.bold: true
color: "white"
- hAlign: "AlignHCenter"
+ horizontalAlignment: "AlignHCenter"
text: "Remove"
opacity: 0
}
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();
}
}