Results 1 to 6 of 6

Thread: Simple DOM Model - making it editable - inserting rows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Posts
    11
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows

    Unhappy Simple DOM Model - making it editable - inserting rows

    I've been messing with the Simple DOM Model Example and I want to make everything editable. I have a problem with adding rows to the model.

    Specifically, when I use insertAfter function in QDomNode:: parentNode(), the model gets updated only internally. When I collapse and expand the parent, the added node(s) are copies of the last nodes and are inserted in the end.

    The only way I am able to get it right is save XML to QString and load it again into QDomModel and QTreeView. Then everything that has been inserted is where it should be. But then all the expanded states are lost! Not very user-friendly...

    I have tried adding rows using insertRows function in QDomModel, however a copy of the entire model gets inserted as a child instead of an empty row!

    Qt Code:
    1. // Get current index
    2. QModelIndex currentTreeIdx = ui->treeView->selectionModel()->currentIndex();
    3. // Get the node corresponding to that index
    4. DomItem *itemRef = static_cast<DomItem*>(currentTreeIdx.internalPointer());
    5.  
    6. QDomElement newParentTag;
    7. QDomElement newTextTag;
    8. QDomText newText;
    9. // Create tags
    10. newParentTag = model->domDocument.createElement("Parent");
    11. newTextTag = model->domDocument.createElement("Child");
    12. newText = model->domDocument.createTextNode("Child text data");
    13. newTextTag.appendChild(newText);
    14. newSubtitleTag.appendChild(newTextTag);
    15. // Attempt to insert a new tag after the currently selected item
    16. itemRef->node().parentNode().insertAfter(newParentTag, itemRef->node());
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to Wolf900 for this useful post:


Similar Threads

  1. Making a QTableWidget Editable
    By llemes4011 in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2010, 19:12
  2. trouble making simple DOM model example editable
    By Mamra in forum Qt Programming
    Replies: 6
    Last Post: 1st October 2009, 14:40
  3. Efficient way of inserting rows?
    By afflictedd2 in forum Qt Programming
    Replies: 1
    Last Post: 14th July 2008, 20:01
  4. QTreeView rows editable
    By Pesho in forum Qt Programming
    Replies: 5
    Last Post: 13th September 2007, 13:19
  5. QTreeWidget - Making a Column editable.
    By Preeteesh in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2007, 12:02

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.