Unsolved Modifying data outside a Model and View
-
I have a custom Model class which contains a pointer to a vector held elsewhere, and a View associated with the Model.
Is it acceptable to modify (add, edit, delete, etc) the vector directly? I.e, not through the model or the view. If so, how would I notify the model that the data has been changed, or does it update automatically?
-
Hi,
Your model can't know of any changes to your vector unless you give an API to that vector that allows to get the information.
-
Would it be best to have all data changes (which affect the view) handled from within the model? What's the best practise with this sort of thing? If I do a sort on the model, will it also sort the vector?
-
See the documentation.
When the complete data changed (whyever this should happen) you can use layoutChanged() but it should be avoided. Use dataChanged() wherever possible.
Sorting has nothing to do with the QAbstractItemModel so no your data will not change. -
@Christian-Ehrlicher said in Modifying data outside a Model and View:
Sorting has nothing to do with the QAbstractItemModel so no your data will not change.
The documentation suggests that I can reimplement QAbstractItemModel::sort() to sort the data.
I need both the vector and the model sorted.
-
Why do you need to sort your data when you can simply use a QSortFilterProxyModel?
-
If I use QSortFilterProxyModel, will it sort the vector too?
-
No, it acts on top of the model it proxies.
-
So I would have to sort the vector manually then?
-
@EaccB said in Modifying data outside a Model and View:
So I would have to sort the vector manually then?
Again: use a QSortFilterProxyModel when you want to display the data sorted.