PDA

View Full Version : BeginRemoveRows, endRemoveRows - removing not all items defined



aidush
25th February 2016, 16:39
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!

anda_skoa
25th February 2016, 17:16
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,
_

aidush
25th February 2016, 20:31
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).

anda_skoa
25th February 2016, 22:12
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,
_

d_stranz
25th February 2016, 23:43
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.

aidush
26th February 2016, 07:37
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.

anda_skoa
26th February 2016, 08:27
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,
_