Results 1 to 2 of 2

Thread: Editable Models

  1. #1
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Editable Models

    It says that editable models should implement methods like insertRows(), etc.. But what if items can only be appended to the internal data structure and not inserted?

    Can I implement custom functions to add items and not implement the normal ones, ir is there some other workaround?

  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 Models

    Quote Originally Posted by MTK358 View Post
    But what if items can only be appended to the internal data structure and not inserted?
    Appending is equivalent to inserting at the end. You can deny insertion that is not at the end of the model, if you want by returning false from QAbstractItemModel::insertRows().

    Can I implement custom functions to add items and not implement the normal ones
    Yes. Just remember to call beginInsertRows() and endInsertRows(). By not reimplementing the regular methods you will prevent views and proxy model from inserting data into your model.

    In general I would advise to reimplement insertRows() but you can also implement your own method (for convinience) that would call insertRows() to do its job. By "behaving well" (i.e. keeping the standards) you make your classes more versatile and reusable which is a good thing in general.
    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. The following user says thank you to wysota for this useful post:

    MTK358 (9th September 2010)

Similar Threads

  1. Models and Delegates
    By bgeller in forum Newbie
    Replies: 13
    Last Post: 4th March 2010, 04:46
  2. sql models
    By damiano19902 in forum Newbie
    Replies: 1
    Last Post: 4th June 2009, 07:18
  3. Proxy models and slection models
    By amunitz in forum The Model-View Framework
    Replies: 1
    Last Post: 23rd September 2008, 14:35
  4. Models in cascade
    By thrantir in forum Qt Programming
    Replies: 6
    Last Post: 18th January 2007, 14:05

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.