diff options
-rw-r--r-- | PySide/QtGui/typesystem_gui_common.xml | 38 | ||||
-rw-r--r-- | tests/QtGui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/QtGui/bug_1124.py | 66 |
3 files changed, 105 insertions, 0 deletions
diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml index 14a4ef7..965b69d 100644 --- a/PySide/QtGui/typesystem_gui_common.xml +++ b/PySide/QtGui/typesystem_gui_common.xml @@ -5445,6 +5445,44 @@ %END_ALLOW_THREADS </template> + <modify-function signature="drawPixmapFragments(const QPainter::PixmapFragment*, int, const QPixmap&, QFlags<QPainter::PixmapFragmentHint>)" since="4.7"> + <modify-argument index="1"> + <replace-type modified-type="PySequence"/> + </modify-argument> + <modify-argument index="2"> + <remove-argument/> + </modify-argument> + <inject-code class="target" position="beginning"> + if (PySequence_Check(%PYARG_1)) { /* object needs to provide sequence protocol */ + Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_1, 0)); + Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object()); + + if (size != -1) { + for (Py_ssize_t i = 0; i < size; i++) { + PyObject* obj = PySequence_Fast_GET_ITEM(seq.object(), i); + if (!%ISCONVERTIBLE[const QPainter::PixmapFragment](obj)) { + PyErr_SetString(PyExc_TypeError, + "You must pass a tuple/list that contain only " + "QtGui.%TYPE.PixmapFragment types"); + goto out; + } + } + + /* at this point we have either tuple or list of QPainter::PixmapFragment's */ + QPainter::PixmapFragment* fragments = new QPainter::PixmapFragment[size]; + for (Py_ssize_t i = 0; i < size; i++) { + PyObject* obj = PySequence_Fast_GET_ITEM(seq.object(), i); + fragments[i] = %CONVERTTOCPP[const QPainter::PixmapFragment](obj); + } + %CPPSELF.%FUNCTION_NAME(fragments, size, %3, %4); + delete [] fragments; + } + } + + out: + ; + </inject-code> + </modify-function> <modify-function signature="drawConvexPolygon(const QPoint*, int)" remove="all" /> <add-function signature="drawConvexPolygon(QVector<QPoint>)"> <inject-code> diff --git a/tests/QtGui/CMakeLists.txt b/tests/QtGui/CMakeLists.txt index 5998ca5..35c0aa6 100644 --- a/tests/QtGui/CMakeLists.txt +++ b/tests/QtGui/CMakeLists.txt @@ -82,6 +82,7 @@ PYSIDE_TEST(bug_1006.py) PYSIDE_TEST(bug_1041.py) PYSIDE_TEST(bug_1048.py) PYSIDE_TEST(bug_1077.py) +PYSIDE_TEST(bug_1124.py) PYSIDE_TEST(customproxywidget_test.py) PYSIDE_TEST(deepcopy_test.py) PYSIDE_TEST(event_filter_test.py) diff --git a/tests/QtGui/bug_1124.py b/tests/QtGui/bug_1124.py new file mode 100644 index 0000000..63fccf3 --- /dev/null +++ b/tests/QtGui/bug_1124.py @@ -0,0 +1,66 @@ +''' unit test for BUG #1124 ''' + +import unittest +from helper import UsesQApplication +from PySide import QtCore, QtGui +import sys + +class MyWidget(QtGui.QWidget): + def __init__(self, parent=None, app=None): + super(MyWidget, self).__init__(parent) + if not app: + app = QApplication([]) + + self.app = app + + def paintEvent(self, event): + pa = QtGui.QPainter(self) + fragments = [] + + makeFragment = lambda *a, **kw: \ + fragments.append(QtGui.QPainter.PixmapFragment.create(*a, **kw)) + + makeFragment(QtCore.QPointF(0, 0), QtCore.QRectF(0, 0, 2, 2)) + makeFragment(QtCore.QPointF(2, 0), QtCore.QRectF(0, 0, 2, 2), + rotation=90) + makeFragment(QtCore.QPointF(4, 0), QtCore.QRectF(0, 0, 2, 2), + rotation=180) + makeFragment(QtCore.QPointF(6, 0), QtCore.QRectF(0, 0, 1, 1), + scaleX=2, scaleY=2) + makeFragment(QtCore.QPointF(8, 0), QtCore.QRectF(1, 0, 1, 1), + scaleX=2, scaleY=2) + makeFragment(QtCore.QPointF(0, 2), QtCore.QRectF(0, 0, 2, 2), + opacity=0.5) + makeFragment(QtCore.QPointF(2, 2), QtCore.QRectF(0, 0, 2, 2), + scaleX=2, scaleY=2) + makeFragment(QtCore.QPointF(6, 2), QtCore.QRectF(0, 0, 2, 2), + scaleX=2, scaleY=2, rotation=90, opacity=0.5) + + try: + pa.drawPixmapFragments(fragments, QtGui.QPixmap(2, 2), 0) + except TypeError: + sys.exit(-1) + + # test pa.drawPixmapFragments() by passing a tuple of integers rather + # than QtGui.QPainter.PixmapFragment's that _must_ throw a TypeError + # exception. + try: + pa.drawPixmapFragments((1, 2, 3), QtGui.QPixmap(2, 2), 0) + sys.exit(-1) # it should not reach here + except TypeError: + pass + +class QPainterTestCase(UsesQApplication): + qapplication = True + + def setUp(self): + super(QPainterTestCase, self).setUp() + self.wid = MyWidget(app=self.app) + + def testIt(self): + QtCore.QTimer.singleShot(200, self.app.quit) + self.wid.show() + self.app.exec_() + +if __name__ == "__main__": + unittest.main() |