diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-02-24 13:31:20 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-03-10 15:17:57 +0100 |
commit | ea8f8e09007f4acb5530b1966bc5b2afab609064 (patch) | |
tree | 03b2c9ff8defd65a45daefe516ecc51501b528d7 /tests/auto/qml/qqmlxmllistmodel/data | |
parent | c42d558dc9ff89d452546412ee88a16ae1e324e4 (diff) |
Introduce XmlListModel to QtDeclarative
XmlListModel was previously a part of QtXmlPatterns, which would not
be a part of Qt 6. The idea of this commit is to move a simplified
version of XmlListModel to QtDeclarative, so that it could be used
at least in the examples of different Qt modules.
Unlike the old implementation, this version does not have an XPath
support. This results in a reduced feature set - the user can't
build complicated XPath queries to populate model roles.
Now the user can select an xml element and, optionally, an
attribute, which will be used to extract the data.
[ChangeLog][XmlListModel] Introduce an XmlListModel QML model to
create read-only models from XML data.
This is a simplified version of a model from QtXmlPatterns, which
would no longer be a part of Qt 6. This model supports only simple
slash-separated paths and, optionally, one attribute for each
element.
Task-number: QTBUG-89817
Change-Id: I4186587dc1445dd981ac92b4ce104434236a32b9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlxmllistmodel/data')
20 files changed, 438 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlxmllistmodel/data/attributes.qml b/tests/auto/qml/qqmlxmllistmodel/data/attributes.qml new file mode 100644 index 0000000000..df44c7862b --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/attributes.qml @@ -0,0 +1,11 @@ +import QtQml.XmlListModel + +XmlListModel { + source: "attributes.xml" + query: "/Pets/Pet" + + XmlListModelRole { name: "name"; elementName: ""; attributeName: "name" } + XmlListModelRole { name: "type"; elementName: "info"; attributeName: "type" } + XmlListModelRole { name: "age"; elementName: "info"; attributeName: "age" } + XmlListModelRole { name: "size"; elementName: "info"; attributeName: "size" } +} diff --git a/tests/auto/qml/qqmlxmllistmodel/data/attributes.xml b/tests/auto/qml/qqmlxmllistmodel/data/attributes.xml new file mode 100644 index 0000000000..a10b77c7dc --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/attributes.xml @@ -0,0 +1,14 @@ +<Pets> + <Pet name="Polly"> + <info type="Parrot" age="12" size="Small"/> + </Pet> + <Pet name="Penny"> + <info type="Turtle" age="4" size="Small"/> + </Pet> + <Pet name="Spot"> + <info type="Dog" age="9" size="Medium"/> + </Pet> + <Pet name="Tiny"> + <info type="Elephant" age="15" size="Large"/> + </Pet> +</Pets> diff --git a/tests/auto/qml/qqmlxmllistmodel/data/elementErrors.qml b/tests/auto/qml/qqmlxmllistmodel/data/elementErrors.qml new file mode 100644 index 0000000000..559aab1ef4 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/elementErrors.qml @@ -0,0 +1,9 @@ +import QtQml.XmlListModel + +XmlListModel { + source: "model.xml" + query: "/Pets/Pet" + XmlListModelRole { name: "name"; elementName: "/name" } // starts with '/' + XmlListModelRole { name: "age"; elementName: "age/" } // ends with '/' + XmlListModelRole { name: "type"; elementName: "some//element" } // contains "//" +} diff --git a/tests/auto/qml/qqmlxmllistmodel/data/empty.xml b/tests/auto/qml/qqmlxmllistmodel/data/empty.xml new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/empty.xml diff --git a/tests/auto/qml/qqmlxmllistmodel/data/malformedAttribute.xml b/tests/auto/qml/qqmlxmllistmodel/data/malformedAttribute.xml new file mode 100644 index 0000000000..6e4c0e3637 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/malformedAttribute.xml @@ -0,0 +1,28 @@ +<Pets> + <Pet> + <name>Polly</name> + <completely> + <useless> + <hierarchy/> + </useless> + </completely> + <some> + <other> + <type>incorrect type tag</type> + <another> + <nested> + <tag/> + </nested> + </another> + <useful> + <tags> + <type>Parrot</type> + <size>incorrect size tag</size> + </tags> + </useful> + <age 1value="12"/> + </other> + <size>Small</size> + </some> + </Pet> +</Pets>
\ No newline at end of file diff --git a/tests/auto/qml/qqmlxmllistmodel/data/malformedData.qml b/tests/auto/qml/qqmlxmllistmodel/data/malformedData.qml new file mode 100644 index 0000000000..092eaa0cdf --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/malformedData.qml @@ -0,0 +1,10 @@ +import QtQml.XmlListModel + +XmlListModel { + query: "/Pets/Pet" + + XmlListModelRole { name: "name"; elementName: "name" } + XmlListModelRole { name: "type"; elementName: "some/other/useful/tags/type" } + XmlListModelRole { name: "age"; elementName: "some/other/age"; attributeName: "value" } + XmlListModelRole { name: "size"; elementName: "some/size" } +}
\ No newline at end of file diff --git a/tests/auto/qml/qqmlxmllistmodel/data/malformedTagNestedLevel.xml b/tests/auto/qml/qqmlxmllistmodel/data/malformedTagNestedLevel.xml new file mode 100644 index 0000000000..d0332e2924 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/malformedTagNestedLevel.xml @@ -0,0 +1,28 @@ +<Pets> + <Pet> + <name>Polly</name> + <completely> + <useless> + <hierarchy/> + </useless> + </completely> + <some> + <other> + <type>incorrect type tag</type> + <another> + <nested> + <tag/> + </nested> + </another> + <useful> + <tags> + <type>Parrot + <size>incorrect size tag</size> + </tags> + </useful> + <age value="12"/> + </other> + <size>Small</size> + </some> + </Pet> +</Pets>
\ No newline at end of file diff --git a/tests/auto/qml/qqmlxmllistmodel/data/malformedTagTopLevel.xml b/tests/auto/qml/qqmlxmllistmodel/data/malformedTagTopLevel.xml new file mode 100644 index 0000000000..b499db4b51 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/malformedTagTopLevel.xml @@ -0,0 +1,28 @@ +<Pets> + <Pet> + <name>Polly</na> + <completely> + <useless> + <hierarchy/> + </useless> + </completely> + <some> + <other> + <type>incorrect type tag</type> + <another> + <nested> + <tag/> + </nested> + </another> + <useful> + <tags> + <type>Parrot</type> + <size>incorrect size tag</size> + </tags> + </useful> + <age value="12"/> + </other> + <size>Small</size> + </some> + </Pet> +</Pets>
\ No newline at end of file diff --git a/tests/auto/qml/qqmlxmllistmodel/data/model.qml b/tests/auto/qml/qqmlxmllistmodel/data/model.qml new file mode 100644 index 0000000000..6634725d4c --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/model.qml @@ -0,0 +1,11 @@ +import QtQml.XmlListModel + +XmlListModel { + source: "model.xml" + query: "/Pets/Pet" + + XmlListModelRole { name: "name"; elementName: "name" } + XmlListModelRole { name: "type"; elementName: "type" } + XmlListModelRole { name: "age"; elementName: "age" } + XmlListModelRole { name: "size"; elementName: "size" } +} diff --git a/tests/auto/qml/qqmlxmllistmodel/data/model.xml b/tests/auto/qml/qqmlxmllistmodel/data/model.xml new file mode 100644 index 0000000000..40cd6d0432 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/model.xml @@ -0,0 +1,54 @@ +<Pets> + <Pet> + <name>Polly</name> + <type>Parrot</type> + <age>12</age> + <size>Small</size> + </Pet> + <Pet> + <name>Penny</name> + <type>Turtle</type> + <age>4</age> + <size>Small</size> + </Pet> + <Pet> + <name>Warren</name> + <type>Rabbit</type> + <age>2</age> + <size>Small</size> + </Pet> + <Pet> + <name>Spot</name> + <type>Dog</type> + <age>9</age> + <size>Medium</size> + </Pet> + <Pet> + <name>Whiskers</name> + <type>Cat</type> + <age>2</age> + <size>Medium</size> + </Pet> + <Pet> + <name>Joey</name> + <type>Kangaroo</type> + <age>1</age> + </Pet> + <Pet> + <name>Kimba</name> + <type>Bunny</type> + <age>65</age> + <size>Large</size> + </Pet> + <Pet> + <name>Rover</name> + <type>Dog</type> + <size>Large</size> + </Pet> + <Pet> + <name>Tiny</name> + <type>Elephant</type> + <age>15</age> + <size>Large</size> + </Pet> +</Pets> diff --git a/tests/auto/qml/qqmlxmllistmodel/data/model2.xml b/tests/auto/qml/qqmlxmllistmodel/data/model2.xml new file mode 100644 index 0000000000..dab2ec6dc0 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/model2.xml @@ -0,0 +1,14 @@ +<Pets> + <Pet> + <name>Polly</name> + <type>Parrot</type> + <age>12</age> + <size>Small</size> + </Pet> + <Pet> + <name>Penny</name> + <type>Turtle</type> + <age>4</age> + <size>Small</size> + </Pet> +</Pets> diff --git a/tests/auto/qml/qqmlxmllistmodel/data/nestedElements.qml b/tests/auto/qml/qqmlxmllistmodel/data/nestedElements.qml new file mode 100644 index 0000000000..2106ac3f77 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/nestedElements.qml @@ -0,0 +1,11 @@ +import QtQml.XmlListModel + +XmlListModel { + source: "nestedElements.xml" + query: "/Pets/Pet" + + XmlListModelRole { name: "name"; elementName: "name" } + XmlListModelRole { name: "type"; elementName: "some/other/useful/tags/type" } + XmlListModelRole { name: "age"; elementName: "some/other/age"; attributeName: "value" } + XmlListModelRole { name: "size"; elementName: "some/size" } +} diff --git a/tests/auto/qml/qqmlxmllistmodel/data/nestedElements.xml b/tests/auto/qml/qqmlxmllistmodel/data/nestedElements.xml new file mode 100644 index 0000000000..8ea904920e --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/nestedElements.xml @@ -0,0 +1,76 @@ +<Pets> + <Pet> + <name>Polly</name> + <completely> + <useless> + <hierarchy/> + </useless> + </completely> + <some> + <other> + <type>incorrect type tag</type> + <another> + <nested> + <tag/> + </nested> + </another> + <useful> + <tags> + <type>Parrot</type> + <size>incorrect size tag</size> + </tags> + </useful> + <age value="12"/> + </other> + <size>Small</size> + </some> + </Pet> + <Pet> + <name>Penny</name> + <some> + <other> + <type>incorrect type tag</type> + <useful> + <tags> + <type>Turtle</type> + <size>incorrect size tag</size> + </tags> + </useful> + <age value="4"/> + </other> + <size>Small</size> + </some> + </Pet> + <Pet> + <name>Spot</name> + <some> + <other> + <type>incorrect type tag</type> + <useful> + <tags> + <type>Dog</type> + <size>incorrect size tag</size> + </tags> + </useful> + <age value="9"/> + </other> + <size>Medium</size> + </some> + </Pet> + <Pet> + <name>Tiny</name> + <some> + <other> + <type>incorrect type tag</type> + <useful> + <tags> + <type>Elephant</type> + <size>incorrect size tag</size> + </tags> + </useful> + <age value="15"/> + </other> + <size>Large</size> + </some> + </Pet> +</Pets> diff --git a/tests/auto/qml/qqmlxmllistmodel/data/propertychanges.qml b/tests/auto/qml/qqmlxmllistmodel/data/propertychanges.qml new file mode 100644 index 0000000000..3b3e77d726 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/propertychanges.qml @@ -0,0 +1,10 @@ +import QtQml.XmlListModel + +XmlListModel { + source: "model.xml" + query: "/Pets/Pet" + XmlListModelRole { objectName: "role"; name: "name"; elementName: "name" } + XmlListModelRole { name: "type"; elementName: "type" } + XmlListModelRole { name: "age"; elementName: "age" } + XmlListModelRole { name: "size"; elementName: "size" } +} diff --git a/tests/auto/qml/qqmlxmllistmodel/data/proxyCrash.qml b/tests/auto/qml/qqmlxmllistmodel/data/proxyCrash.qml new file mode 100644 index 0000000000..9233975b19 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/proxyCrash.qml @@ -0,0 +1,8 @@ +import QtQml.XmlListModel +import SortFilterProxyModel 1.0 + +SortFilterProxyModel { + source: XmlListModel { + XmlListModelRole { } + } +} diff --git a/tests/auto/qml/qqmlxmllistmodel/data/recipes.qml b/tests/auto/qml/qqmlxmllistmodel/data/recipes.qml new file mode 100644 index 0000000000..18cd8c301a --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/recipes.qml @@ -0,0 +1,10 @@ +import QtQml.XmlListModel + +XmlListModel { + source: "recipes.xml" + query: "/recipes/recipe" + XmlListModelRole { name: "title"; elementName: ""; attributeName: "title" } + XmlListModelRole { name: "picture"; elementName: "picture" } + XmlListModelRole { name: "ingredients"; elementName: "ingredients" } + XmlListModelRole { name: "preparation"; elementName: "method" } +} diff --git a/tests/auto/qml/qqmlxmllistmodel/data/recipes.xml b/tests/auto/qml/qqmlxmllistmodel/data/recipes.xml new file mode 100644 index 0000000000..d71de60710 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/recipes.xml @@ -0,0 +1,90 @@ +<recipes> + <recipe title="Pancakes"> + <picture>content/pics/pancakes.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 1 cup (150g) self-raising flour + <li> 1 tbs caster sugar + <li> 3/4 cup (185ml) milk + <li> 1 egg + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Sift flour and sugar together into a bowl. Add a pinch of salt. + <li> Beat milk and egg together, then add to dry ingredients. Beat until smooth. + <li> Pour mixture into a pan on medium heat and cook until bubbles appear on the surface. + <li> Turn over and cook other side until golden. + </ol> + </html> + ]]></method> + </recipe> + <recipe title="Fruit Salad"> + <picture>content/pics/fruit-salad.jpg</picture> + <ingredients><![CDATA[* Seasonal Fruit]]></ingredients> + <method><![CDATA[* Chop fruit and place in a bowl.]]></method> + </recipe> + <recipe title="Vegetable Soup"> + <picture>content/pics/vegetable-soup.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 1 onion + <li> 1 turnip + <li> 1 potato + <li> 1 carrot + <li> 1 head of celery + <li> 1 1/2 litres of water + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Chop vegetables. + <li> Boil in water until vegetables soften. + <li> Season with salt and pepper to taste. + </ol> + </html> + ]]></method> + </recipe> + <recipe title="Hamburger"> + <picture>content/pics/hamburger.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 500g minced beef + <li> Seasoning + <li> lettuce, tomato, onion, cheese + <li> 1 hamburger bun for each burger + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Mix the beef, together with seasoning, in a food processor. + <li> Shape the beef into burgers. + <li> Grill the burgers for about 5 mins on each side (until cooked through) + <li> Serve each burger on a bun with ketchup, cheese, lettuce, tomato and onion. + </ol> + </html> + ]]></method> + </recipe> + <recipe title="Lemonade"> + <picture>content/pics/lemonade.jpg</picture> + <ingredients><![CDATA[<html> + <ul> + <li> 1 cup Lemon Juice + <li> 1 cup Sugar + <li> 6 Cups of Water (2 cups warm water, 4 cups cold water) + </ul> + </html> + ]]></ingredients> + <method><![CDATA[<html> + <ol> + <li> Pour 2 cups of warm water into a pitcher and stir in sugar until it dissolves. + <li> Pour in lemon juice, stir again, and add 4 cups of cold water. + <li> Chill or serve over ice cubes. + </ol> + </html> + ]]></method> + </recipe> +</recipes> diff --git a/tests/auto/qml/qqmlxmllistmodel/data/roleCrash.qml b/tests/auto/qml/qqmlxmllistmodel/data/roleCrash.qml new file mode 100644 index 0000000000..85cb692f03 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/roleCrash.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 +import QtQml.XmlListModel + +XmlListModel { + id: model + XmlListModelRole {} + Component.onCompleted: { + model.roles = 0 + } +} diff --git a/tests/auto/qml/qqmlxmllistmodel/data/threading.qml b/tests/auto/qml/qqmlxmllistmodel/data/threading.qml new file mode 100644 index 0000000000..43672d01ba --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/threading.qml @@ -0,0 +1,8 @@ +import QtQml.XmlListModel + +XmlListModel { + query: "/data/item" + XmlListModelRole { name: "name"; elementName: "name" } + XmlListModelRole { name: "age"; elementName: "age" } + XmlListModelRole { name: "sport"; elementName: "sport" } +} diff --git a/tests/auto/qml/qqmlxmllistmodel/data/unique.qml b/tests/auto/qml/qqmlxmllistmodel/data/unique.qml new file mode 100644 index 0000000000..1289c7de93 --- /dev/null +++ b/tests/auto/qml/qqmlxmllistmodel/data/unique.qml @@ -0,0 +1,8 @@ +import QtQml.XmlListModel + +XmlListModel { + source: "model.xml" + query: "/Pets/Pet" + XmlListModelRole { name: "name"; elementName: "name" } + XmlListModelRole { name: "name"; elementName: "type" } +} |