Micro-optimize QAbstractItemModel::setItemData
If b becomes false, we won't call setData ever again. Just bail out the loop early and return in that case. Change-Id: I4b0ed7e21546d686bc3f785209a314a8bed08471 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>bb10
parent
d1b099c3e3
commit
a52a3b2aa4
|
|
@ -1898,10 +1898,17 @@ bool QAbstractItemModel::clearItemData(const QModelIndex &index)
|
|||
*/
|
||||
bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)
|
||||
{
|
||||
bool b = true;
|
||||
for (QMap<int, QVariant>::ConstIterator it = roles.begin(); it != roles.end(); ++it)
|
||||
b = b && setData(index, it.value(), it.key());
|
||||
return b;
|
||||
// ### Qt 6: Consider change the semantics of this function,
|
||||
// or deprecating/removing it altogether.
|
||||
//
|
||||
// For instance, it should try setting *all* the data
|
||||
// in \a roles, and not bail out at the first setData that returns
|
||||
// false. It should also have a transactional approach.
|
||||
for (auto it = roles.begin(), e = roles.end(); it != e; ++it) {
|
||||
if (!setData(index, it.value(), it.key()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
Loading…
Reference in New Issue