[Qt5-feedback] Adding better data access method to QAbstractItemModel?
Stephen Kelly
steveire at gmail.com
Mon Jul 11 14:43:41 CEST 2011
Hi,
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.
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.
I also want to change the dataChanged signal to
dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
QSet<int> &roles = QSet<int>());
so that it actaully tells you what roles have changed. The extra roles
argument can be safely ignored, and a signal emission with an empty roles
set has the same meaning as dataChanged has today.
That means this is source compatible for the emitter but not the receiver,
ie,
emit dataChanged(foo, bar);
still works, but
connect(model, SIGNAL(dataChanged(QMI,QMI)), SLOT(onDataChanged(QMI,QMI));
Needs to be changed to at least:
connect(model, SIGNAL(dataChanged(QMI,QMI,QSet<int>)),
SLOT(onDataChanged(QMI,QMI));
The (source compatible) alternative would be to add a roleDataChanged signal
with the signature I proposed instead of changing dataChanged (and possibly
deprecating dataChanged).
What are your thoughts? Are small source incompatibilities like that
acceptible?
Thanks,
Steve.
More information about the Qt5-feedback
mailing list