From 03ac42cd8e453ae46dcb5400ca375035c2e1c3f1 Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 8 Nov 2023 12:24:46 +0100 Subject: [PATCH] Doc: QIdentityProxyModel::itemData() should be reimplemented too This is a "regression" (voluntary, known) from commit c27d2a57a441f9a1ce760e71635bd4c96882249d which changed QAbstractProxyModel::itemData() to call the source model's itemData(), so our data() reimplementation is no longer used. Of course this only matters if itemData() is actually called, which isn't the case in Qt itself. People will likely skip this if they don't care - but if itemData() is used in the project, then this shows how to reimplement it correctly. Change-Id: I3acea16c05d30d7526bac32fd6cce42b5ad4b617 Reviewed-by: Volker Hilsheimer (cherry picked from commit abc739600447af06befaca8ae616dd607b99b184) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit bbd868ff682c991bbd6cb88a9cf363e04871472b) --- .../code/src_gui_itemviews_qidentityproxymodel.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp b/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp index 52934b61592..4ef1891cdbf 100644 --- a/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp +++ b/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp @@ -17,10 +17,16 @@ class DateFormatProxyModel : public QIdentityProxyModel return QIdentityProxyModel::data(index, role); const QDateTime dateTime = sourceModel()->data(SourceClass::DateRole).toDateTime(); - return dateTime.toString(m_formatString); } + QMap itemData(const QModelIndex &proxyIndex) const override + { + QMap map = QIdentityProxyModel::itemData(proxyIndex); + map[Qt::DisplayRole] = data(proxyIndex); + return map; + } + private: QString m_formatString; };