Hello,

I have a QTreeView to which I set a subclassed DomModel:QAbstractItemModel. Each item is a DomItem which deals mostly with QDomNode. I set QDomDocument to this model. I think I've derived this system from one of the Qt examples.

It has 3 columns: 0 for node name, 1 for attributes and 2 for value.

Anyway, I wanted to make this XML DOM tree editable. I've modified some flags such as Qt::ItemIsEditable and some other things in the model class and now I can edit the model through QTreeView by double clicking.

For column 2 it's easy, since QDomItem has this setNodeValue function, however I've found there are no "set" functions for item->node().NodeName() and item->node().attributes() which would, I presume, modify columns 0 and 1.

So now when I modify column 2 it works, however columns 0 and 1 revert to their previous values upon pressing enter. But I cannot seem to find any way to modify them.

Qt Code:
  1. bool DomModel::setData(const QModelIndex &index, const QVariant &value,
  2. int role)
  3. {
  4. if (role != Qt::EditRole) return false;
  5.  
  6. DomItem *item = static_cast<DomItem*>(index.internalPointer());
  7.  
  8. switch (index.column()){
  9. case 0:
  10. // ???
  11. break;
  12. case 1:
  13. // ???
  14. break;
  15. case 2:
  16. item->node().setNodeValue(value.toString()); // This works - QTreeView's column 2 is updated
  17. break;
  18. }
  19. ...
  20. }
To copy to clipboard, switch view to plain text mode