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

List:       kde-commits
Subject:    [kcompletion] /: KComboBox: Reuse the existing completion object on new line edit
From:       Milian Wolff <null () kde ! org>
Date:       2017-11-30 23:21:41
Message-ID: E1eKY9F-0001On-5g () code ! kde ! org
[Download RAW message or body]

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_unittest.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 = testCombo.completionObject();
+        QVERIFY(completion);
+        testCombo.setEditable(true);
+        auto lineEdit = qobject_cast<KLineEdit*>(testCombo.lineEdit());
+        QVERIFY(lineEdit);
+        QVERIFY(lineEdit->compObj());
+        QCOMPARE(lineEdit->compObj(), completion);
+        QCOMPARE(testCombo.completionObject(), completion);
+    }
+
     void testSelectionResetOnReturn()
     {
         // void QComboBoxPrivate::_q_returnPressed() calls lineEdit->deselect()
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 = kedit;
     }
 
+    // reuse an existing completion object, if it was configured already
+    auto completion = compObj();
+
     QComboBox::setLineEdit(edit);
     d->klineEdit = qobject_cast<KLineEdit *>(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()));

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

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