[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kcompletion] /: KComboBox: Return early when setting editable to previous value
From:       Milian Wolff <null () kde ! org>
Date:       2017-11-30 23:21:41
Message-ID: E1eKY9F-0001On-6U () code ! kde ! org
[Download RAW message or body]

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 = */ 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_unittest.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<KLineEdit *>(w.lineEdit()));
+        auto lineEdit = 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(QString)));
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, bool insert, int index)
 
 void KComboBox::setEditable(bool editable)
 {
+    if (editable == 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...
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic