Priority: Not Evaluated
Affects Version/s: 6.2.0 FF
Fix Version/s: None
Component/s: Core: Item Models
The issue title is a bit generic, but in a nutshell, there are situations inside Qt where a view/view-like class wants to add data to its underlying model.
QAbstractItemModel has no generic "addData" function.
Therefore, what view-like classes do is something like:
- call insertRow(s) as needed (note that this may fail, because a model may not want rows to be added this way)
- call setData() on the newly added rows to populate them (again this may, in theory, fail)
For instance, consider QComboBox::addItem, which ends up calling this stuff in qcombobox.cpp:
This isn't transitional, and if setData fails on the source model then one is left with a dummy row in the model.
But even without the problem of not being transational, this is simply broken for many other scenarios. For instance consider the case where one has
Model -> QSFPM -> QComboBox
The insertRow call succeeds, because QSFPM correctly propagates it to the underlying model. But
- if the newly inserted row is filtered out (because, say, it's empty, and QSFPM has a filter to exclude it) then the subsequent calls will return an invalid model index and setData wont' work;
- if QSFPM is sorting, this risks overwriting an unrelated index .
... QSFPM docs in fact warn about 2) and suggest to disable the dynamic sort filter property. But it's not easy to do when one isn't using QSFPM directly; QComboBox should be in charge of doing it. And even with a non-dynamic QSFPM, 1) still fails.
In a nutshell, it looks to me that we're missing some API to insert new rows, with data, and return the corresponding QModelIndex(es).