summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-03-05 17:59:54 +0100
committerIvan Solovev <ivan.solovev@qt.io>2021-03-18 21:18:54 +0100
commit31f7b6222dfb07be6334c2d2e9280fff17cdd6a7 (patch)
tree84eee9cba8da593f604491eb6d8c739970104467
parent8e94a3347f9f2bc5dfb89b66fee98f51008d965c (diff)
downloadqtdeclarative-31f7b6222dfb07be6334c2d2e9280fff17cdd6a7.tar.gz
Update elements test application to use new XmlListModel
As far as I can see, this application is not used anywhere. But this patch at least makes it valid, so that someone could theoretically use it. However the example is simplified, because the new XmlListModel does not provide the features that were previousl used there. Task-number: QTBUG-89817 Change-Id: I0c5d724cf4807eb9596829331c10796579716c54 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--tests/testapplications/elements/content/XmlListModelElement.qml95
-rw-r--r--tests/testapplications/elements/content/cookbook.xml54
2 files changed, 69 insertions, 80 deletions
diff --git a/tests/testapplications/elements/content/XmlListModelElement.qml b/tests/testapplications/elements/content/XmlListModelElement.qml
index 90a5095cc7..36b5569761 100644
--- a/tests/testapplications/elements/content/XmlListModelElement.qml
+++ b/tests/testapplications/elements/content/XmlListModelElement.qml
@@ -27,27 +27,20 @@
****************************************************************************/
import QtQuick 2.0
-import QtQuick.XmlListModel 2.0
+import QtQml.XmlListModel
Item {
id: xmllistmodelelementtest
anchors.fill: parent
property string testtext: ""
- property string modelxml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
- "<cookbook><recipe id=\"MushroomSoup\">"+
- "<title>Hot chocolate</title>"+
- "<ingredient name=\"Milk\" quantity=\"1\" unit=\"cup\"/>"+
- "<time quantity=\"2\" unit=\"minutes\"/>"+
- "<method><step>1. Place the cup of milk in the microwave for 1 minute.</step>"+
- "<step>2. Stir in 2 teaspoons of drinking chocolate.</step></method></recipe></cookbook>"
XmlListModel { id: xmllistmodelelement
source: "cookbook.xml"
query: "/cookbook/recipe"
- XmlRole { name: "title"; query: "title/string()" }
- XmlRole { name: "xmlid"; query: "@id/string()" }
- XmlRole { name: "method"; query: "method/string()" }
- XmlRole { name: "time"; query: "time/@quantity/number()" }
+ XmlListModelRole { name: "title"; elementName: "title" }
+ XmlListModelRole { name: "method"; elementName: "method" }
+ XmlListModelRole { name: "time"; elementName: "time"; attributeName: "quantity" }
+ XmlListModelRole { name: "ingredients"; elementName: "ingredients" }
}
ListView {
@@ -70,36 +63,56 @@ Item {
Behavior on opacity { NumberAnimation { duration: 250 } }
}
- // Sub XmlListModel
- XmlListModel { id: subxmllistmodelelement
- source: "cookbook.xml"
- query: "/cookbook/recipe[@id = '"+model.xmlid+"']/ingredient"
- XmlRole { name: "ingredientname"; query: "@name/string()" }
- XmlRole { name: "ingredientquantity"; query: "@quantity/string()" }
- XmlRole { name: "ingredientunit"; query: "@unit/string()" }
- }
-
- ListView {
+ Item {
id: ingredientlist
- model: subxmllistmodelelement
- height: 20 * count; width: parent.width
visible: opacity != 0
+ width: parent.width
+ height: header.implicitHeight + content.implicitHeight
Behavior on opacity { NumberAnimation { duration: 250 } }
- anchors.horizontalCenter: parent.horizontalCenter; anchors.top: recipetime.bottom; anchors.topMargin: 10
- header: Text { text: "<b>Ingredients:</b>" }
- delegate: Text {
- text: ingredientquantity + " " + ingredientunit + " of " + ingredientname; height: 20;
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ top: recipetime.bottom
+ topMargin: 10
+ }
+ Text {
+ id: header
+ text: "<b>Ingredients:</b>"
+ }
+ Text {
+ anchors.top: header.bottom;
+ id: content
+ wrapMode: Text.WordWrap
+ textFormat: Text.MarkdownText
+ width: ingredientlist.width
+ // a bit of regexp to remove unneeded whitespaces
+ text: model.ingredients.replace(/\ +/g,' ')
}
}
- Text {
+ Item {
id: recipemethod
- property string methodtext: ""
- width: parent.width; wrapMode: Text.WordWrap; visible: opacity != 0; text: methodtext
- anchors.horizontalCenter: parent.horizontalCenter; anchors.top: ingredientlist.bottom
- Behavior on opacity { NumberAnimation { duration: 250 } }
- Component.onCompleted: { methodtext = model.method; }
+ width: parent.width;
+ height: methodHeader.implicitHeight + methodContent.implicitHeight
+ visible: opacity != 0;
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ top: ingredientlist.bottom
+ }
+ Text {
+ id: methodHeader
+ text: "<b>Cooking method:</b>"
+ }
+ Text {
+ id: methodContent
+ anchors.top: methodHeader.bottom;
+ wrapMode: Text.WordWrap
+ textFormat: Text.MarkdownText
+ width: recipemethod.width
+ // a bit of regexp to remove unneeded whitespaces
+ text: model.method.replace(/\ +/g,' ')
+ }
}
+
MouseArea { anchors.fill: parent; onClicked: delbox.state = delbox.state == "open" ? "closed" : "open" }
Behavior on height { NumberAnimation { duration: 250 } }
states: [
@@ -112,6 +125,8 @@ Item {
State { name: "open"
PropertyChanges { target: delbox; height: recipemethod.height+recipetime.height+ingredientlist.height+50 }
PropertyChanges { target: recipemethod; opacity: 1 }
+ PropertyChanges { target: recipetime; opacity: 1 }
+ PropertyChanges { target: ingredientlist; opacity: 1 }
StateChangeScript { script: { recipeview.positionViewAtIndex(model.index, ListView.Beginning); } }
}
]
@@ -121,21 +136,15 @@ Item {
SystemTestHelp { id: helpbubble; visible: statenum != 0
anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; topMargin: 50 }
+ showadvance: false
}
BugPanel { id: bugpanel }
states: [
State { name: "start"; when: statenum == 1
PropertyChanges { target: xmllistmodelelementtest
- testtext: "This is a ListView populated by an XmlListModel. Clicking on an item will show the recipe details.\n"+
- "Next we will change to source of the model data to a local string" }
- },
- State { name: "xmlstring"; when: statenum == 2
- PropertyChanges { target: xmllistmodelelement; source: "" }
- PropertyChanges { target: xmllistmodelelement; xml: modelxml }
- PropertyChanges { target: xmllistmodelelementtest
- testtext: "The list should now only contain a Hot chocolate recipe.\n"+
- "Advance to restart the test." }
+ testtext: "This is a ListView populated by an XmlListModel. Clicking on an item will show the recipe details."
+ }
}
]
diff --git a/tests/testapplications/elements/content/cookbook.xml b/tests/testapplications/elements/content/cookbook.xml
index 33dd91a5de..16c7f56a57 100644
--- a/tests/testapplications/elements/content/cookbook.xml
+++ b/tests/testapplications/elements/content/cookbook.xml
@@ -2,35 +2,18 @@
<cookbook>
<recipe id="MushroomSoup">
<title>Quick and Easy Mushroom Soup</title>
- <ingredient name="Fresh mushrooms"
- quantity="7"
- unit="pieces"/>
- <ingredient name="Garlic"
- quantity="1"
- unit="cloves"/>
- <ingredient name="Olive oil"
- quantity="2"
- unit="tablespoons"/>
- <ingredient name="Milk"
- quantity="200"
- unit="milliliters"/>
- <ingredient name="Water"
- quantity="200"
- unit="milliliters"/>
- <ingredient name="Cream"
- quantity="100"
- unit="milliliters"/>
- <ingredient name="Vegetable soup cube"
- quantity="1/2"
- unit="cubes"/>
- <ingredient name="Ground black pepper"
- quantity="1/2"
- unit="teaspoons"/>
- <ingredient name="Dried parsley"
- quantity="1"
- unit="teaspoons"/>
- <time quantity="20"
- unit="minutes"/>
+ <ingredients>
+ <ingredient>1. 7 pieces of Fresh mushrooms</ingredient>
+ <ingredient>2. 1 cloves of Garlic</ingredient>
+ <ingredient>3. 2 tablespoons of Olive oil</ingredient>
+ <ingredient>4. 200 milliliters of Milk</ingredient>
+ <ingredient>5. 200 milliliters of Water</ingredient>
+ <ingredient>6. 200 milliliters of Cream</ingredient>
+ <ingredient>7. 1/2 cubes of Vegetable soup cube</ingredient>
+ <ingredient>8. 1/2 teaspoons of Ground black pepper</ingredient>
+ <ingredient>9. 1 teaspoon of Dried parsley</ingredient>
+ </ingredients>
+ <time quantity="20" unit="minutes"/>
<method>
<step>1. Slice mushrooms and garlic.</step>
<step>2. Fry mushroom slices and garlic with olive oil.</step>
@@ -43,14 +26,11 @@
</recipe>
<recipe id="CheeseOnToast">
<title>Cheese on Toast</title>
- <ingredient name="Bread"
- quantity="2"
- unit="slices"/>
- <ingredient name="Cheese"
- quantity="2"
- unit="slices"/>
- <time quantity="3"
- unit="minutes"/>
+ <ingredients>
+ <ingredient>1. 2 slices of Bread</ingredient>
+ <ingredient>2. 2 slices of Cheese</ingredient>
+ </ingredients>
+ <time quantity="3" unit="minutes"/>
<method>
<step>1. Slice the bread and cheese.</step>
<step>2. Grill one side of each slice of bread.</step>