OK, I've now got this going. After some more playing I decided to select the data by xml Node name - I used "Page" & "Item". If anyone else is looking at hierarchical models in C++ and views in QML the other key requirement I found to implementing a solution is the QML DelegateModel (formally VisualDataModel). Here are the snippets that directly answer the questions...
From DomModel.h
public:
enum menuRoles
{
PageNumberRole = Qt::UserRole + 1,
PageNameRole,
ItemNumberRole,
ItemNameRole
};
...
QVariant data(const QModelIndex &index, int role) const;
...
protected:
QHash<int, QByteArray> roleNames() const;
From DomModel.cpp
QVariant DomModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
else
{
DomItem *item = static_cast<DomItem*>(index.internalPointer());
QDomNode node = item->node();
if(node.nodeName() == "Page")
{
switch (role)
{
case PageNumberRole:
return node.attributes().namedItem("number").nodeValue();
break;
case PageNameRole:
return node.attributes().namedItem("name").nodeValue();
break;
default:
return QVariant();
break;
}
}
else if(node.nodeName() == "Item")
{
switch (role)
{
case ItemNumberRole:
return node.attributes().namedItem("number").nodeValue();
break;
case ItemNameRole:
return node.attributes().namedItem("name").nodeValue();
break;
default:
return QVariant();
break;
}
}
else
return QVariant();
}
}
...
QHash<int, QByteArray> DomModel::roleNames() const
{
// This tells the subscribing views what data roles are available
// Any changes must be reflected in the DomModel::data function
QHash<int, QByteArray> roles;
roles[PageNumberRole] = "pageNumber";
roles[PageNameRole] = "pageName";
roles[ItemNumberRole] = "itemNumber";
roles[ItemNameRole] = "itemName";
return roles;
}