From ef45995bc59cff6299ca5b10b4acb4840c473172 Mon Sep 17 00:00:00 2001
From: Filippo Cucchetto <filippocucchetto@gmail.com>
Date: Wed, 19 Nov 2014 23:16:42 +0100
Subject: [PATCH] Fix Spinbox missing value change if minimumValue is set

The Spinbox validator considered invalid an intermediate value preventing the user for inserting a valid value.

Task-number: QTBUG-42342
Change-Id: I24d2f9f7d6fb9d5d4f96f81821b37a30421665a3
Reviewed-by: Filippo Cucchetto <filippocucchetto@gmail.com>
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
---
 src/controls/Private/qquickspinboxvalidator.cpp | 4 +++-
 tests/auto/controls/data/tst_spinbox.qml        | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/controls/Private/qquickspinboxvalidator.cpp b/src/controls/Private/qquickspinboxvalidator.cpp
index afbc866c8..2fec79e82 100644
--- a/src/controls/Private/qquickspinboxvalidator.cpp
+++ b/src/controls/Private/qquickspinboxvalidator.cpp
@@ -200,7 +200,9 @@ QValidator::State QQuickSpinBoxValidator::validate(QString &input, int &pos) con
         bool ok = false;
         qreal val = locale().toDouble(value, &ok);
         if (ok) {
-            if (state == QValidator::Acceptable) {
+            if (state == QValidator::Acceptable ||
+               (state == QValidator::Intermediate && val >= 0 && val <= m_validator.top()) ||
+               (state == QValidator::Intermediate && val < 0 && val >= m_validator.bottom())) {
                 const_cast<QQuickSpinBoxValidator *>(this)->setValue(val);
                 if (input != textFromValue(val))
                     state = QValidator::Intermediate;
diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml
index f74386c94..71132ca9f 100644
--- a/tests/auto/controls/data/tst_spinbox.qml
+++ b/tests/auto/controls/data/tst_spinbox.qml
@@ -132,7 +132,10 @@ Item {
                 {tag: "-20", input: [Qt.Key_Minus, Qt.Key_2, Qt.Key_0, Qt.Key_Return], value: -2, minimumValue: -10},
                 {tag: "-200", input: [Qt.Key_Minus, Qt.Key_2, Qt.Key_0, Qt.Key_0, Qt.Key_Return], value: -20, minimumValue: -100},
                 {tag: "-2000", input: [Qt.Key_Minus, Qt.Key_2, Qt.Key_0, Qt.Key_0, Qt.Key_0, Qt.Key_Return], value: -200, minimumValue: -1000},
-                {tag: "-0123", input: [Qt.Key_Minus, Qt.Key_0, Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_Return], value: -123, minimumValue: -150}
+                {tag: "-0123", input: [Qt.Key_Minus, Qt.Key_0, Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_Return], value: -123, minimumValue: -150},
+
+                {tag: "5", input: [Qt.Key_2, Qt.Key_0, Qt.Key_Return], value: 20, minimumValue: 10, maximumValue: 99},
+                {tag: "-5", input: [Qt.Key_Minus, Qt.Key_2, Qt.Key_0, Qt.Key_Return], value: -20, minimumValue: -99, maximumValue: -10},
             ]
         }
 
-- 
GitLab