QLineEdit: Emit inputRejected() when part of the input is rejected
When pasting text, it is possible that part of the text is still pasted
but part of it is not. For example, if there is a maximum length set then
only the first part of the text is pasted and the rest is dropped. In
this case it should still emit inputRejected() as not all of the input
was accepted. This amends c901cdadc0.
Change-Id: If7906767be27e88ed9914c50bf0427833de5b8fa
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
bb10
parent
792298e42d
commit
af4435c5f8
|
|
@ -1681,6 +1681,11 @@ void QLineEdit::mouseDoubleClickEvent(QMouseEvent* e)
|
|||
results in a validator's validate() call to return Invalid.
|
||||
Another case is when trying to enter in more characters beyond the
|
||||
maximum length of the line edit.
|
||||
|
||||
Note: This signal will still be emitted in a case where part of
|
||||
the text is accepted but not all of it is. For example, if there
|
||||
is a maximum length set and the clipboard text is longer than the
|
||||
maximum length when it is pasted.
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -872,9 +872,9 @@ void QWidgetLineControl::internalInsert(const QString &s)
|
|||
for (int i = 0; i < (int) s.left(remaining).length(); ++i)
|
||||
addCommand(Command(Insert, m_cursor++, s.at(i), -1, -1));
|
||||
m_textDirty = true;
|
||||
} else {
|
||||
emit inputRejected();
|
||||
}
|
||||
if (s.length() > remaining)
|
||||
emit inputRejected();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4838,6 +4838,13 @@ void tst_QLineEdit::inputRejected()
|
|||
QCOMPARE(spyInputRejected.count(), 0);
|
||||
QTest::keyClicks(testWidget, "fgh");
|
||||
QCOMPARE(spyInputRejected.count(), 3);
|
||||
testWidget->clear();
|
||||
spyInputRejected.clear();
|
||||
QApplication::clipboard()->setText("ijklmno");
|
||||
testWidget->paste();
|
||||
// The first 5 characters are accepted, but
|
||||
// the last 2 are not.
|
||||
QCOMPARE(spyInputRejected.count(), 1);
|
||||
|
||||
testWidget->setMaxLength(INT_MAX);
|
||||
testWidget->clear();
|
||||
|
|
@ -4848,6 +4855,11 @@ void tst_QLineEdit::inputRejected()
|
|||
QCOMPARE(spyInputRejected.count(), 0);
|
||||
QTest::keyClicks(testWidget, "a#");
|
||||
QCOMPARE(spyInputRejected.count(), 2);
|
||||
testWidget->clear();
|
||||
spyInputRejected.clear();
|
||||
QApplication::clipboard()->setText("a#");
|
||||
testWidget->paste();
|
||||
QCOMPARE(spyInputRejected.count(), 1);
|
||||
|
||||
testWidget->clear();
|
||||
testWidget->setValidator(0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue