Fix bug 879 - "QDoubleSpinBox: Can't call the parent validate() method from a subclass"
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
590abafc54
commit
df30f37512
3 changed files with 70 additions and 33 deletions
|
|
@ -2706,6 +2706,43 @@
|
||||||
</modify-function>
|
</modify-function>
|
||||||
</object-type>
|
</object-type>
|
||||||
<object-type name="QVBoxLayout"/>
|
<object-type name="QVBoxLayout"/>
|
||||||
|
|
||||||
|
<template name="validator_conversionrule">
|
||||||
|
QValidator::State %out;
|
||||||
|
|
||||||
|
if (PySequence_Check(%PYARG_0)) {
|
||||||
|
Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_0, 0));
|
||||||
|
int size = PySequence_Fast_GET_SIZE(seq.object());
|
||||||
|
|
||||||
|
if (size > 1) {
|
||||||
|
if (Shiboken::Converter<QString>::isConvertible(PySequence_Fast_GET_ITEM(seq.object(), 1)))
|
||||||
|
%1 = %CONVERTTOCPP[QString](PySequence_Fast_GET_ITEM(seq.object(), 1));
|
||||||
|
else
|
||||||
|
qWarning("%TYPE::%FUNCTION_NAME: Second tuple element is not convertible to unicode.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size > 2) {
|
||||||
|
if (Shiboken::Converter<int>::isConvertible(PySequence_Fast_GET_ITEM(seq.object(), 2)))
|
||||||
|
%2 = %CONVERTTOCPP[int](PySequence_Fast_GET_ITEM(seq.object(), 2));
|
||||||
|
else
|
||||||
|
qWarning("%TYPE::%FUNCTION_NAME: Second tuple element is not convertible to int.");
|
||||||
|
}
|
||||||
|
%PYARG_0 = PySequence_Fast_GET_ITEM(seq.object(), 0);
|
||||||
|
Py_INCREF(%PYARG_0); // we need to incref, because "%PYARG_0 = ..." will decref the tuple and the tuple will be decrefed again at the end of this scope.
|
||||||
|
}
|
||||||
|
|
||||||
|
// check retrun value
|
||||||
|
if (Shiboken::Converter<QValidator::State>::isConvertible(%PYARG_0)) {
|
||||||
|
%out = %CONVERTTOCPP[QValidator::State](%PYARG_0);
|
||||||
|
} else {
|
||||||
|
PyErr_Format(PyExc_TypeError, "Invalid return value in function %s, expected %s, got %s.",
|
||||||
|
"QValidator.validate",
|
||||||
|
"PySide.QtGui.QValidator.State, (PySide.QtGui.QValidator.State,), (PySide.QtGui.QValidator.State, unicode) or (PySide.QtGui.QValidator.State, unicode, int)",
|
||||||
|
pyResult->ob_type->tp_name);
|
||||||
|
return QValidator::State();
|
||||||
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<object-type name="QValidator">
|
<object-type name="QValidator">
|
||||||
<enum-type name="State"/>
|
<enum-type name="State"/>
|
||||||
<modify-function signature="fixup(QString &)const">
|
<modify-function signature="fixup(QString &)const">
|
||||||
|
|
@ -2720,39 +2757,7 @@
|
||||||
<modify-argument index="return">
|
<modify-argument index="return">
|
||||||
<replace-type modified-type="PyObject"/>
|
<replace-type modified-type="PyObject"/>
|
||||||
<conversion-rule class="native">
|
<conversion-rule class="native">
|
||||||
QValidator::State %out;
|
<insert-template name="validator_conversionrule"/>
|
||||||
|
|
||||||
if (PySequence_Check(%PYARG_0)) {
|
|
||||||
Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_0, 0));
|
|
||||||
int size = PySequence_Fast_GET_SIZE(seq.object());
|
|
||||||
|
|
||||||
if (size > 1) {
|
|
||||||
if (Shiboken::Converter<QString>::isConvertible(PySequence_Fast_GET_ITEM(seq.object(), 1)))
|
|
||||||
%1 = %CONVERTTOCPP[QString](PySequence_Fast_GET_ITEM(seq.object(), 1));
|
|
||||||
else
|
|
||||||
qWarning("%TYPE::%FUNCTION_NAME: Second tuple element is not convertible to unicode.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size > 2) {
|
|
||||||
if (Shiboken::Converter<int>::isConvertible(PySequence_Fast_GET_ITEM(seq.object(), 2)))
|
|
||||||
%2 = %CONVERTTOCPP[int](PySequence_Fast_GET_ITEM(seq.object(), 2));
|
|
||||||
else
|
|
||||||
qWarning("%TYPE::%FUNCTION_NAME: Second tuple element is not convertible to int.");
|
|
||||||
}
|
|
||||||
%PYARG_0 = PySequence_Fast_GET_ITEM(seq.object(), 0);
|
|
||||||
Py_INCREF(%PYARG_0); // we need to incref, because "%PYARG_0 = ..." will decref the tuple and the tuple will be decrefed again at the end of this scope.
|
|
||||||
}
|
|
||||||
|
|
||||||
// check retrun value
|
|
||||||
if (Shiboken::Converter<QValidator::State>::isConvertible(%PYARG_0)) {
|
|
||||||
%out = %CONVERTTOCPP[QValidator::State](%PYARG_0);
|
|
||||||
} else {
|
|
||||||
PyErr_Format(PyExc_TypeError, "Invalid return value in function %s, expected %s, got %s.",
|
|
||||||
"QValidator.validate",
|
|
||||||
"PySide.QtGui.QValidator.State, (PySide.QtGui.QValidator.State,), (PySide.QtGui.QValidator.State, unicode) or (PySide.QtGui.QValidator.State, unicode, int)",
|
|
||||||
pyResult->ob_type->tp_name);
|
|
||||||
return QValidator::State();
|
|
||||||
}
|
|
||||||
</conversion-rule>
|
</conversion-rule>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
<inject-code class="target" position="end">
|
<inject-code class="target" position="end">
|
||||||
|
|
@ -4127,6 +4132,9 @@
|
||||||
<modify-function signature="validate(QString &, int &)const">
|
<modify-function signature="validate(QString &, int &)const">
|
||||||
<modify-argument index="return">
|
<modify-argument index="return">
|
||||||
<replace-type modified-type="PyObject"/>
|
<replace-type modified-type="PyObject"/>
|
||||||
|
<conversion-rule class="native">
|
||||||
|
<insert-template name="validator_conversionrule"/>
|
||||||
|
</conversion-rule>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
<inject-code class="target" position="end">
|
<inject-code class="target" position="end">
|
||||||
<insert-template name="return_tuple_QValidator_QString_int"/>
|
<insert-template name="return_tuple_QValidator_QString_int"/>
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ PYSIDE_TEST(bug_854.py)
|
||||||
PYSIDE_TEST(bug_860.py)
|
PYSIDE_TEST(bug_860.py)
|
||||||
PYSIDE_TEST(bug_862.py)
|
PYSIDE_TEST(bug_862.py)
|
||||||
PYSIDE_TEST(bug_871.py)
|
PYSIDE_TEST(bug_871.py)
|
||||||
|
PYSIDE_TEST(bug_879.py)
|
||||||
PYSIDE_TEST(bug_882.py)
|
PYSIDE_TEST(bug_882.py)
|
||||||
PYSIDE_TEST(customproxywidget_test.py)
|
PYSIDE_TEST(customproxywidget_test.py)
|
||||||
PYSIDE_TEST(deepcopy_test.py)
|
PYSIDE_TEST(deepcopy_test.py)
|
||||||
|
|
|
||||||
28
tests/QtGui/bug_879.py
Normal file
28
tests/QtGui/bug_879.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import unittest
|
||||||
|
from PySide.QtCore import *
|
||||||
|
from PySide.QtGui import *
|
||||||
|
|
||||||
|
class MySpinBox(QSpinBox):
|
||||||
|
|
||||||
|
def validate(self,text,pos):
|
||||||
|
return QSpinBox.validate(self,text,pos)
|
||||||
|
|
||||||
|
class TestBug879 (unittest.TestCase):
|
||||||
|
|
||||||
|
def testIt(self):
|
||||||
|
app = QApplication([])
|
||||||
|
self.box = MySpinBox()
|
||||||
|
self.box.show()
|
||||||
|
|
||||||
|
QTimer.singleShot(0, self.sendKbdEvent)
|
||||||
|
QTimer.singleShot(100, app.quit)
|
||||||
|
app.exec_()
|
||||||
|
|
||||||
|
self.assertEqual(self.box.text(), '0')
|
||||||
|
|
||||||
|
def sendKbdEvent(self):
|
||||||
|
ev = QKeyEvent(QEvent.KeyPress, Qt.Key_A, Qt.NoModifier, 'a')
|
||||||
|
QCoreApplication.sendEvent(self.box, ev)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue