Prevent QLineEdit from emitting edited signal (QTBUG-27347)

edited() signal should not be emitted when QValidator fixups
text in a lineedit.

Change-Id: Iccef45c4b858a65fd5097dc9e5033cefb09ad889
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Ivan Komissarov 2012-12-29 11:46:03 +04:00 committed by The Qt Project
parent d040681b6f
commit 16579e5b84
2 changed files with 8 additions and 2 deletions

View File

@ -427,7 +427,7 @@ bool QWidgetLineControl::fixup() // this function assumes that validate currentl
m_validator->fixup(textCopy);
if (m_validator->validate(textCopy, cursorCopy) == QValidator::Acceptable) {
if (textCopy != m_text || cursorCopy != m_cursor)
internalSetText(textCopy, cursorCopy);
internalSetText(textCopy, cursorCopy, false);
return true;
}
}
@ -672,7 +672,7 @@ bool QWidgetLineControl::finishChange(int validateFromState, bool update, bool e
m_validInput = (m_validator->validate(textCopy, cursorCopy) != QValidator::Invalid);
if (m_validInput) {
if (m_text != textCopy) {
internalSetText(textCopy, cursorCopy);
internalSetText(textCopy, cursorCopy, false);
return true;
}
m_cursor = cursorCopy;

View File

@ -866,12 +866,18 @@ public:
void tst_QLineEdit::hasAcceptableInputValidator()
{
QSignalSpy spyChanged(testWidget, SIGNAL(textChanged(QString)));
QSignalSpy spyEdited(testWidget, SIGNAL(textEdited(QString)));
QFocusEvent lostFocus(QEvent::FocusOut);
ValidatorWithFixup val;
testWidget->setValidator(&val);
testWidget->setText("foobar");
qApp->sendEvent(testWidget, &lostFocus);
QVERIFY(testWidget->hasAcceptableInput());
QCOMPARE(spyChanged.count(), 2);
QCOMPARE(spyEdited.count(), 0);
}