Results 1 to 6 of 6

Thread: Editable Tree Model

  1. #1
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Editable Tree Model

    I'm currently trying to add editing capabilities to the Simple Tree Model Example and it isn't going too well. Before I put my malfunctioning code up here, I'd like to ask whether somebody knows full featured Tree Model Example.

    Edit: I'm specifically looking for a way to add/remove nodes and edit their contents. I have read the Editable Model doc, but I'm still not quite sure how to implement those methods for a tree-like data structure...
    Last edited by kloffy; 9th October 2007 at 23:32.

  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: Editable Tree Model

    You can use QStandardItemModel which supports tree structures and is editable. If you want to implement edit capabilities to the simple tree model, you'll have to implement insertRow() and removeRow() methods and make them add/remove items from the internal QList. Additionally you'll have to implement setData() to operate on the list changing its contents and make flags() return ItemIsEditable (among other values) for items you want editable.

  3. #3
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Editable Tree Model

    I'd rather not use QStandardItemModel because I already have my own tree implementation. Unless I'm missing something, using QStandardItemModel would mean that I'd have to take all the nodes from my tree and put them into QStandardItems. That would result in two different tree representations of the same data.
    I'm aware of the methods I need to implement, but obviously I must be doing something wrong. Anyways, I'll give it another shot tomorrow and post my results here...

  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: Editable Tree Model

    Yes, you are right. If you already have a tree structure, it'd be a redundancy. If you post your code here, we'll try to help you (just please attach it instead of embedding if it's more than 50 lines of code).

  5. #5
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Editable Tree Model

    Ok, I did get it to work. Heres the editable version of the simple tree model.
    Attached Files Attached Files

  6. #6
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Editable Tree Model

    And here's the application to run it.

    Edit: I would not advise on using this code as is. I'm just happy that the basic functionality is there and I have a pretty good understanding of how to implement an editable tree model now. If I have some free time I'll properly implement the necessary methods (e.g. to support multiple columns).
    Attached Files Attached Files
    Last edited by kloffy; 10th October 2007 at 16:32.

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  2. Coin3d + Qt: SIGLNALs and SLOTs
    By vonCZ in forum Newbie
    Replies: 26
    Last Post: 15th May 2009, 07:34
  3. Model Choices review/questions
    By ucntcme in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2007, 21:57
  4. Optimizing filterAcceptsRow() to filter a tree
    By vfernandez in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2007, 12:50
  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.