Results 1 to 6 of 6

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

Hybrid 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:


  3. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Simple DOM Model - making it editable - inserting rows

    If you want the model to be updated, you need to add rows through the model API or at least inform the model how you are changing the underlying data structure.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:


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

    Default Re: Simple DOM Model - making it editable - inserting rows

    I've tried to inform the model by calling
    Qt Code:
    1. emit dataChanged(idx, idx);
    To copy to clipboard, switch view to plain text mode 
    in DomModel : QAbstractItemModel when QModelIndex idx is updated. It seems it does nothing.

    I've even tried to call it for each index in the model.

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


  7. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Simple DOM Model - making it editable - inserting rows

    dataChanged() is for modifying existing elements, not for adding new ones.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following 2 users say thank you to wysota for this useful post:

    Wolf900 (29th February 2012)

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
  •  
Qt is a trademark of The Qt Company.