[Qt5-feedback] Adding better data access method to QAbstractItemModel?

Sean Harmer sh at theharmers.co.uk
Mon Jul 11 15:19:12 CEST 2011


On Monday 11 July 2011 14:43:41 Stephen Kelly wrote:
> Currently in the modelview API there are a lot of individual calls to the
> data() method. These can get expensive when proxy models are added to the
> mix.

This is especially true when plotting or charting models since they often need 
to show all of the data in the model at once. So I would like to see something 
similar added.

> I'm thinking of adding a method like this to QAbstractItemModel:
> 
> virtual QVariantist rangeData(const QModelIndex &topLeft, const QModelIndex
> &bottomRight, const QList<int> &roles) const;
> 
> with a default implementation like
> 
> {
>   QVariantList list;
>   for (int row = topLeft.row(); row <= bottomRight.row(); ++row)
>     for (int col = topLeft.column(); col <= bottomRight.column() ++col)
>       foreach (int role, roles)
>         list << index(row, column, topLeft.parent()).data(role);
>   return list;
> }
> 
> A model implementation and a proxy implementation can both do better of
> course, which is the whole idea. This change is source incompatible, but the
> itemData method currently in QAIM should maybe be deprecated.

Why is it source incompatible if it is a new function? Does this new function 
not just provide an alternative lighter-weight way of getting at contiguous 
blocks of data? Or am I missing something blindingly obvious (quite possible).

Cheers,

Sean



More information about the Qt5-feedback mailing list