Git commit cf2f5c72d9f3f76841afd78809f046abcb7cf835 by Milian Wolff. Committed on 30/11/2017 at 23:17. Pushed by mwolff into branch 'master'. KComboBox: Reuse the existing completion object on new line edit Summary: When a KComboBox was created and a completion object configured on it, that setting was lost once the combo box was set to be editable. To support this workflow and make the API easier to use, we now keep the previous completion object alive and set it on the new line edit. Subscribers: dfaure, #frameworks Tags: #frameworks Differential Revision: https://phabricator.kde.org/D7966 M +15 -0 autotests/kcombobox_unittest.cpp M +7 -0 src/kcombobox.cpp https://commits.kde.org/kcompletion/cf2f5c72d9f3f76841afd78809f046abcb7cf835 diff --git a/autotests/kcombobox_unittest.cpp b/autotests/kcombobox_unittes= t.cpp index 20167b8..0804c75 100644 --- a/autotests/kcombobox_unittest.cpp +++ b/autotests/kcombobox_unittest.cpp @@ -132,6 +132,21 @@ private Q_SLOTS: delete testCombo; // not needed anymore } = + void testLineEditCompletion() + { + // Test for KCombo's KLineEdit inheriting the completion object of= the parent + KTestComboBox testCombo(false, nullptr); + QVERIFY(!testCombo.lineEdit()); + auto completion =3D testCombo.completionObject(); + QVERIFY(completion); + testCombo.setEditable(true); + auto lineEdit =3D qobject_cast(testCombo.lineEdit()); + QVERIFY(lineEdit); + QVERIFY(lineEdit->compObj()); + QCOMPARE(lineEdit->compObj(), completion); + QCOMPARE(testCombo.completionObject(), completion); + } + void testSelectionResetOnReturn() { // void QComboBoxPrivate::_q_returnPressed() calls lineEdit->desel= ect() diff --git a/src/kcombobox.cpp b/src/kcombobox.cpp index 22a3281..99ebbc8 100644 --- a/src/kcombobox.cpp +++ b/src/kcombobox.cpp @@ -311,10 +311,17 @@ void KComboBox::setLineEdit(QLineEdit *edit) edit =3D kedit; } = + // reuse an existing completion object, if it was configured already + auto completion =3D compObj(); + QComboBox::setLineEdit(edit); d->klineEdit =3D qobject_cast(edit); setDelegate(d->klineEdit); = + if (completion && d->klineEdit) { + d->klineEdit->setCompletionObject(completion); + } + // Connect the returnPressed signal for both Q[K]LineEdits' if (edit) { connect(edit, SIGNAL(returnPressed()), SIGNAL(returnPressed()));