Make QAbstractProxyModel itemData() behave like data()
QAbstractProxyModel::itemData/setItemData should behave just like data()/setData() instead of calling the QAbstractItemModel implementation. Before this change the QAbstractProxyModel implementation calls its the QAbstractItemModel implementation, which ends up calling data()/setData() in a loop bypassing the convenience of itemData/setItemData. [ChangeLog][QtCore][QAbstractProxyModel] The itemData() and setItemData() functions will now call the respective implementations in the source model (after mapping the index to a source index), matching what data() and setData() already did. Before, the proxy model simply called the default implementations of itemData()/setItemData() in its own base class (QAbstractItemModel). Change-Id: I9e680d355f44fa130660dd7e1c8ac37484c1566e Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
99644a9e94
commit
c27d2a57a4
@ -268,7 +268,8 @@ QVariant QAbstractProxyModel::headerData(int section, Qt::Orientation orientatio
|
||||
*/
|
||||
QMap<int, QVariant> QAbstractProxyModel::itemData(const QModelIndex &proxyIndex) const
|
||||
{
|
||||
return QAbstractItemModel::itemData(proxyIndex);
|
||||
Q_D(const QAbstractProxyModel);
|
||||
return d->model->itemData(mapToSource(proxyIndex));
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -294,7 +295,8 @@ bool QAbstractProxyModel::setData(const QModelIndex &index, const QVariant &valu
|
||||
*/
|
||||
bool QAbstractProxyModel::setItemData(const QModelIndex &index, const QMap< int, QVariant >& roles)
|
||||
{
|
||||
return QAbstractItemModel::setItemData(index, roles);
|
||||
Q_D(QAbstractProxyModel);
|
||||
return d->model->setItemData(mapToSource(index), roles);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -404,8 +404,17 @@ public:
|
||||
const QVariant result = QIdentityProxyModel::data(index, role);
|
||||
if (role != Qt::DisplayRole)
|
||||
return result;
|
||||
return result.toString() + "_appended";
|
||||
return result.toString() + QLatin1String("_appended");
|
||||
}
|
||||
QMap<int, QVariant> itemData(const QModelIndex &index) const override
|
||||
{
|
||||
QMap<int, QVariant> result = QIdentityProxyModel::itemData(index);
|
||||
auto displayIter = result.find(Qt::DisplayRole);
|
||||
if (displayIter != result.end())
|
||||
displayIter.value() = displayIter.value().toString() + QLatin1String("_appended");
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void tst_QIdentityProxyModel::itemData()
|
||||
|
Loading…
Reference in New Issue
Block a user