From c88305b68d228a60fa302afb627b6887ece7a110 Mon Sep 17 00:00:00 2001 From: Olga Radko Date: Thu, 9 Aug 2018 16:50:03 +0300 Subject: [PATCH] QSortFilterProxyModel: add test for inserting via a QComboBox This new test double-checks the bugfix for QSortFilterProxyModel::insertRows in commit 70ba75519d. Previously, when using QComboBox on top of QSortFilterProxyModel and calling QComboBox::addItem with row==rowCount(), an empty item was inserted in one place, and then another item was modified (instead of the inserted empty one). This test checks that the above bugfix indeed fixes the behavior of QComboBox::addItem when used in this manner. Task-number: QTBUG-69158 Change-Id: Id01345e0525694a57250c656222d626e2267aa8e Reviewed-by: Luca Beldi Reviewed-by: David Faure --- .../tst_qsortfilterproxymodel.cpp | 53 +++++++++++++++++++ .../tst_qsortfilterproxymodel.h | 2 + 2 files changed, 55 insertions(+) diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp index 646f96c3a1..82cd26971b 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -506,6 +507,58 @@ void tst_QSortFilterProxyModel::prependRow() QCOMPARE(proxy.rowCount(QModelIndex()), 1); //only the "root" item is there } +void tst_QSortFilterProxyModel::appendRowFromCombobox_data() +{ + QTest::addColumn("pattern"); + QTest::addColumn("initial"); + QTest::addColumn("newitem"); + QTest::addColumn("expected"); + + QTest::newRow("filter_out_second_last_item") + << "^[0-9]*$" + << (QStringList() << "a" << "1") + << "2" + << (QStringList() << "a" << "1" << "2"); + + QTest::newRow("filter_out_everything") + << "^c*$" + << (QStringList() << "a" << "b") + << "c" + << (QStringList() << "a" << "b" << "c"); + + QTest::newRow("no_filter") + << "" + << (QStringList() << "0" << "1") + << "2" + << (QStringList() << "0" << "1" << "2"); + + QTest::newRow("filter_out_last_item") + << "^[a-z]*$" + << (QStringList() << "a" << "1") + << "b" + << (QStringList() << "a" << "1" << "b"); +} + +void tst_QSortFilterProxyModel::appendRowFromCombobox() +{ + QFETCH(QString, pattern); + QFETCH(QStringList, initial); + QFETCH(QString, newitem); + QFETCH(QStringList, expected); + + QStringListModel model(initial); + + QSortFilterProxyModel proxy; + proxy.setSourceModel(&model); + proxy.setFilterRegExp(pattern); + + QComboBox comboBox; + comboBox.setModel(&proxy); + comboBox.addItem(newitem); + + QCOMPARE(model.stringList(), expected); +} + void tst_QSortFilterProxyModel::removeRows_data() { QTest::addColumn("initial"); diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h index 4ea5e8fb6a..82d4b7344e 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h @@ -72,6 +72,8 @@ private slots: void insertRows_data(); void insertRows(); void prependRow(); + void appendRowFromCombobox_data(); + void appendRowFromCombobox(); void removeRows_data(); void removeRows(); void removeColumns_data();