diff options
author | Mark Brand <mabrand@mabrand.nl> | 2012-10-13 13:41:30 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-26 15:24:00 +0200 |
commit | 84787d82ee9369b2a83c5b0568ee62ab602a5528 (patch) | |
tree | 56ba0976b2a8acc32c334d2918dd150349ffbfc2 /tests/auto/widgets/widgets | |
parent | 4fbdb969fb4e446eab01f27eb2c880f8d6cb9106 (diff) |
QComboBox: fix use in QDataWidgetMapper/QItemDelegate
QItemDelegate and QDataWidgetMapper use the WRITE method on the USER
property to set a value in a widget. This did not work for QComboBox
whose USER property currentText lacked a WRITE method.
This change adds the missing setter and flags it as the WRITE method.
The setter setCurrentText() simply calls setEditText() if the combo
box is editable. Otherwise, if there is a matching text in the list,
currentIndex is set to the corresponding index.
Test included.
Follow-up to 816c5540179362500dfc175b77f05abf3ef25233 which restored
currentText as the USER property.
Task-number: QTBUG-26501
Change-Id: I5f2f999e60b09728ca03ead4e28fe36d1f3ee189
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto/widgets/widgets')
-rw-r--r-- | tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 11e9a9d82f..df0eb89682 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -121,6 +121,8 @@ private slots: void modelDeleted(); void setMaxCount(); void setCurrentIndex(); + void setCurrentText_data(); + void setCurrentText(); void convenienceViews(); void findText_data(); void findText(); @@ -1355,6 +1357,57 @@ void tst_QComboBox::setCurrentIndex() QCOMPARE(testWidget->currentText(), QString("foo")); } +void tst_QComboBox::setCurrentText_data() +{ + QTest::addColumn<bool>("editable"); + QTest::newRow("editable") << true; + QTest::newRow("not editable") << false; +} + +void tst_QComboBox::setCurrentText() +{ + QFETCH(bool, editable); + + QCOMPARE(testWidget->count(), 0); + testWidget->addItems(QStringList() << "foo" << "bar"); + QCOMPARE(testWidget->count(), 2); + + testWidget->setEditable(editable); + testWidget->setCurrentIndex(0); + QCOMPARE(testWidget->currentIndex(), 0); + + // effect on currentText and currentIndex + // currentIndex not changed if editable + QCOMPARE(testWidget->currentText(), QString("foo")); + testWidget->setCurrentText(QString("bar")); + QCOMPARE(testWidget->currentText(), QString("bar")); + if (editable) + QCOMPARE(testWidget->currentIndex(), 0); + else + QCOMPARE(testWidget->currentIndex(), 1); + + testWidget->setCurrentText(QString("foo")); + QCOMPARE(testWidget->currentIndex(), 0); + QCOMPARE(testWidget->currentText(), QString("foo")); + + // effect of text not found in list + testWidget->setCurrentText(QString("qt")); + QCOMPARE(testWidget->currentIndex(), 0); + if (editable) + QCOMPARE(testWidget->currentText(), QString("qt")); + else + QCOMPARE(testWidget->currentText(), QString("foo")); + +#ifndef QT_NO_PROPERTIES + // verify WRITE for currentText property + testWidget->setCurrentIndex(0); + const QByteArray n("currentText"); + QCOMPARE(testWidget->property(n).toString(), QString("foo")); + testWidget->setProperty(n, QString("bar")); + QCOMPARE(testWidget->property(n).toString(), QString("bar")); +#endif +} + void tst_QComboBox::editTextChanged() { QCOMPARE(testWidget->count(), 0); |