aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@jollamobile.com>2014-07-22 17:39:53 +1000
committerAaron McCarthy <mccarthy.aaron@gmail.com>2014-07-24 06:33:59 +0200
commitb25035e51289d6f5f50ee967575c7c97c26a127c (patch)
treece75213f896fa45d68af4afb77c566455be94cfe /src
parentd10b97563f839b7550b5fc940371dbccea0be237 (diff)
Fix incorrect acceptableInput value on construction.
The value for acceptableInput was being calculated every time the property value was read. This can lead to situations where the value returned from successive property reads is different even though no acceptableInputChanged() signal is emitted between the two calls. This can be seen during QML component construction where emission of the changed signal is suppressed until the component completes and the value of acceptableInput changes as the other properties are set. If the property is read during binding evaluation an intermediate value can be seen and the QML engine will not re-read the property until after the changed signal is emitted. This doesn't happen until the true value of the acceptableInput property is toggled. Fixed by changing the property getter to returned the precalculated value of acceptableInput and ensuring that this value is set when correctly. Change-Id: Id3ba3a34988ff50f590e4f8330b873f390eaa025 Reviewed-by: Martin Jones <martin.jones@jollamobile.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquicktextinput.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index f3f9d0b5aa..37b103613d 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -1199,7 +1199,7 @@ void QQuickTextInput::setInputMask(const QString &im)
bool QQuickTextInput::hasAcceptableInput() const
{
Q_D(const QQuickTextInput);
- return d->hasAcceptableInput(d->m_text) == QQuickTextInputPrivate::AcceptableInput;
+ return d->m_acceptableInput;
}
/*!
@@ -2589,7 +2589,7 @@ void QQuickTextInputPrivate::handleFocusEvent(QFocusEvent *event)
&& !persistentSelection)
deselect();
- if (q->hasAcceptableInput() || fixup())
+ if (hasAcceptableInput(m_text) == AcceptableInput || fixup())
emit q->editingFinished();
#ifndef QT_NO_IM
@@ -3415,6 +3415,27 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo
}
}
#endif
+
+ if (m_maskData) {
+ if (m_text.length() != m_maxLength) {
+ m_acceptableInput = false;
+ } else {
+ for (int i = 0; i < m_maxLength; ++i) {
+ if (m_maskData[i].separator) {
+ if (m_text.at(i) != m_maskData[i].maskChar) {
+ m_acceptableInput = false;
+ break;
+ }
+ } else {
+ if (!isValidInput(m_text.at(i), m_maskData[i].maskChar)) {
+ m_acceptableInput = false;
+ break;
+ }
+ }
+ }
+ }
+ }
+
if (validateFromState >= 0 && wasValidInput && !m_validInput) {
if (m_transactions.count())
return false;
@@ -4199,7 +4220,7 @@ void QQuickTextInputPrivate::processKeyEvent(QKeyEvent* event)
Q_Q(QQuickTextInput);
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
- if (q->hasAcceptableInput() || fixup()) {
+ if (hasAcceptableInput(m_text) == AcceptableInput || fixup()) {
emit q->accepted();
emit q->editingFinished();
}