summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <pcacjr@gmail.com>2012-01-19 16:10:34 -0300
committerPaulo Alcantara <pcacjr@gmail.com>2012-01-23 11:34:28 -0300
commit6f3792457c3c965d49f9cdc614ccbfff7b94317c (patch)
tree67788e8d45d8f67723b0b5594e8fc3dc6f7d29eb
parent3aba7ebbf7ae05804d96dc1db9edad3926c89ee5 (diff)
downloadpyside-6f3792457c3c965d49f9cdc614ccbfff7b94317c.tar.gz
pyside-6f3792457c3c965d49f9cdc614ccbfff7b94317c.tar.xz
pyside-6f3792457c3c965d49f9cdc614ccbfff7b94317c.zip
Fix BUG #1124 - "QPainter.drawPixmapFragments should take a list as
first argument" See http://bugs.pyside.org/show_bug.cgi?id=1124. Signed-off-by: Paulo Alcantara <pcacjr@gmail.com> Reviewed-by: Hugo Parente Lima <hugo.pl@gmail.com> Reviewed-by: Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--PySide/QtGui/typesystem_gui_common.xml38
-rw-r--r--tests/QtGui/CMakeLists.txt1
-rw-r--r--tests/QtGui/bug_1124.py66
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&amp;, QFlags&lt;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 &lt; 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 &lt; 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&lt;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()