QAbstractItemModel reset Persistent Index
Hi,
How do I reset a persistent Index List?
Let's say I signal "layoutAboutToBeChanged()" then I update my data and check if the current persistent index is still there. If it's not there, I would like to clear the persistent index. Is there a way to do this?
Thank you
Re: QAbstractItemModel reset Persistent Index
You can probably assign an invalid (null) model index to it. Although layoutAboutToBeChanged() shouldn't invalidate any indexes as no data gets added or removed, only its position may change.
Re: QAbstractItemModel reset Persistent Index
I'm almost sure that I'm using the layoutToBeChanged() in a wrong way. To clarify a bit what I want to do is: I have a table view that shows files on a server, which the client can assign to a certain item or folder. Once the file gets assigned, it gets removed from the table view (hence, the persistent index would be set back to a non selection).
Changing the persistent index to an empty model index list crashes the Application.
Thank you.
Re: QAbstractItemModel reset Persistent Index
Why are you using persistent indexes in the first place? In 99% of the cases you shouldn't need them at all.
Re: QAbstractItemModel reset Persistent Index
But how do I keep a view from changing it's selection after updating it's data? I'm aware that the selection on a view doesn't move from it's row or column, but sometimes after updating data the order on the view gets resorted.
Re: QAbstractItemModel reset Persistent Index
Quote:
Originally Posted by
larcho
But how do I keep a view from changing it's selection after updating it's data?
The view will take care of that if you emit proper signals from the model (i.e. dataChanged(), rowsInserted(), rowsRemoved(), etc.). It takes a bit of effort to do it but you just have to do it.
Re: QAbstractItemModel reset Persistent Index
I'll give a look into that. Thank you.
Re: QAbstractItemModel reset Persistent Index
One more thing... what you might try is to connect a slot to the layoutAboutToBeChanged() signal and use QAbstractItemModel::changePersistentIndex() to update persistent indexes manually if you are able to determine new positions of each of the persistent indexes kept by the model.
Re: QAbstractItemModel reset Persistent Index
I did your first approach and it worked fine. Working with dataChanged(), insertRow() and removeRow() did the trick. As you said, it´s a bit more work, but the end result is great.
Thank you.