diff options
author | Volker Krause <volker.krause@kdab.com> | 2013-05-04 18:26:25 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-06 22:24:04 +0200 |
commit | bb00ac8d1251be3e703cc09e5fb2f100f24b398b (patch) | |
tree | 170de83ede70b06b9df300412231cf18f47e2857 | |
parent | 66ebc3e079d71a22e6fef5550fa2b00ff4a9cbe9 (diff) |
Don't bypass overwritten [set]data() methods in the proxy.
By calling itemData() of the source model directly, the result cannot
contain data provided by the proxy model itself. The base class
implementation however will call data() on the proxy instead.
Cherry-picked from qtbase/96e3c2bcbfedc8b5cb8fc099229a02a1fa335c21.
Change-Id: I7e8b65ab045382089c577d9832edc1555b71419e
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
-rw-r--r-- | src/gui/itemviews/qabstractproxymodel.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp | 26 |
2 files changed, 28 insertions, 4 deletions
diff --git a/src/gui/itemviews/qabstractproxymodel.cpp b/src/gui/itemviews/qabstractproxymodel.cpp index 7acc0bdb9f..2143a8f8f3 100644 --- a/src/gui/itemviews/qabstractproxymodel.cpp +++ b/src/gui/itemviews/qabstractproxymodel.cpp @@ -248,8 +248,7 @@ QVariant QAbstractProxyModel::headerData(int section, Qt::Orientation orientatio */ QMap<int, QVariant> QAbstractProxyModel::itemData(const QModelIndex &proxyIndex) const { - Q_D(const QAbstractProxyModel); - return d->model->itemData(mapToSource(proxyIndex)); + return QAbstractItemModel::itemData(proxyIndex); } /*! @@ -275,8 +274,7 @@ bool QAbstractProxyModel::setData(const QModelIndex &index, const QVariant &valu */ bool QAbstractProxyModel::setItemData(const QModelIndex &index, const QMap< int, QVariant >& roles) { - Q_D(QAbstractProxyModel); - return d->model->setItemData(mapToSource(index), roles); + return QAbstractItemModel::setItemData(index, roles); } /*! diff --git a/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp b/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp index cc4603780c..80a8577746 100644 --- a/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp +++ b/tests/auto/qidentityproxymodel/tst_qidentityproxymodel.cpp @@ -75,6 +75,8 @@ private slots: void moveRows(); void reset(); + void itemData(); + protected: void verifyIdentity(QAbstractItemModel *model, const QModelIndex &parent = QModelIndex()); @@ -330,5 +332,29 @@ void tst_QIdentityProxyModel::reset() m_proxy->setSourceModel(0); } +class AppendStringProxy : public QIdentityProxyModel +{ +public: + QVariant data(const QModelIndex &index, int role) const + { + const QVariant result = sourceModel()->data(index, role); + if (role != Qt::DisplayRole) + return result; + return result.toString() + "_appended"; + } +}; + +void tst_QIdentityProxyModel::itemData() +{ + QStringListModel model(QStringList() << "Monday" << "Tuesday" << "Wednesday"); + AppendStringProxy proxy; + proxy.setSourceModel(&model); + + const QModelIndex topIndex = proxy.index(0, 0); + QCOMPARE(topIndex.data(Qt::DisplayRole).toString(), QString::fromLatin1("Monday_appended")); + QCOMPARE(proxy.data(topIndex, Qt::DisplayRole).toString(), QString::fromLatin1("Monday_appended")); + QCOMPARE(proxy.itemData(topIndex).value(Qt::DisplayRole).toString(), QString::fromLatin1("Monday_appended")); +} + QTEST_MAIN(tst_QIdentityProxyModel) #include "tst_qidentityproxymodel.moc" |