1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 id: xmllistmodelelementtest
47 property string testtext: ""
48 property string modelxml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
49 "<cookbook><recipe id=\"MushroomSoup\">"+
50 "<title>Hot chocolate</title>"+
51 "<ingredient name=\"Milk\" quantity=\"1\" unit=\"cup\"/>"+
52 "<time quantity=\"2\" unit=\"minutes\"/>"+
53 "<method><step>1. Place the cup of milk in the microwave for 1 minute.</step>"+
54 "<step>2. Stir in 2 teaspoons of drinking chocolate.</step></method></recipe></cookbook>"
56 XmlListModel { id: xmllistmodelelement
57 source: "cookbook.xml"
58 query: "/cookbook/recipe"
59 XmlRole { name: "title"; query: "title/string()" }
60 XmlRole { name: "xmlid"; query: "@id/string()" }
61 XmlRole { name: "method"; query: "method/string()" }
62 XmlRole { name: "time"; query: "time/@quantity/number()" }
67 model: xmllistmodelelement; height: 300; width: 300; clip: true
68 anchors.centerIn: parent
70 Rectangle { id: delbox; height: 50; width: 296; color: "orange"; border.color: "black"; state: "closed"; clip: true; radius: 5
71 anchors.horizontalCenter: parent.horizontalCenter
74 text: model.title; font.pointSize: 12; font.bold: true
75 anchors.horizontalCenter: parent.horizontalCenter; y: 20;
80 width: parent.width; height: 20; text: "<b>Time: </b>" +model.time + " minutes"; visible: opacity != 0
81 anchors.horizontalCenter: parent.horizontalCenter; anchors.top: recipetitle.bottom
82 Behavior on opacity { NumberAnimation { duration: 250 } }
86 XmlListModel { id: subxmllistmodelelement
87 source: "cookbook.xml"
88 query: "/cookbook/recipe[@id = '"+model.xmlid+"']/ingredient"
89 XmlRole { name: "ingredientname"; query: "@name/string()" }
90 XmlRole { name: "ingredientquantity"; query: "@quantity/string()" }
91 XmlRole { name: "ingredientunit"; query: "@unit/string()" }
96 model: subxmllistmodelelement
97 height: 20 * count; width: parent.width
99 Behavior on opacity { NumberAnimation { duration: 250 } }
100 anchors.horizontalCenter: parent.horizontalCenter; anchors.top: recipetime.bottom; anchors.topMargin: 10
101 header: Text { text: "<b>Ingredients:</b>" }
103 text: ingredientquantity + " " + ingredientunit + " of " + ingredientname; height: 20;
109 property string methodtext: ""
110 width: parent.width; wrapMode: Text.WordWrap; visible: opacity != 0; text: methodtext
111 anchors.horizontalCenter: parent.horizontalCenter; anchors.top: ingredientlist.bottom
112 Behavior on opacity { NumberAnimation { duration: 250 } }
113 Component.onCompleted: { console.log(model.method); methodtext = model.method; console.log(recipemethod.textFormat); }
115 MouseArea { anchors.fill: parent; onClicked: delbox.state = delbox.state == "open" ? "closed" : "open" }
116 Behavior on height { NumberAnimation { duration: 250 } }
118 State { name: "closed"
119 PropertyChanges { target: delbox; height: 50 }
120 PropertyChanges { target: recipemethod; opacity: 0 }
121 PropertyChanges { target: recipetime; opacity: 0 }
122 PropertyChanges { target: ingredientlist; opacity: 0 }
125 PropertyChanges { target: delbox; height: recipemethod.height+recipetime.height+ingredientlist.height+50 }
126 PropertyChanges { target: recipemethod; opacity: 1 }
127 StateChangeScript { script: { recipeview.positionViewAtIndex(model.index, ListView.Beginning); } }
134 SystemTestHelp { id: helpbubble; visible: statenum != 0
135 anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; topMargin: 50 }
137 BugPanel { id: bugpanel }
140 State { name: "start"; when: statenum == 1
141 PropertyChanges { target: xmllistmodelelementtest
142 testtext: "This is a ListView populated by an XmlListModel. Clicking on an item will show the recipe details.\n"+
143 "Next we will change to source of the model data to a local string" }
145 State { name: "xmlstring"; when: statenum == 2
146 PropertyChanges { target: xmllistmodelelement; source: "" }
147 PropertyChanges { target: xmllistmodelelement; xml: modelxml }
148 PropertyChanges { target: xmllistmodelelementtest
149 testtext: "The list should now only contain a Hot chocolate recipe.\n"+
150 "Advance to restart the test." }