QAbstractItemModel: no flagsChanged( const QModelIndex& index ) notification signal
What functionality QAbstractItemModel offers:
The only way to tell model's views to lookup the flags on demand and apply them both visually and functionally is to fire rowsRemoved + rowsInserted or modelReset. Emitting dataChanged makes the views reapply the model's flags at the given QModelIndex-es only functionally but not visually. So, let's suppose that the enablence of an item at a given QModelIndex depends on the value of the Qt::CheckStateRole of the same item (for instance) - checked = enabled, unchecked = disabled. Unchecking the checkbox at that QModelIndex and firing only dataChanged at that index will make the item functionally disabled but will retain its visual state - the same as it was when the item was enabled.
What I think is that there should be at least flagsChanged signal without setter, so that it is possible to notify the views that flags have changed.
Does anyone knows how to notify flags changed in a more correct manner, so that views refresh their visual state as well?
(duplicate topic: http://qt-project.org/forums/viewthread/18504)
bq. So, let’s suppose that the enablence of an item at a given QModelIndex depends on the value of the Qt::CheckStateRole of the same item
imho this should be wrong, the enablance of an item(and in general its functionality) depends on the flags, only, in this case on Qt::ItemIsEnabled ... it does not depend on Qt::CheckStateRole which controls exactly the visual box checking by item's internal check states; so no enabling/disabling code by changing flags should be put in setData()for this role! rather the same code used in setData() for changing check states must be used in flags() to combine flags
Probably, I haven't explained the example scenario correctly.
Let's suppose that we have a table that lists countries you have visited. The table would have two columns:
- country name + checkbox to denote if you have visited the country
- the number of visits - editable, so that you could set the times you have visited the given country. The requirement here is that this table cell should be disabled if the cbeckbox of column 1 is unchecked and enabled if the checkbox is checked.
How would you acbieve this behavior?