Index: autotests/klineedit_unittest.cpp =================================================================== --- autotests/klineedit_unittest.cpp +++ 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,33 @@ textChangedSpy.clear(); textEditedSpy.clear(); + // calling clear should emit textChanged, but not textEdited, nor userTextChanged + w.clear(); + QCOMPARE(textChangedSpy.count(),1); + QCOMPARE(textEditedSpy.count(),0); +#ifndef KCOMPLETION_NO_DEPRECATED + QCOMPARE(userTextChangedSpy.count(),0); +#endif + + //if text box is already clear, 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(),0); +#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")); Index: src/klineedit.h =================================================================== --- src/klineedit.h +++ 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()) Index: src/klineedit.cpp =================================================================== --- src/klineedit.cpp +++ src/klineedit.cpp @@ -51,16 +51,15 @@ delete style.data(); } -void KLineEditPrivate::_k_textChanged(const QString &text) +void KLineEditPrivate::_k_textEmitted(const QString &text) { Q_Q(KLineEdit); - // COMPAT (as documented): emit userTextChanged whenever textChanged is emitted + // COMPAT (as documented): emit userTextChanged whenever textEmitted is emitted if (!completionRunning && (text != userText)) { userText = text; #ifndef KCOMPLETION_NO_DEPRECATED emit q->userTextChanged(text); #endif - emit q->textEdited(text); } } @@ -182,7 +181,7 @@ style = new KLineEditStyle(q->style()); q->setStyle(style.data()); - q->connect(q, SIGNAL(textChanged(QString)), q, SLOT(_k_textChanged(QString))); + q->connect(q, SIGNAL(textChanged(QString)), q, SLOT(_k_textEmitted(QString))); } KLineEdit::KLineEdit(const QString &string, QWidget *parent) Index: src/klineedit_p.h =================================================================== --- src/klineedit_p.h +++ 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();