Results 1 to 7 of 7

Thread: trouble making simple DOM model example editable

  1. #1
    Join Date
    Sep 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy trouble making simple DOM model example editable

    I've been trying for some time now to make the "simple DOM model" example editable but most of my efforts failed. I managed to achieve some functionality but still can’t get exactly what I need. Other editable model examples wont help.
    Is there someone that worked with this example in the past and transformed it into an editable model successfully? If there is, I’m dying to see his implementation or receive some guidance from him.
    Thanks anyway.

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

    Default Re: trouble making simple DOM model example editable

    What's wrong exactly?
    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.


  3. #3
    Join Date
    Sep 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: trouble making simple DOM model example editable

    My problem right now is how to insert rows(children).I was able to remove them and set data on them but the insertion functionality wont work.
    Nothing happens. I'm not sure what I'm supposed to do, each time I need to insert I create a new instand of the DomItem class and I insert a pointer to it in the last position of the QHash provided by the childs parent.
    Is there something more that should be done?
    I must be missing something.
    I've worked with the model/view concept before and I never had such problems. Never had to use DomDocument ofcourse.

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

    Default Re: trouble making simple DOM model example editable

    As far as I remember the nodes are only a part of representation of the dom tree. They don't actually touch the DOM tree in any way, they are just constructed from the tree. So if you want to add new tags to the tree, you need to both create the nodes and insert appropriate tags in the tree.
    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.


  5. #5
    Join Date
    Sep 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: trouble making simple DOM model example editable

    This is how I try to add one new child.
    In fact all I need is to append it.

    Qt Code:
    1. QDomNode node;
    2. DomItem *item = new DomItem(node, childItems.count()+1, this);
    3. domNode.appendChild(node);
    4. childItems.insert(childItems.count()+1 ,item);
    To copy to clipboard, switch view to plain text mode 

    First I create a new null node.
    Then a new DomItem object(the class that represents data upon the node).
    Finaly I append the node to the fathers QDomNodeList and the new DomItem pointer to the fathers QHash.

    After this is executed I get the following message:
    QTreeView:Internal representetion of the tree corrupted.Reseting

    Any ideas...?

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

    Default Re: trouble making simple DOM model example editable

    What about emitting proper signals rom the model?
    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.


  7. #7
    Join Date
    Sep 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: trouble making simple DOM model example editable

    I'm not sure which signals you mean...layoutAboutToBeChanged() or rowsAboutToBeInserted() perhaps?
    I think beginInsertRows() will take care of those things

    Anyway, this is how my insert mechanism looks like
    Is this what you have in mind?

    Qt Code:
    1. bool DomModel::insertRows(int position, int rows, const QModelIndex& parent)
    2. {
    3. DomItem *parentItem;
    4.  
    5. if (!parent.isValid())
    6. parentItem = rootItem;
    7. else
    8. parentItem = static_cast<DomItem*>(parent.internalPointer());
    9.  
    10. //only need to append one child
    11. beginInsertRows(parent, position, position);
    12.  
    13. if(!parentItem->insertChild())
    14. return false;
    15.  
    16. endInsertRows();
    17.  
    18. return true;
    19. }
    20.  
    21. bool DomItem::insertChild()
    22. {
    23. int rows = childItems.count();
    24.  
    25. QDomNode node;
    26. DomItem *item = new DomItem(node, rows+1, this);
    27. domNode.appendChild(node);
    28. childItems.insert(rows+1, item);
    29.  
    30. return true;
    31. }
    To copy to clipboard, switch view to plain text mode 

    I keep getting the same message(which was written wrong in my last post)

    QTreeView::rowsInserted internal representation of the model has been corrupted, resetting.

    It looks like bad indexing occurs...but I'm not sure why that happens.

Similar Threads

  1. Replies: 4
    Last Post: 10th October 2009, 17:59
  2. Replies: 12
    Last Post: 5th July 2009, 16:03
  3. A simple example of a tree model
    By YaK in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2009, 17:15
  4. QTreeWidget - Making a Column editable.
    By Preeteesh in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2007, 12:02
  5. using the example of simple tree model
    By krishna.bv in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2006, 12:28

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.