Make inputmask 'X' mask character require non-blank input

The implementation for the X mask would accept any printable
character. Since that includes the blank character, there was no
difference in behavior between the requiring X and optional x: both
would allow the input to be unset, i.e. blank.

This change should be seen in conjunction with the doc improvement
da0af1e.

[ChangeLog][QtWidgets][QLineEdit] Inputmask X character now requires non-blank input.

Fixes: QTBUG-76320
Change-Id: I3e0363e9be5c13373a157cce69c99379615b5829
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
bb10
Eirik Aavitsland 2019-12-02 10:44:40 +01:00
parent c69a2448ab
commit 95689c645f
3 changed files with 3 additions and 6 deletions

View File

@ -1214,8 +1214,8 @@ QMargins QLineEdit::textMargins() const
\row \li \c a \li ASCII alphabetic character permitted but not required.
\row \li \c N \li ASCII alphanumeric character required. A-Z, a-z, 0-9.
\row \li \c n \li ASCII alphanumeric character permitted but not required.
\row \li \c X \li Any character required.
\row \li \c x \li Any character permitted but not required.
\row \li \c X \li Any non-blank character required.
\row \li \c x \li Any non-blank character permitted but not required.
\row \li \c 9 \li ASCII digit required. 0-9.
\row \li \c 0 \li ASCII digit permitted but not required.
\row \li \c D \li ASCII digit required. 1-9.

View File

@ -1090,7 +1090,7 @@ bool QWidgetLineControl::isValidInput(QChar key, QChar mask) const
return true;
break;
case 'X':
if (key.isPrint())
if (key.isPrint() && key != m_blank)
return true;
break;
case 'x':

View File

@ -873,9 +873,6 @@ void tst_QLineEdit::hasAcceptableInputMask()
qApp->sendEvent(testWidget, &lostFocus);
QVERIFY(validInput);
// at the moment we don't strip the blank character if it is valid input, this makes the test between x vs X useless
QEXPECT_FAIL( "Any optional and required", "To eat blanks or not? Known issue. Task 43172", Abort);
// test requiredMask
testWidget->setInputMask(requiredMask);
validInput = true;