From kde-commits Thu Nov 30 23:21:41 2017 From: Milian Wolff Date: Thu, 30 Nov 2017 23:21:41 +0000 To: kde-commits Subject: [kcompletion] /: KComboBox: Return early when setting editable to previous value Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=151208411216140 Git commit 11cba47b8718eee3c7f8506dc29f1e6466d534d1 by Milian Wolff. Committed on 30/11/2017 at 23:17. Pushed by mwolff into branch 'master'. KComboBox: Return early when setting editable to previous value Summary: Instead of creating a new line edit, keep the previous one intact. This ensures we don't set a new line edit for code such as the following: KComboBox combo(/* rw =3D */ true); combo.setEditable(true); Subscribers: #frameworks Tags: #frameworks Differential Revision: https://phabricator.kde.org/D7967 M +4 -0 autotests/kcombobox_unittest.cpp M +4 -0 src/kcombobox.cpp https://commits.kde.org/kcompletion/11cba47b8718eee3c7f8506dc29f1e6466d534d1 diff --git a/autotests/kcombobox_unittest.cpp b/autotests/kcombobox_unittes= t.cpp index 0804c75..898b3e5 100644 --- a/autotests/kcombobox_unittest.cpp +++ b/autotests/kcombobox_unittest.cpp @@ -45,6 +45,10 @@ private: w.addItem(QStringLiteral("Hello world")); QVERIFY(w.lineEdit()); QVERIFY(qobject_cast(w.lineEdit())); + auto lineEdit =3D w.lineEdit(); + // set editable again, don't recreate the line edit + w.setEditable(true); + QCOMPARE(w.lineEdit(), lineEdit); // KLineEdit signals QSignalSpy qReturnPressedSpy(w.lineEdit(), SIGNAL(returnPressed())= ); QSignalSpy kReturnPressedSpy(w.lineEdit(), SIGNAL(returnPressed(QS= tring))); diff --git a/src/kcombobox.cpp b/src/kcombobox.cpp index 99ebbc8..1c5d74f 100644 --- a/src/kcombobox.cpp +++ b/src/kcombobox.cpp @@ -389,6 +389,10 @@ void KComboBox::setCurrentItem(const QString &item, bo= ol insert, int index) = void KComboBox::setEditable(bool editable) { + if (editable =3D=3D isEditable()) { + return; + } + if (editable) { // Create a KLineEdit instead of a QLineEdit // Compared to QComboBox::setEditable, we might be missing the SH_= ComboBox_Popup code though...