Browsing through nested items in XmlListModel: XPath Query question



  • Hi All,

    I am trying to make a little program that iterates through an xmlfile with childs that are actually submenus. I am almost there, the last thing missing is a way to tell the ListView delegate what query it should pass back to the XmlListModel when the item is clicked. And also a query to determine if certain children exists. I find it a bit hard to explain, please have a look at below example. What I really want is to get rid of the 'subMenuQuery' element in the xml file. Can that be done?

    So line 14 in the qml file needs to be some more elaborate XPath query. Or perhaps in line 24 I can find out which index this listviewitem has, so I can use it to create a string containing the new query for the XmlListModel?

    For your reference, the codes. First the XML File
    @
    <?xml version="1.0" encoding="utf-8"?>
    <items>
    <item>
    <title>Battery voltage</title>
    <value>13.4V</value>
    </item>
    <item>
    <title>Battery current</title>
    <value>+0.3A</value>
    </item>
    <item>
    <title>Submenu</title>
    <value>-90Ah</value>
    <subMenuQuery>/items/item[3]/items/item</subMenuQuery>
    <items>
    <item>
    <title>Submenitem1</title>
    <value>1</value
    </item>
    <item>
    <title>Submenitem2</title>
    <value>2</value
    </item>
    </items>
    </item>
    </items>
    @

    The qml file:
    @
    import QtQuick 1.0

    Rectangle {
    width: 480
    height: 272

    XmlListModel {
        id: xmlModel
        source: "lynxshunt.xml"
        query: "/items/item"
    
        XmlRole { name: "title"; query: "title/string()" }
        XmlRole { name: "value"; query: "value/string()" }
        XmlRole { name: "subMenuQuery"; query: "subMenuQuery/string()" }
    }
    
    ListView {
        id: listView;
        anchors.fill: parent;
        model: xmlModel;
        delegate: MyListItemDelegate {
            deviceName: title
            deviceValue: listView.currentIndex.toString()
            submenuQuery: subMenuQuery
            lv: xmlModel
    
        }
    }
    

    }

    @

    The delegate:
    @
    import QtQuick 1.0

    Rectangle {
    id: rectangle1
    width: 480
    height: 54

    property string deviceName: "";
    property string deviceValue: "";
    property string submenuQuery: "";
    property XmlListModel lv;
    
    MouseArea {
        anchors.fill: parent
        onClicked: {
            if (submenuQuery != "") { lv.query = submenuQuery }
        }
    }
    
    Text {
        id: deviceNameText
        anchors.left:  parent.left; anchors.leftMargin: 20
        anchors.top:  parent.top; anchors.topMargin: 5
        text: rectangle1.deviceName
    }
    
    Text {
        id: deviceSummaryText
        anchors.left:  parent.left; anchors.leftMargin: 20
        anchors.bottom:  parent.bottom; anchors.bottomMargin: 8
        text: rectangle1.deviceValue
    }
    

    }
    @



  • What I've understood of your problem, is you need a support for nested xml in qml ?
    If that so , there is no support yet but you could follow the "bug report":http://bugreports.qt.nokia.com/browse/QTBUG-13688?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel#issue-tabs .


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.