Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / testapplications / elements / content / XmlListModelElement.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 import QtQuick 2.0
43
44 Item {
45     id: xmllistmodelelementtest
46     anchors.fill: parent
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>"
55
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()" }
63     }
64
65     ListView {
66         id: recipeview
67         model: xmllistmodelelement; height: 300; width: 300; clip: true
68         anchors.centerIn: parent
69         delegate: Component {
70             Rectangle { id: delbox; height: 50; width: 296; color: "orange"; border.color: "black"; state: "closed"; clip: true; radius: 5
71                 anchors.horizontalCenter: parent.horizontalCenter
72                 Text {
73                     id: recipetitle
74                     text: model.title; font.pointSize: 12; font.bold: true
75                     anchors.horizontalCenter: parent.horizontalCenter; y: 20;
76                 }
77
78                 Text {
79                     id: recipetime
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 } }
83                 }
84
85                 // Sub XmlListModel
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()" }
92                 }
93
94                 ListView {
95                     id: ingredientlist
96                     model: subxmllistmodelelement
97                     height: 20 * count; width: parent.width
98                     visible: opacity != 0
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>" }
102                     delegate: Text {
103                         text: ingredientquantity + " " + ingredientunit + " of " + ingredientname; height: 20;
104                     }
105                 }
106
107                 Text {
108                     id: recipemethod
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); }
114                 }
115                 MouseArea { anchors.fill: parent; onClicked: delbox.state = delbox.state == "open" ? "closed" : "open" }
116                 Behavior on height { NumberAnimation { duration: 250 } }
117                 states: [
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 }
123                     },
124                     State { name: "open"
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); } }
128                     }
129                 ]
130             }
131         }
132     }
133
134     SystemTestHelp { id: helpbubble; visible: statenum != 0
135         anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; topMargin: 50 }
136     }
137     BugPanel { id: bugpanel }
138
139     states: [
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" }
144         },
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." }
151         }
152     ]
153
154 }