Тип XmlRole QML
Для указания роли для XmlListModel. Подробнее...
| Заявление об импорте: | import QtQuick.XmlListModel 2.11 |
Свойства
Подробное описание
См. также Qt QML.
Документация по свойствам
isKey : bool
Определяет, является ли эта роль ключевой. Ключевые роли используются для определения, следует ли обновлять или добавлять набор значений в модель XML-списка при вызове XmlListModel::reload().
См. также XmlListModel.
name : string
Имя роли. Это имя используется для доступа к данным модели для этой роли.
Например, следующая модель имеет роль с именем «title», к которой можно получить доступ из делегата представления:
XmlListModel {
id: xmlModel
// ...
XmlRole {
name: "title"
query: "title/string()"
}
} ListView {
model: xmlModel
delegate: Text { text: title }
} query : string
Запрос относительного XPath для этой роли. Запрос должен быть относительным; он не может начинаться с '/'.
Например, если у вас есть документ XML такого вида:
<?xml version="1.0" encoding="iso-8859-1" ?>
<catalog>
<book type="Online" wanted="true">
<title>Qt 5 Cadaques</title>
<year>2014</year>
<author>Juergen Bocklage-Ryannel</author>
<author>Johan Thelin</author>
</book>
<book type="Hardcover">
<title>C++ GUI Programming with Qt 4</title>
<year>2006</year>
<author>Jasmin Blanchette</author>
<author>Mark Summerfield</author>
</book>
<book type="Paperback">
<title>Programming with Qt</title>
<year>2002</year>
<author>Matthias Kalle Dalheimer</author>
</book>
</catalog> Вот некоторые допустимые выражения XPath для запросов XmlRole для этого документа:
XmlListModel {
id: model
...
// XmlRole queries will be made on <book> elements
query: "/catalog/book"
// query the book title
XmlRole { name: "title"; query: "title/string()" }
// query the book's year
XmlRole { name: "year"; query: "year/number()" }
// query the book's type (the '@' indicates 'type' is an attribute, not an element)
XmlRole { name: "type"; query: "@type/string()" }
// query the book's first listed author (note in XPath the first index is 1, not 0)
XmlRole { name: "first_author"; query: "author[1]/string()" }
// query the wanted attribute as a boolean
XmlRole { name: "wanted"; query: "boolean(@wanted)" }
} Доступ к данным модели для вышеуказанных ролей из делегата:
ListView {
width: 300; height: 200
model: model
delegate: Column {
Text { text: title + " (" + type + ")"; font.bold: wanted }
Text { text: first_author }
Text { text: year }
} См. спецификацию W3C XPath 2.0 для получения дополнительной информации.
© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/archives/qt-5.11/qml-qtquick-xmllistmodel-xmlrole.html