diff --git a/autotests/klineedit_unittest.cpp b/autotests/klineedit_unittest.cpp --- a/autotests/klineedit_unittest.cpp +++ b/autotests/klineedit_unittest.cpp @@ -68,7 +68,7 @@ #endif QCOMPARE(textChangedSpy.count(), 1); QCOMPARE(textChangedSpy[0][0].toString(), w.text()); - QCOMPARE(textEditedSpy.count(), 1); + QCOMPARE(textEditedSpy.count(), 0); QVERIFY(!w.isModified()); #ifndef KCOMPLETION_NO_DEPRECATED userTextChangedSpy.clear(); @@ -76,6 +76,32 @@ textChangedSpy.clear(); textEditedSpy.clear(); + // calling clear should emit textChanged and userTextChanged, but not textEdited + w.clear(); + QCOMPARE(textChangedSpy.count(),1); + QCOMPARE(textEditedSpy.count(),0); +#ifndef KCOMPLETION_NO_DEPRECATED + QCOMPARE(userTextChangedSpy.count(),1); +#endif + + //if text box is already empty, calling clear() shouldn't emit + // any more signals + w.clear(); + QCOMPARE(textChangedSpy.count(),1); + QCOMPARE(textEditedSpy.count(),0); +#ifndef KCOMPLETION_NO_DEPRECATED + QCOMPARE(userTextChangedSpy.count(),1); +#endif + + + //set the text back for further tests below + w.setText("Hello worl"); +#ifndef KCOMPLETION_NO_DEPRECATED + userTextChangedSpy.clear(); +#endif + textChangedSpy.clear(); + textEditedSpy.clear(); + // typing emits all three signals QTest::keyClick(&w, Qt::Key_D); QCOMPARE(w.text(), QString::fromLatin1("Hello world")); @@ -85,7 +111,7 @@ #endif QCOMPARE(textChangedSpy.count(), 1); QCOMPARE(textChangedSpy[0][0].toString(), w.text()); - QCOMPARE(textEditedSpy.count(), 2); + QCOMPARE(textEditedSpy.count(), 1); QCOMPARE(textEditedSpy[0][0].toString(), w.text()); QVERIFY(w.isModified()); @@ -169,7 +195,7 @@ QCOMPARE(userTextChangedSpy.count(), 2); #endif QCOMPARE(textChangedSpy.count(), 2); - QCOMPARE(textEditedSpy.count(), 2); + QCOMPARE(textEditedSpy.count(), 0); #ifndef KCOMPLETION_NO_DEPRECATED userTextChangedSpy.clear(); #endif diff --git a/src/klineedit.h b/src/klineedit.h --- a/src/klineedit.h +++ b/src/klineedit.h @@ -626,7 +626,7 @@ private: const QScopedPointer d_ptr; - Q_PRIVATE_SLOT(d_func(), void _k_textChanged(const QString &)) + Q_PRIVATE_SLOT(d_func(), void _k_textEmitted(const QString &)) Q_PRIVATE_SLOT(d_func(), void _k_completionMenuActivated(QAction *)) Q_PRIVATE_SLOT(d_func(), void _k_tripleClickTimeout()) Q_PRIVATE_SLOT(d_func(), void _k_restoreSelectionColors()) diff --git a/src/klineedit.cpp b/src/klineedit.cpp --- a/src/klineedit.cpp +++ b/src/klineedit.cpp @@ -60,7 +60,6 @@ #ifndef KCOMPLETION_NO_DEPRECATED emit q->userTextChanged(text); #endif - emit q->textEdited(text); } } diff --git a/src/klineedit_p.h b/src/klineedit_p.h --- a/src/klineedit_p.h +++ b/src/klineedit_p.h @@ -210,7 +210,7 @@ ~KLineEditPrivate(); - void _k_textChanged(const QString &text); + void _k_textEmitted(const QString &text); void _k_completionMenuActivated(QAction *act); void _k_tripleClickTimeout(); // resets possibleTripleClick void _k_restoreSelectionColors();