diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2014-12-03 18:08:51 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2014-12-07 20:51:08 +0100 |
commit | f96baeb75fc36a41d2b08f880536cee5a8041e79 (patch) | |
tree | e8348edffe77f8ef18253bb7c96fd2954b9d297c /tests/auto/corelib/itemmodels | |
parent | 9cb85ada8bc599bbc861371a5d2725c5fc5c73b1 (diff) |
QSortFilterProxyModel: honor the roles parameter of dataChanged
When the source model emits dataChanged, it may tell which roles
have been changed. That information was lost when using a
QSortFilterProxyModel -- the proxy simply dropped that argument
(meaning "all roles may have changed"). It's instead a good idea
to forward the roles argument, as it may minimize hits on the
proxy (on unchanged roles).
[ChangeLog][QtCore][QSortFilterProxyModel] QSortFilterProxyModel
now properly forwards the roles that have been changed when
the source model emits dataChanged().
Task-number: QTBUG-35440
Change-Id: Ifa5213866ba04dfd57d50b5fbd47638f2191eb8e
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests/auto/corelib/itemmodels')
-rw-r--r-- | tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index d05ed6c20f..d5f976ed64 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -96,6 +96,7 @@ private slots: void changeSourceData_data(); void changeSourceData(); void changeSourceDataKeepsStableSorting_qtbug1548(); + void changeSourceDataForwardsRoles_qtbug35440(); void sortFilterRole(); void selectionFilteredOut(); void match_data(); @@ -2084,6 +2085,37 @@ void tst_QSortFilterProxyModel::changeSourceDataKeepsStableSorting_qtbug1548() checkSortedTableModel(&model, rows); } +void tst_QSortFilterProxyModel::changeSourceDataForwardsRoles_qtbug35440() +{ + QStringList strings; + for (int i = 0; i < 100; ++i) + strings << QString::number(i); + + QStringListModel model(strings); + + QSortFilterProxyModel proxy; + proxy.setSourceModel(&model); + proxy.sort(0, Qt::AscendingOrder); + + QSignalSpy spy(&proxy, &QAbstractItemModel::dataChanged); + QVERIFY(spy.isValid()); + QCOMPARE(spy.length(), 0); + + QModelIndex index; + + index = model.index(0, 0); + QVERIFY(index.isValid()); + model.setData(index, QStringLiteral("teststring"), Qt::DisplayRole); + QCOMPARE(spy.length(), 1); + QCOMPARE(spy.at(0).at(2).value<QVector<int> >(), QVector<int>() << Qt::DisplayRole); + + index = model.index(1, 0); + QVERIFY(index.isValid()); + model.setData(index, QStringLiteral("teststring2"), Qt::EditRole); + QCOMPARE(spy.length(), 2); + QCOMPARE(spy.at(1).at(2).value<QVector<int> >(), QVector<int>() << Qt::EditRole); +} + void tst_QSortFilterProxyModel::sortFilterRole() { QStandardItemModel model; |