aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-12-13 14:03:32 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-01-03 18:50:54 +0000
commite254c3c2aa140016e298107a0297885234abfde7 (patch)
treedb15ce3a6329ec3cc87a1b53f91e62ce754aeadc /sources/pyside2/tests
parent0b352fca7391d01ce410ec0c04c285326e465dc1 (diff)
Fix crash related to multiple inheritance
In the <class>_PTR_CppToPython_<class> converter function (written by CppGenerator::writeConverterFunctions()), the generated code used typeid(*ptr).name() to retrieve the name to use for the SbkObjectTypes. This construct returns the name of the outermost class (for example, "QWidget" for a QWidget-type paint device returned by QPainter::device()), as opposed to "QPaintDevice *" returned by typeid(ptr).name(). This caused a crash with multiple inheritance since QWidget inherits QObject and QPaintDevice and the "QWidget" type was associated with the QPaintDevice pointer. To fix this: - Add API to libshiboken to obtain the SbkObjectType* by name and check for the presence of a special cast function (multiple inheritance). - Generate the code of <class>_PTR_CppToPython_<class> as follows: Check whether the outermost type obtained by typeid(*ptr).name() has a special cast function. If that is the case, use the type name obtained by typeid(ptr).name() (base class) to create the wrapper. Change-Id: I8ee6b4c084e9dafa434623433661809b83aedee5 Fixes: PYSIDE-868 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r--sources/pyside2/tests/QtWidgets/qgraphicsscene_test.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/sources/pyside2/tests/QtWidgets/qgraphicsscene_test.py b/sources/pyside2/tests/QtWidgets/qgraphicsscene_test.py
index 07926d177..80a09dc57 100644
--- a/sources/pyside2/tests/QtWidgets/qgraphicsscene_test.py
+++ b/sources/pyside2/tests/QtWidgets/qgraphicsscene_test.py
@@ -32,14 +32,14 @@ import unittest
import gc
from PySide2.QtCore import QPointF
-from PySide2.QtGui import QPolygonF, QPixmap, QPainterPath, QTransform
+from PySide2.QtGui import QPolygonF, QPixmap, QPainterPath, QTransform, QWindow
from PySide2.QtWidgets import QApplication, QPushButton
from PySide2.QtWidgets import QGraphicsScene
from PySide2.QtWidgets import QGraphicsEllipseItem, QGraphicsLineItem
from PySide2.QtWidgets import QGraphicsPathItem, QGraphicsPixmapItem
from PySide2.QtWidgets import QGraphicsPolygonItem, QGraphicsRectItem
from PySide2.QtWidgets import QGraphicsSimpleTextItem, QGraphicsTextItem
-from PySide2.QtWidgets import QGraphicsProxyWidget
+from PySide2.QtWidgets import QGraphicsProxyWidget, QGraphicsView
from helper import UsesQApplication
@@ -51,6 +51,19 @@ class Constructor(unittest.TestCase):
obj = QGraphicsScene()
self.assertTrue(isinstance(obj, QGraphicsScene))
+# Test for PYSIDE-868: Test whether painter.device() can be accessed
+# correctly. This was crashing when the underlying QPaintDevice was a
+# QWidget due to handling multiple inheritance incorrectly.
+class CustomScene(QGraphicsScene):
+ def __init__(self, parent = None):
+ super(CustomScene, self).__init__(parent)
+ self.dpi = 0
+
+ def drawBackground(self, painter, rect):
+ self.dpi = painter.device().physicalDpiX()
+
+ def drawForeground(self, painter, rect):
+ self.dpi = painter.device().physicalDpiX()
class ConstructorWithRect(unittest.TestCase):
'''QGraphicsScene qrect constructor and related sizes'''
@@ -192,6 +205,14 @@ class TestGraphicsGroup(UsesQApplication):
scene.destroyItemGroup(group)
self.assertRaises(RuntimeError, group.type)
+ def testCustomScene(self): # For PYSIDE-868, see above
+ scene = CustomScene()
+ view = QGraphicsView(scene)
+ view.show()
+ while scene.dpi == 0:
+ QApplication.instance().processEvents()
+ view.hide()
+
if __name__ == '__main__':
unittest.main()