aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Sæther <[email protected]>2019-12-02 14:33:39 +0100
committerJan Arve Sæther <[email protected]>2019-12-02 15:43:01 +0100
commitbd7ce75f26ae646176b22310c8cdbf568c7516dd (patch)
tree1666a5b666b61477c9709d0bc05c5614b7c5cf04
parent23df1603f514407d245a2740f32f589318ef654e (diff)
Do not emit inputMaskChanged when setting the same input mask
If you did not specify a blank character (e.g. "; " as suffix) it would internally add that suffix to the property, resulting in that the property itself actually got a "; " suffix even when not specified. So when setting the same input mask again, it wouldn't match the existing inputMask property, and it would emit inputMaskChanged again. Change-Id: Ia47d63d56c640b4be9d6d0a704ddfaff01befbdb Fixes: QTBUG-80190 Reviewed-by: Richard Moe Gustavsen <[email protected]>
-rw-r--r--src/quick/items/qquicktextinput.cpp5
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp8
2 files changed, 12 insertions, 1 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index a83b9beaa5..cd4f2eebc6 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -1140,7 +1140,10 @@ QString QQuickTextInput::inputMask() const
void QQuickTextInput::setInputMask(const QString &im)
{
Q_D(QQuickTextInput);
- if (d->inputMask() == im)
+ QString canonicalInputMask = im;
+ if (im.lastIndexOf(QLatin1Char(';')) == -1)
+ canonicalInputMask.append(QLatin1String("; "));
+ if (d->inputMask() == canonicalInputMask)
return;
d->setInputMask(im);
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
index cab4e1145f..6f24ca8ded 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -6411,6 +6411,14 @@ void tst_qquicktextinput::setInputMask()
QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(textInputComponent.create());
QVERIFY(textInput != nullptr);
+ // [QTBUG-80190] check if setting the same property value again doesn't emit an
+ // inputMaskChanged signal
+ QString unescapedMask = mask; // mask is escaped, because '\' is also escape in a JS string
+ unescapedMask.replace(QLatin1String("\\\\"), QLatin1String("\\")); // simple unescape
+ QSignalSpy spy(textInput, SIGNAL(inputMaskChanged(const QString &)));
+ textInput->setInputMask(unescapedMask);
+ QCOMPARE(spy.count(), 0);
+
// then either insert using insert() or keyboard
if (insert_text) {
textInput->insert(0, input);