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 ****************************************************************************/
43 import QtQuick.XmlListModel 2.0
46 id: xmllistmodelelementtest
48 property string testtext: ""
49 property string modelxml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
50 "<cookbook><recipe id=\"MushroomSoup\">"+
51 "<title>Hot chocolate</title>"+
52 "<ingredient name=\"Milk\" quantity=\"1\" unit=\"cup\"/>"+
53 "<time quantity=\"2\" unit=\"minutes\"/>"+
54 "<method><step>1. Place the cup of milk in the microwave for 1 minute.</step>"+
55 "<step>2. Stir in 2 teaspoons of drinking chocolate.</step></method></recipe></cookbook>"
57 XmlListModel { id: xmllistmodelelement
58 source: "cookbook.xml"
59 query: "/cookbook/recipe"
60 XmlRole { name: "title"; query: "title/string()" }
61 XmlRole { name: "xmlid"; query: "@id/string()" }
62 XmlRole { name: "method"; query: "method/string()" }
63 XmlRole { name: "time"; query: "time/@quantity/number()" }
68 model: xmllistmodelelement; height: 300; width: 300; clip: true
69 anchors.centerIn: parent
71 Rectangle { id: delbox; height: 50; width: 296; color: "orange"; border.color: "black"; state: "closed"; clip: true; radius: 5
72 anchors.horizontalCenter: parent.horizontalCenter
75 text: model.title; font.pointSize: 12; font.bold: true
76 anchors.horizontalCenter: parent.horizontalCenter; y: 20;
81 width: parent.width; height: 20; text: "<b>Time: </b>" +model.time + " minutes"; visible: opacity != 0
82 anchors.horizontalCenter: parent.horizontalCenter; anchors.top: recipetitle.bottom
83 Behavior on opacity { NumberAnimation { duration: 250 } }
87 XmlListModel { id: subxmllistmodelelement
88 source: "cookbook.xml"
89 query: "/cookbook/recipe[@id = '"+model.xmlid+"']/ingredient"
90 XmlRole { name: "ingredientname"; query: "@name/string()" }
91 XmlRole { name: "ingredientquantity"; query: "@quantity/string()" }
92 XmlRole { name: "ingredientunit"; query: "@unit/string()" }
97 model: subxmllistmodelelement
98 height: 20 * count; width: parent.width
100 Behavior on opacity { NumberAnimation { duration: 250 } }
101 anchors.horizontalCenter: parent.horizontalCenter; anchors.top: recipetime.bottom; anchors.topMargin: 10
102 header: Text { text: "<b>Ingredients:</b>" }
104 text: ingredientquantity + " " + ingredientunit + " of " + ingredientname; height: 20;
110 property string methodtext: ""
111 width: parent.width; wrapMode: Text.WordWrap; visible: opacity != 0; text: methodtext
112 anchors.horizontalCenter: parent.horizontalCenter; anchors.top: ingredientlist.bottom
113 Behavior on opacity { NumberAnimation { duration: 250 } }
114 Component.onCompleted: { methodtext = model.method; }
116 MouseArea { anchors.fill: parent; onClicked: delbox.state = delbox.state == "open" ? "closed" : "open" }
117 Behavior on height { NumberAnimation { duration: 250 } }
119 State { name: "closed"
120 PropertyChanges { target: delbox; height: 50 }
121 PropertyChanges { target: recipemethod; opacity: 0 }
122 PropertyChanges { target: recipetime; opacity: 0 }
123 PropertyChanges { target: ingredientlist; opacity: 0 }
126 PropertyChanges { target: delbox; height: recipemethod.height+recipetime.height+ingredientlist.height+50 }
127 PropertyChanges { target: recipemethod; opacity: 1 }
128 StateChangeScript { script: { recipeview.positionViewAtIndex(model.index, ListView.Beginning); } }
135 SystemTestHelp { id: helpbubble; visible: statenum != 0
136 anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; topMargin: 50 }
138 BugPanel { id: bugpanel }
141 State { name: "start"; when: statenum == 1
142 PropertyChanges { target: xmllistmodelelementtest
143 testtext: "This is a ListView populated by an XmlListModel. Clicking on an item will show the recipe details.\n"+
144 "Next we will change to source of the model data to a local string" }
146 State { name: "xmlstring"; when: statenum == 2
147 PropertyChanges { target: xmllistmodelelement; source: "" }
148 PropertyChanges { target: xmllistmodelelement; xml: modelxml }
149 PropertyChanges { target: xmllistmodelelementtest
150 testtext: "The list should now only contain a Hot chocolate recipe.\n"+
151 "Advance to restart the test." }