aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-02-27 14:44:39 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-03-01 13:56:16 +0000
commit6c0a0d70305cd6e12260a352099e74d34f3c239e (patch)
treeda2df8451c284ef91fdeea76ae6f24315bf03864
parent85e14a0d72b3470748e3cbe8871e23a818820ee9 (diff)
Fix QValidator fixup() behavior
The return value from the fixup() method was ignored leaving an Intermediate or Invalid input intact. This was solved injecting code to the native wrapper for the fixup() method that allows to change its value. A test case is provided. Task-number: PYSIDE-106 Change-Id: I1d796955178dbdbcfff90adb6ede5c8b2dd1acc3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml3
-rw-r--r--sources/pyside2/PySide2/typesystem_templates.xml6
-rw-r--r--sources/pyside2/tests/QtWidgets/qvalidator_test.py27
3 files changed, 32 insertions, 4 deletions
diff --git a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml
index 55bc438be..2578a1aa9 100644
--- a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml
+++ b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml
@@ -1713,6 +1713,9 @@
<modify-argument index="return">
<replace-type modified-type="QString"/>
</modify-argument>
+ <inject-code class="native" position="end">
+ <insert-template name="return_QString_native"/>
+ </inject-code>
<inject-code class="target" position="end">
<insert-template name="return_QString"/>
</inject-code>
diff --git a/sources/pyside2/PySide2/typesystem_templates.xml b/sources/pyside2/PySide2/typesystem_templates.xml
index 7ac4ac158..e0b47b6e3 100644
--- a/sources/pyside2/PySide2/typesystem_templates.xml
+++ b/sources/pyside2/PySide2/typesystem_templates.xml
@@ -278,6 +278,12 @@
<template name="return_QString">
%PYARG_0 = %CONVERTTOPYTHON[QString](%1);
</template>
+ <template name="return_QString_native">
+ if (%ISCONVERTIBLE[QString](%PYARG_0))
+ %1 = %CONVERTTOCPP[QString](%PYARG_0);
+ else
+ qWarning("%TYPE::%FUNCTION_NAME: Argument is not convertible to unicode.");
+ </template>
<template name="return_tuple_QValidator_QString_int">
%BEGIN_ALLOW_THREADS
diff --git a/sources/pyside2/tests/QtWidgets/qvalidator_test.py b/sources/pyside2/tests/QtWidgets/qvalidator_test.py
index 951d6b2b0..dd5eaadb3 100644
--- a/sources/pyside2/tests/QtWidgets/qvalidator_test.py
+++ b/sources/pyside2/tests/QtWidgets/qvalidator_test.py
@@ -29,38 +29,49 @@
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
+from PySide2.QtTest import *
import unittest
from helper import UsesQApplication
class MyValidator1(QValidator):
- def fixUp(self, input):
+ def fixup(self, input):
return "fixed"
def validate(self, input, pos):
return (QValidator.Acceptable, "fixed", 1)
class MyValidator2(QValidator):
- def fixUp(self, input):
+ def fixup(self, input):
return "fixed"
def validate(self, input, pos):
return (QValidator.Acceptable, "fixed")
class MyValidator3(QValidator):
- def fixUp(self, input):
+ def fixup(self, input):
return "fixed"
def validate(self, input, pos):
return (QValidator.Acceptable,)
class MyValidator4(QValidator):
- def fixUp(self, input):
+ def fixup(self, input):
return "fixed"
def validate(self, input, pos):
return QValidator.Acceptable
+class MyValidator5(QValidator):
+ def validate(self, input, pos):
+ if input.islower():
+ return (QValidator.Intermediate, input, pos)
+ else:
+ return (QValidator.Acceptable, input, pos)
+
+ def fixup(self, input):
+ return "22"
+
class QValidatorTest(UsesQApplication):
def testValidator1(self):
line = QLineEdit()
@@ -110,5 +121,13 @@ class QValidatorTest(UsesQApplication):
self.assertEqual(line.text(), "foo")
self.assertEqual(line.cursorPosition(), 3)
+ def testValidator5(self):
+ line = QLineEdit()
+ line.show()
+ line.setValidator(MyValidator5())
+ line.setText("foo")
+ QTest.keyClick(line, Qt.Key_Return)
+ self.assertEqual(line.text(), "22")
+
if __name__ == '__main__':
unittest.main()