Why is flags() in model, not in view?
-
With Itemflags you can set items editable, selectable, checkable, etc. When working in a model/view structure, why are these flags set in the model?
To me they seem more like properties of the view.
Let's say you have one model with two views, and in one view you want the items to be editable and not in the other.
Wouldn't it make much more sense that you could set that in the views? -
No, the model knows if an item should be editable or if the use should be able to change the check state or whatever. Use QIdentityProxyModel or similar to modify the data of a model without changing the base model.
-
@Christian-Ehrlicher said in Why is flags() in model, not in view?:
No, the model knows if an item should be editable
I understand that's how it is in qt.
I find this very counterintuitive, and usually that means that I'm not seeing the bigger picture. I'm asking for that bigger picture.In classic MVC structure, the user interacts with the controller. In qt the view and the controller are combined, so you would expect things that modify user interaction to be properties of the view.
What's the logic behind the flags being set in the model? What would be the downside of setting the flags in the view?
-
The view only displays data, flags() is a property on how the data is displayed so it has nothing to do in the view.
-
Hi,
You can put several views on top of the same model. With flags in the view you would lose the consistency through these views.
-
If the model says an item cannot be edited then no view can edit it. The model may do this because the value being presented is coming from a source that cannot be written to (e.g. a sensor of some sort), or is derived in some way (e.g. presenting area derived from editable length and width values).
A view can choose to disallow editing of items the model says can be edited (by providing no edit trigger), but it cannot do the opposite. Each view is independent, so one can edit where another may not.
If you need to restrict editing of individual items that the base model says can be edited (or other fine grained tweaks) then you can us QIdentityProxyModel as @Christian-Ehrlicher pointed out.