diff options
| author | Olga Radko <olya_r@tut.by> | 2018-08-09 16:50:03 +0300 |
|---|---|---|
| committer | Olga Radko <olya_r@tut.by> | 2018-09-06 05:56:18 +0000 |
| commit | c88305b68d228a60fa302afb627b6887ece7a110 (patch) | |
| tree | bd7937c3b8f7af7ed38e9e99bea1d4ddc138aa4c | |
| parent | 028727c20ca43f1a56bad010354837e238e30024 (diff) | |
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 <v.ronin@yahoo.it>
Reviewed-by: David Faure <david.faure@kdab.com>
| -rw-r--r-- | tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp | 53 | ||||
| -rw-r--r-- | tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h | 2 |
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp index 646f96c3a16..82cd26971b7 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 <QtCore/QCoreApplication> #include <QtGui/QStandardItem> +#include <QtWidgets/QComboBox> #include <QtWidgets/QTreeView> #include <QtWidgets/QTableView> @@ -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<QString>("pattern"); + QTest::addColumn<QStringList>("initial"); + QTest::addColumn<QString>("newitem"); + QTest::addColumn<QStringList>("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<QStringList>("initial"); diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h index 4ea5e8fb6a6..82d4b7344e6 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(); |
