Results 1 to 7 of 7

Thread: BeginRemoveRows, endRemoveRows - removing not all items defined

  1. #1
    Join Date
    Feb 2016
    Posts
    3
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default BeginRemoveRows, endRemoveRows - removing not all items defined

    Hi all,
    I have a question regarding beginRemoveRows..

    Here is some let's say code:
    ...
    beginRemoveRows(parent, startRow, endRow);

    for(..)
    {
    .. start removing items
    .. if user clicks on cancel -> break;
    }

    endRemoveRows();

    And question is: if it is correct code how to work with beginRemoveRow and endRemoveRow when to allow user to cancel an operation -> meaning not all rows which were anounced to model that they are going to be removed, will be actually removed...

    Could have such a code some downfalls?

    Thanks for answers in advance!
    Last edited by aidush; 25th February 2016 at 20:31.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: BeginRemoveRows, endRemoveRows - removing not all items defined

    Quote Originally Posted by aidush View Post
    Hi all,
    I have a question regarding beginRemoveRows..

    Here is some let's say code:
    ...
    model->beginRemoveRows(parent, startRow, endRow);
    That's not possible, beginRemoveRows() is protected.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Posts
    3
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: BeginRemoveRows, endRemoveRows - removing not all items defined

    thanks for answer,
    ok then I subclass model and then I can do such calls. What interests me is what happens if less items are removed than defined in beginRemoveRows(code in my first post edited to avoid confusion).

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: BeginRemoveRows, endRemoveRows - removing not all items defined

    So you mean you have a method that is called by a user action, that then calls beginRemoveRows(), then exits before completing?
    And then, sometime later you call a method that then calls endRemoveRows().

    Any specific reason you would not just remove all the rows?

    Cheers,
    _

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: BeginRemoveRows, endRemoveRows - removing not all items defined

    So you mean you have a method that is called by a user action, that then calls beginRemoveRows(), then exits before completing?
    And then, sometime later you call a method that then calls endRemoveRows().
    I think what the OP means is that suppose you call beginRemoveRows() and specify the range to be removed. While you are in the process of doing that, the loop removing the rows gets interrupted (maybe the loop is checking for a click on a Cancel button), and then endRemoveRows() is called. You've lied about how many rows were actually removed - fewer than you said.

    What happens in that case? Do views get garbaged up or does the normal update mechanism realize the lie and update correctly?

    I suppose what I would do in this case is call endRemoveRows(), but then immediately call a begin / endModelReset() pair to ensure the entire view gets updated.

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

    aidush (26th February 2016)

  7. #6
    Join Date
    Feb 2016
    Posts
    3
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: BeginRemoveRows, endRemoveRows - removing not all items defined

    Any specific reason you would not just remove all the rows?
    Removing items is time-demanding operation which lasts really long time if there are few hundreds items about to be removed so I want to give user option to stop it. In my implementation I do also some stuff on my own which prolongs this time.

    d_stranz got my point.
    Last edited by aidush; 26th February 2016 at 07:41.

  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: BeginRemoveRows, endRemoveRows - removing not all items defined

    Quote Originally Posted by aidush View Post
    Removing items is time-demanding operation which lasts really long time if there are few hundreds items about to be removed so I want to give user option to stop it. In my implementation I do also some stuff on my own which prolongs this time.
    I think it is important to keep in mind that the model is only the interface between data and views.
    These methods are for communicating between model and its views.

    Lets take for example a model that presents values of remote files, e.g. a view on a file server or email on a mail server.

    Invoking a delete operation is will take time, but there are lot of different ways of doing that.

    The model could tell the views that it removes all rows, remember which rows it no longer shows and reset (or reinsert) if the operation is interrupted.

    It could also change the properties of all items that are about to be deleted and issue row removal for each that has actually been removed.
    I have an email client that does that. It displays about-to-be-deleted emails with strike-through text and removes them when they got deleted.

    It could also just iusse row removal notifications for each items that the data source has actually begun deleting.
    I have a file manager that stops displaying a file when it has issued the delete on that file.

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    aidush (26th February 2016)

Similar Threads

  1. Replies: 0
    Last Post: 4th January 2014, 02:15
  2. Replies: 1
    Last Post: 23rd September 2010, 05:45
  3. QAbstractItemModel::beginRemoveRows/endRemoveRows
    By SiS-Shadowman in forum Qt Programming
    Replies: 0
    Last Post: 12th July 2010, 08:56
  4. Removing all items QListView
    By vcp in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2009, 18:55
  5. removing model Items
    By gyre in forum Newbie
    Replies: 2
    Last Post: 25th November 2007, 20:10

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.