diff options
-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 7acc0bd..2143a8f 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 cc46037..80a8577 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" |