From bb0ab1d8cf57dd4a7b69c8478c2a40c1cd1782e9 Mon Sep 17 00:00:00 2001
From: Thierry Bastian <thierry.bastian@nokia.com>
Date: Thu, 10 Dec 2009 11:27:51 +0100
Subject: Fix spinbox input when seecting the prefix

If you were selcting the prefix and entering a digit the cursor position
would not be updated correctly

Task-number: QTBUG-6670
Reviewed-by: ogoffart
---
 src/gui/widgets/qabstractspinbox.cpp             |  4 +++-
 tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/gui/widgets/qabstractspinbox.cpp b/src/gui/widgets/qabstractspinbox.cpp
index a18af4f..c015589 100644
--- a/src/gui/widgets/qabstractspinbox.cpp
+++ b/src/gui/widgets/qabstractspinbox.cpp
@@ -1856,8 +1856,10 @@ QValidator::State QSpinBoxValidator::validate(QString &input, int &pos) const
     if (dptr->specialValueText.size() > 0 && input == dptr->specialValueText)
         return QValidator::Acceptable;
 
-    if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix))
+    if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) {
         input.prepend(dptr->prefix);
+        pos += dptr->prefix.length();
+    }
 
     if (!dptr->suffix.isEmpty() && !input.endsWith(dptr->suffix))
         input.append(dptr->suffix);
diff --git a/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp b/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp
index 7f03153..a3f0915 100644
--- a/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp
+++ b/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp
@@ -148,6 +148,7 @@ private slots:
     void task255471_decimalsValidation();
 
     void taskQTBUG_5008_textFromValueAndValidate();
+    void taskQTBUG_6670_selectAllWithPrefix();
 
 public slots:
     void valueChangedHelper(const QString &);
@@ -1084,5 +1085,16 @@ void tst_QDoubleSpinBox::taskQTBUG_5008_textFromValueAndValidate()
     QCOMPARE(spinbox.text(), spinbox.locale().toString(spinbox.value()));
 }
 
+void tst_QDoubleSpinBox::taskQTBUG_6670_selectAllWithPrefix()
+{
+    DoubleSpinBox spin;
+    spin.setPrefix("$ ");
+    spin.lineEdit()->selectAll();
+    QTest::keyClick(spin.lineEdit(), Qt::Key_1);
+    QCOMPARE(spin.value(), 1.);
+    QTest::keyClick(spin.lineEdit(), Qt::Key_2);
+    QCOMPARE(spin.value(), 12.);
+}
+
 QTEST_MAIN(tst_QDoubleSpinBox)
 #include "tst_qdoublespinbox.moc"
-- 
cgit v0.12