[Development] QML and QAbstractListModel

Bache-Wiig Jens Jens.Bache-Wiig at digia.com
Fri Jan 11 10:59:23 CET 2013


On Jan 10, 2013, at 5:46 PM, Alberto Mardegan <mardy at users.sourceforge.net> wrote:

> Hi all!
>   I'd like to make C++ models more usable from QML; in the net there 
> are several blog posts illustrating how to achieve that, but IMHO it 
> would be better if at least some of these handy features were in 
> QAbstractListModel itself:
> 
> - "count" property
> - "get(index)" invocable method, returning a QVariantMap mapping all the 
> roles to their data for the specified index

+1 from me. That would clean up a lot of the ugly special casing we have to deal with whenever models are provided to components.

> Also, though not very often requested, we could add:
> - "remove(index)" which just calls QAbstractItemModel::removeRow()
> - "QList<QVariant> items(const QString &role)", which returns the data 
> for the role "role" for all items.
> 
> The implementation for the above is fairly trivial, so I wonder if 
> there's some other reasons why it hasn't been done or if it's just that 
> no one did and a patch is welcome.

I would suspect it the latter and we just assumed there was a philosophy behind it. Another possibly low hanging fruit is to add some convenience for sorting models. But the model implementation differences make straight forward use of QSortFilterProxyModel problematic.

Jens


More information about the Development mailing list