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>
bb10
parent
028727c20c
commit
c88305b68d
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue