[Development] QML and QAbstractListModel

Alan Alpert 416365416c at gmail.com
Mon Jan 14 16:48:18 CET 2013


On Mon, Jan 14, 2013 at 3:37 AM, Alberto Mardegan
<mardy at users.sourceforge.net> wrote:
> On 01/14/2013 11:37 AM, André Somers wrote:
> [...]
>> top of them. Note that you can also use a proxy to map a table model to
>> a list by mapping the data in columns to different roles. The base class
>> would not be a QListModel, but the data would be available from the
>> first column anyway. When using the proxy approach I suggest, that works
>> nicely. Your approach only works for models that derive from
>> QAbstractListModel directly.
>
> Very good point. Maybe this helper class could help expose more complex
> models to QML as a list model, by providing a sub-selection of the data.
> Something like:
>
> ============
> ItemModel {
>      id: itemModel
>      model: myModel
>      column: 4
> }
>
> ListView {
>      model: itemModel
> }
> ============
>
> where "myModel" could be a tabular QAbstractItemModel, and in
> "itemModel" we select the 4th column in order to create a list model.
> Though whether it's useful, it's another matter. :-)

In terms of what's useful, this change was originally inspired by
multiple people saying they augmented an actual list, not a tree or
table model, because they needed to right now. To properly fix all
QAIM usage in QML would be even better, but the last time we looked at
that was the ItemViewsNG project maybe two years ago. I'm still of the
opinion that the proper fix needs a new modelview framework - which
means it won't happen for quite a while. Perhaps it's worth adding a
couple simple methods (count and get specifically) now to ease the
pain of the QML users while they wait?

--
Alan Alpert



More information about the Development mailing list